-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
support lower_bound for iterator #2504
Conversation
_ => unreachable!(), | ||
}; | ||
|
||
self.statistics_cache.add(self.scanner.get_statistics()); | ||
let lower_bound = Some(Key::from_raw(&self.range.start).encoded().to_vec()); |
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.
It seems the same with L51-L65?
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.
L51-L65 depends if desc
is set, but here is not.
|
||
self.statistics_cache.add(self.scanner.get_statistics()); | ||
let lower_bound = Some(Key::from_raw(&self.range.start).encoded().to_vec()); | ||
let upper_bound = Some(Key::from_raw(&self.range.end).encoded().to_vec()); |
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.
What happen if it reverse seek upper_bound
?
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.
Inside the RocksDB, SeekForPrev(upper_bound)
will return the largest valid key, it is equal to SeekToLast()
. I see we use SeekForPrev
to implement reverse seek, so the behavior is the same.
}; | ||
iter_opt.set_lower_bound(lower_bound) | ||
} | ||
|
||
fn set_upper_bound(iter_opt: IterOption, region: &Region) -> IterOption { |
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.
Can it take a &mut IterOption
instead?
@@ -48,12 +48,18 @@ impl Scanner { | |||
key_only: bool, | |||
range: KeyRange, | |||
) -> Result<Scanner> { | |||
let (scan_mode, seek_key, upper_bound) = if desc { | |||
(ScanMode::Backward, range.get_end().to_vec(), None) | |||
let (scan_mode, seek_key, lower_bound, upper_bound) = if desc { |
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.
Here why not set both lower_bound
and upper_bound
, like we do at line 92?
_ => keys::enc_end_key(region), | ||
Some(k) if !k.is_empty() => { | ||
let k = keys::data_key(k); | ||
if k < region_end_key { |
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.
I think we can use cmp::max
.
LGTM. |
LGTM |
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.
Rest LGTM
@@ -591,5 +616,22 @@ mod tests { | |||
let mut expect = test_data.clone(); | |||
expect.reverse(); | |||
assert_eq!(res, expect); | |||
|
|||
// test lower bound | |||
let store = new_peer_storage(engine.clone(), raft_engine.clone(), ®ion); |
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.
Could we define an independent function to test lower bound?
/run-all-tests |
@BusyJay @AndreMouche PTAL