-
Notifications
You must be signed in to change notification settings - Fork 590
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
feat(storage): support reverse scan #12570
Merged
Merged
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
da97cfe
tmp commit
Little-Wallace b139383
refactor code
Little-Wallace f4b5eca
rev iterator
Little-Wallace af91a74
fix check
Little-Wallace 27c4bb9
add test
Little-Wallace 40d7711
fix test
Little-Wallace 8367c90
remove core
Little-Wallace 6c88003
Merge branch 'main' into reverse-iter
Little-Wallace 11f48f9
fix conflict
Little-Wallace d8360cc
revert user key refactor
Little-Wallace b89d706
add micro benchmark
Little-Wallace c94b648
add ut
Little-Wallace 02d8825
fix format
Little-Wallace a8f563a
refactor iterator builder
Little-Wallace 849da4b
refactor
Little-Wallace 3c82812
refactor interface
Little-Wallace 3ccc35c
Merge branch 'main' into reverse-iter
Little-Wallace 059e527
fix conflict
Little-Wallace c0343b4
fix format
Little-Wallace c7d7adf
add ut
Little-Wallace 4289518
fix check
Little-Wallace 349b617
fix corner case
Little-Wallace 5632104
fix scan bound
Little-Wallace 9615962
Merge branch 'main' into reverse-iter
Little-Wallace 7c6217b
fix fmt
Little-Wallace 16b1719
fix warn
Little-Wallace c2c0164
Merge branch 'main' into reverse-iter
Little-Wallace 2420d15
address comment
Little-Wallace d0c0fd4
Merge branch 'main' into reverse-iter
Little-Wallace fa29061
fix conflict
Little-Wallace 4dd8d3f
fix check
Little-Wallace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,6 +379,82 @@ impl<'a, B: RustIteratorBuilder> FromRustIterator<'a, B> { | |
table_id, | ||
} | ||
} | ||
|
||
async fn seek_inner<'b>(&'b mut self, key: FullKey<&'b [u8]>) -> HummockResult<()> { | ||
match self.table_id.cmp(&key.user_key.table_id) { | ||
std::cmp::Ordering::Less => { | ||
self.iter = None; | ||
return Ok(()); | ||
} | ||
std::cmp::Ordering::Greater => { | ||
return self.rewind().await; | ||
} | ||
_ => {} | ||
} | ||
let mut iter = B::seek(self.inner, key.user_key.table_key); | ||
match iter.next() { | ||
Some((first_key, first_value)) => { | ||
if first_key.eq(&key.user_key.table_key) && self.epoch > key.epoch_with_gap { | ||
// The semantic of `seek_fn` will ensure that `first_key` >= table_key of `key`. | ||
// At the beginning we have checked that `self.table_id` >= table_id of `key`. | ||
match iter.next() { | ||
Some((next_key, next_value)) => { | ||
assert_gt!(next_key, first_key); | ||
self.iter = | ||
Some((RustIteratorOfBuilder::Seek(iter), next_key, next_value)); | ||
} | ||
None => { | ||
self.iter = None; | ||
} | ||
} | ||
} else { | ||
self.iter = Some((RustIteratorOfBuilder::Seek(iter), first_key, first_value)); | ||
} | ||
} | ||
None => { | ||
self.iter = None; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
async fn rev_seek_inner<'b>(&'b mut self, key: FullKey<&'b [u8]>) -> HummockResult<()> { | ||
match self.table_id.cmp(&key.user_key.table_id) { | ||
std::cmp::Ordering::Less => { | ||
return self.rewind().await; | ||
} | ||
std::cmp::Ordering::Greater => { | ||
self.iter = None; | ||
return Ok(()); | ||
} | ||
_ => {} | ||
} | ||
let mut iter = B::seek(self.inner, key.user_key.table_key); | ||
match iter.next() { | ||
Some((first_key, first_value)) => { | ||
if first_key.eq(&key.user_key.table_key) && self.epoch < key.epoch_with_gap { | ||
// The semantic of `seek_fn` will ensure that `first_key` >= table_key of `key`. | ||
// At the beginning we have checked that `self.table_id` >= table_id of `key`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nits: should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
match iter.next() { | ||
Some((next_key, next_value)) => { | ||
assert_lt!(next_key, first_key); | ||
self.iter = | ||
Some((RustIteratorOfBuilder::Seek(iter), next_key, next_value)); | ||
} | ||
None => { | ||
self.iter = None; | ||
} | ||
} | ||
} else { | ||
self.iter = Some((RustIteratorOfBuilder::Seek(iter), first_key, first_value)); | ||
} | ||
} | ||
None => { | ||
self.iter = None; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl<'a, B: RustIteratorBuilder> HummockIterator for FromRustIterator<'a, B> { | ||
|
@@ -426,59 +502,10 @@ impl<'a, B: RustIteratorBuilder> HummockIterator for FromRustIterator<'a, B> { | |
} | ||
|
||
async fn seek<'b>(&'b mut self, key: FullKey<&'b [u8]>) -> HummockResult<()> { | ||
match self.table_id.cmp(&key.user_key.table_id) { | ||
std::cmp::Ordering::Less => match Self::Direction::direction() { | ||
DirectionEnum::Forward => { | ||
self.iter = None; | ||
return Ok(()); | ||
} | ||
DirectionEnum::Backward => { | ||
return self.rewind().await; | ||
} | ||
}, | ||
std::cmp::Ordering::Greater => match Self::Direction::direction() { | ||
DirectionEnum::Forward => { | ||
return self.rewind().await; | ||
} | ||
DirectionEnum::Backward => { | ||
self.iter = None; | ||
return Ok(()); | ||
} | ||
}, | ||
_ => {} | ||
match Self::Direction::direction() { | ||
DirectionEnum::Forward => self.seek_inner(key).await, | ||
DirectionEnum::Backward => self.rev_seek_inner(key).await, | ||
} | ||
let mut iter = B::seek(self.inner, key.user_key.table_key); | ||
match iter.next() { | ||
Some((first_key, first_value)) => { | ||
if first_key.eq(&key.user_key.table_key) && self.epoch > key.epoch_with_gap { | ||
// The semantic of `seek_fn` will ensure that `first_key` >= table_key of `key`. | ||
// At the beginning we have checked that `self.table_id` >= table_id of `key`. | ||
match iter.next() { | ||
Some((next_key, next_value)) => { | ||
match Self::Direction::direction() { | ||
DirectionEnum::Forward => { | ||
assert_gt!(next_key, first_key); | ||
} | ||
DirectionEnum::Backward => { | ||
assert_lt!(next_key, first_key); | ||
} | ||
} | ||
self.iter = | ||
Some((RustIteratorOfBuilder::Seek(iter), next_key, next_value)); | ||
} | ||
None => { | ||
self.iter = None; | ||
} | ||
} | ||
} else { | ||
self.iter = Some((RustIteratorOfBuilder::Seek(iter), first_key, first_value)); | ||
} | ||
} | ||
None => { | ||
self.iter = None; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn collect_local_statistic(&self, _stats: &mut StoreLocalStatistic) {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits: should be
first_key <= table_key of key
in the comment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed