Skip to content
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

Merged
merged 7 commits into from
Dec 6, 2017
Merged

Conversation

zhangjinpeng87
Copy link
Member

@zhangjinpeng87 zhangjinpeng87 commented Nov 25, 2017

@zhangjinpeng87 zhangjinpeng87 changed the title support lower_bound for iterator [DNM] support lower_bound for iterator Nov 25, 2017
@zhangjinpeng87 zhangjinpeng87 changed the title [DNM] support lower_bound for iterator support lower_bound for iterator Dec 4, 2017
_ => unreachable!(),
};

self.statistics_cache.add(self.scanner.get_statistics());
let lower_bound = Some(Key::from_raw(&self.range.start).encoded().to_vec());
Copy link
Member

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?

Copy link
Member Author

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());
Copy link
Member

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?

Copy link
Member Author

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 {
Copy link
Member

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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.

@hicqu
Copy link
Contributor

hicqu commented Dec 5, 2017

LGTM.

@BusyJay
Copy link
Member

BusyJay commented Dec 5, 2017

LGTM

Copy link
Member

@AndreMouche AndreMouche left a 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(), &region);
Copy link
Member

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?

@AndreMouche
Copy link
Member

/run-all-tests

@zhangjinpeng87 zhangjinpeng87 merged commit c9d390c into master Dec 6, 2017
@zhangjinpeng87 zhangjinpeng87 deleted the zhangjinpeng/lower-bound branch December 6, 2017 01:04
zhangjinpeng87 added a commit to zhangjinpeng87/tikv that referenced this pull request Dec 6, 2017
zhangjinpeng87 added a commit to zhangjinpeng87/tikv that referenced this pull request Dec 6, 2017
@blacktear23 blacktear23 mentioned this pull request Dec 8, 2017
sticnarf pushed a commit to sticnarf/tikv that referenced this pull request Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants