Skip to content

fix(obserivation): fix missed hitmap updates, fix drop order #14788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 25, 2024

Conversation

MrCroxx
Copy link
Contributor

@MrCroxx MrCroxx commented Jan 25, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

FIx:

  • Take block seek read into hitmap's account.
  • Make sure hitmap is dropped before the block holder.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@MrCroxx MrCroxx requested a review from wenym1 January 25, 2024 06:09
@MrCroxx MrCroxx self-assigned this Jan 25, 2024
@github-actions github-actions bot added the type/fix Type: Bug fix. Only for pull requests. label Jan 25, 2024
@@ -246,7 +261,10 @@ impl BlockIterator {
}

/// Searches the restart point index that the given `key` belongs to.
fn search_restart_point_index_by_key(&self, key: FullKey<&[u8]>) -> usize {
fn search_restart_point_index_by_key(&mut self, key: FullKey<&[u8]>) -> usize {
// Create a temporary local hitmap.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just update the local hitmap instead of creating a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block binary search requires the iterator's immutable reference, and the hitmap cannot be updated in the closure for it requires the mutable reference. (I forgot to restore this diff line, let me fix it.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the immutable reference is required to call decode_prefix_at of self. However, looking into the implementation of decode_prefix_at, it only uses self.block. Therefore, if we change to implement decode_prefix_at as method of BlockHolder, we don't need the immutable reference of self here. And it makes sense to me to make decode_prefix_at a method of a single block instead of a method of BlockIterator.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can just inline the call of decode_prefix_at as

KeyPrefix::decode(
    &mut &self.block.data()[offset..],
    offset,
    key_len_type,
    value_len_type,
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the offset information is duplicated here, once in slice range, and once as method parameter.

Maybe we can change the first parameter of decode from buf: &mut impl Buf to &[u8] and we generate the &mut &self.block.data()[offset..] inside the code of KeyPrefix::decode so that we remove the duplicated offset information in method call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for inline call, but I think duplicated offset sounds okay here, it will unify the encode/decode parameters of KeyPrefix.

///
/// - `hitmap` is supposed to be updated each time accessing the block data in a new position.
/// - `hitmap` is supposed to be dropped before `block`
hitmap: ManuallyDrop<LocalHitmap<HITMAP_ELEMS>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current way of report hitmap leverages the drop of local hitmap, but the correctness of the drop of local hitmap should depend on the correct implementation of the drop of BlockIterator. If so, I think we'd better decouple hitmap and local hitmap, which means we won't associate a hitmap the local hitmap, and the local hitmap won't implement its drop. We only manually apply the local hitmap to the block hitmap in the drop of BlockIterator.

@MrCroxx MrCroxx requested a review from wenym1 January 25, 2024 08:53
@MrCroxx MrCroxx enabled auto-merge January 25, 2024 10:14
@MrCroxx MrCroxx added this pull request to the merge queue Jan 25, 2024
Merged via the queue into main with commit 996a4ba Jan 25, 2024
@MrCroxx MrCroxx deleted the xx/fix-hitmap-drop-order branch January 25, 2024 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/fix Type: Bug fix. Only for pull requests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants