Skip to content

storage: support reverse raw_scan and raw_batch_scan#3724

Merged
MyonKeminta merged 27 commits intotikv:masterfrom
kamijin-fanta:master
Nov 15, 2018
Merged

storage: support reverse raw_scan and raw_batch_scan#3724
MyonKeminta merged 27 commits intotikv:masterfrom
kamijin-fanta:master

Conversation

@kamijin-fanta
Copy link
Contributor

What have you changed? (mandatory)

What are the type of the changes? (mandatory)

  • New feature (non-breaking change which adds functionality)

How has this PR been tested? (mandatory)

yes. I added unit test for raw_batch_scan.

Does this PR affect documentation (docs/docs-cn) update? (mandatory)

no.

Does this PR affect tidb-ansible update? (mandatory)

no.

Refer to a related PR or issue link (optional)

Benchmark result if necessary (optional)

Add a few positive/negative examples (optional)

@sre-bot
Copy link
Contributor

sre-bot commented Oct 30, 2018

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@MyonKeminta
Copy link
Contributor

Great job!
Please sign-off your commits and run cargo fmt

@kamijin-fanta
Copy link
Contributor Author

thanks!
I used "sign-off" for the first time. is this ok?

Signed-off-by: kamijin_fanta <kamijin@live.jp>
- for support reverse option pingcap/kvproto#304

Signed-off-by: kamijin_fanta <kamijin@live.jp>
- add reverse request test cases
- support reverse in check_key_range
- for support reverse option pingcap/kvproto#304

Signed-off-by: kamijin_fanta <kamijin@live.jp>
@MyonKeminta
Copy link
Contributor

Yes! And, please also fix the error messages from CircleCI

@MyonKeminta MyonKeminta changed the title support reverse scan support reverse raw_scan Oct 30, 2018
Signed-off-by: kamijin_fanta <kamijin@live.jp>
@MyonKeminta MyonKeminta changed the title support reverse raw_scan support reverse raw_scan and raw_batch_scan Oct 30, 2018
@MyonKeminta
Copy link
Contributor

MyonKeminta commented Oct 30, 2018

In fact, I think it's better if the range to scan is always [start_key, end_key) whenever we are scanning forward or backward, which is more close to our semantics of the term "start_key" and "end_key".
@breeswish @zhangjinpeng1987 How do you think about it?

Signed-off-by: kamijin_fanta <kamijin@live.jp>
@MyonKeminta MyonKeminta added type/enhancement The issue or PR belongs to an enhancement. component/storage Component: Storage, Scheduler, etc. contribution This PR is from a community contributor. labels Oct 30, 2018
Signed-off-by: kamijin_fanta <kamijin@live.jp>
@kamijin-fanta
Copy link
Contributor Author

lowerBound / upperBound and startKey / endKey are distinguished in the code.
so, I wrote such a code.

@breezewish
Copy link
Member

Actually currently our semantic is that there is a range [lower_bound, upper_bound). when we do forward scan, we scan from lower_bound to upper_bound in the range. When we do reverse scan, we scan from upper_bound to lower_bound in the range. Maybe we can rename start_key to lower_bound and end_key to upper_bound to be less ambiguous?

@MyonKeminta
Copy link
Contributor

@breeswish Seems it's not easy, since you may need to change the fields' name in kvproto

@MyonKeminta
Copy link
Contributor

@breeswish oh, sorry, it seems renaming fields in kvproto won't break compatibility between tikv and rpc client..?

@MyonKeminta
Copy link
Contributor

At least I think the fields of KeyRange should keep their meanings.
Neither should we rename the fields in it.

In coprocessor.proto:

// [start, end)
message KeyRange {
    bytes start = 1;
    bytes end = 2;
}

In kvrpcpb.proto

message KeyRange {
  bytes start_key = 1;
  bytes end_key = 2;
}

