tikv / pd

Placement driver for TiKV
Apache License 2.0
1.06k stars 724 forks source link

region: check if the query startkey and endkey specify an uncovered region #8790

Open JackL9u opened 3 weeks ago

JackL9u commented 3 weeks ago

What problem does this PR solve?

handle a special case in GetRegion function

Issue Number: ref #6711

What is changed and how does it work?

The (item, index) returned by GetWithIndex(key) function has the following meaning: 1) if there exists an interval defined by [startkey, endkey) such that startkey == key, then item will be the interval object, and index will be the index of this interval in sorted order (sorted by startkey) 2) otherwise, item will be nil, and index will be the number of intervals whose startkey < key.

Since the return values have different meanings in different situations, I want to unify them. To do this, I want to make sure item object is the largest interval (sorted by startkey) whose startkey <= key, and index is the number of interval object whose startkey <= key. Line 1794 - 1805 did this.

To find out if a key lies in an interval, we need to 1) get the item, index defined above 2) make sure item is not nil (it will be nil if key is less then the smallest startkey) 3) and startkey <= key <= endkey Line 1807 - 1814 did this.

To find out if a region [k1, k2) does not overlap with any existing intervals, we need to 1) make sure both k1 and k2 do NOT lie in an existing interval, and 2) there are equal number of intervals before them The 2) check is necessary in case we have an existing interval [2, 4), and we are querying [1, 5). Without the 2) check, it would return true. Line 1824 - 1826 did this.

Line 1816 - 1823 is handling a special case

Check List

Tests

Code changes

Side effects

Related changes

Release note

None.
ti-chi-bot[bot] commented 3 weeks ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Once this PR has been reviewed and has the lgtm label, please assign rleungx for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files: - **[OWNERS](https://github.com/tikv/pd/blob/master/OWNERS)** Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
ti-chi-bot[bot] commented 3 weeks ago

Hi @JackL9u. Thanks for your PR.

I'm waiting for a tikv member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 75.64%. Comparing base (b27f021) to head (59f8fa0). Report is 4 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #8790 +/- ## ========================================== - Coverage 75.71% 75.64% -0.08% ========================================== Files 461 461 Lines 72285 72329 +44 ========================================== - Hits 54731 54712 -19 - Misses 14045 14116 +71 + Partials 3509 3501 -8 ``` | [Flag](https://app.codecov.io/gh/tikv/pd/pull/8790/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/tikv/pd/pull/8790/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv) | `75.64% <100.00%> (-0.08%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#carryforward-flags-in-the-pull-request-comment) to find out more.
rleungx commented 2 weeks ago

/ok-to-test

okJiang commented 2 weeks ago

Can you add some description to explain your work? For example:

This is very helpful to review your code

JackL9u commented 2 weeks ago

comments updated with explanations.