If we change them, we may introduce too much changes to TiKV and TiDB.
I think it's better to let [start_key, end_key) equivalent to [lower_bound, upper_bound) now.

@kamijin-fanta
Copy link
Contributor Author

the consistency between startKey of ScanRequest and startKey of inside is lost.

message ScanRequest {
    Context context = 1;
    bytes start_key = 2;
    uint32 limit = 3;
    uint64 version = 4;
    bool key_only = 5;
    bool reverse = 6;
}

https://github.com/pingcap/kvproto/blob/855d2192cdc79c7353cf36e6b60e049bf436dc8a/proto/kvrpcpb.proto#L94-L101

I think it is easy to understand clearly distinguish between startKey and lowerBound.

@MyonKeminta
Copy link
Contributor

OK. Let's accept this. But please add some comments to explain why start_key is the greater one.

- check_key_ranges
- no specify end_key in reverse batch scan request

Signed-off-by: kamijin_fanta <kamijin@live.jp>
- invert reverse option in raw_scan, reverse_raw_scan

Signed-off-by: kamijin_fanta <kamijin@live.jp>
@breezewish
Copy link
Member

For the following two ranges, it looks wired in the reverse mode.. The first one is a, b, c and the second one is c, b, a. I prefer to keep the same global total order for all possible ranges in reverse mode, i.e. for every range (a_i, b_i) at index i, we have a_i > a_i+1.

        let ranges = make_ranges(vec![
            (b"a3".to_vec(), b"a".to_vec()),
            (b"b3".to_vec(), b"b".to_vec()),
            (b"c3".to_vec(), b"c".to_vec()),
        ]);
         let ranges = make_ranges(vec![
            (b"c3".to_vec(), vec![]),
            (b"b3".to_vec(), vec![]),
            (b"a3".to_vec(), vec![]),
        ]);

@breezewish
Copy link
Member

How do you think @MyonKeminta

@MyonKeminta
Copy link
Contributor

@breeswish IMO, I think both are ok..

Copy link
Contributor

@MyonKeminta MyonKeminta left a comment

Choose a reason for hiding this comment

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

LGTM

@MyonKeminta MyonKeminta changed the title support reverse raw_scan and raw_batch_scan storage: support reverse raw_scan and raw_batch_scan Nov 9, 2018
@siddontang
Copy link
Contributor

PTAL @breeswish

@breezewish
Copy link
Member

Is it possible to specify ranges in reverse mode like below?

        let ranges = make_ranges(vec![
            (b"c3".to_vec(), b"c".to_vec()),
            (b"b3".to_vec(), b"b".to_vec()),
            (b"a3".to_vec(), b"a".to_vec()),
        ]);

@kamijin-fanta
Copy link
Contributor Author

@breeswish yes

Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

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

Okay

@breezewish breezewish added the status/LGT2 Indicates that a PR has LGTM 2. label Nov 13, 2018
@kamijin-fanta
Copy link
Contributor Author

what is the status of this PR?

@MyonKeminta
Copy link
Contributor

Oh, sorry
/run-integration-tests

@breezewish breezewish removed the type/enhancement The issue or PR belongs to an enhancement. label Nov 15, 2018
@MyonKeminta
Copy link
Contributor

/run-integration-common-test

1 similar comment
@MyonKeminta
Copy link
Contributor

/run-integration-common-test

@MyonKeminta MyonKeminta merged commit 3025141 into tikv:master Nov 15, 2018
@kamijin-fanta
Copy link
Contributor Author

Thank you for the merge! 🎉

MyonKeminta pushed a commit to MyonKeminta/tikv that referenced this pull request Jul 29, 2019
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
youjiali1995 pushed a commit that referenced this pull request Aug 2, 2019
* storage: Support reverse raw_scan and raw_batch_scan (#3724)

Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>

* Update kvproto

Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
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

component/storage Component: Storage, Scheduler, etc. contribution This PR is from a community contributor. status/LGT2 Indicates that a PR has LGTM 2.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants