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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JackL9u
Copy link
Contributor

@JackL9u JackL9u commented Nov 7, 2024

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

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Code changes

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

Release note

None.

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. labels Nov 7, 2024
Copy link
Contributor

ti-chi-bot bot commented Nov 7, 2024

[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:

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 ti-chi-bot bot added the needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. label Nov 7, 2024
Copy link
Contributor

ti-chi-bot bot commented Nov 7, 2024

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. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 7, 2024
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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 Coverage Δ
unittests 75.64% <100.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@rleungx
Copy link
Member

rleungx commented Nov 11, 2024

/ok-to-test

@ti-chi-bot ti-chi-bot bot added ok-to-test Indicates a PR is ready to be tested. and removed needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Nov 11, 2024
@rleungx rleungx requested a review from lhy1024 November 11, 2024 03:22
@okJiang
Copy link
Member

okJiang commented Nov 13, 2024

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

  • How does it work?
  • Why can it solve this issue?

This is very helpful to review your code

@JackL9u
Copy link
Contributor Author

JackL9u commented Nov 14, 2024

comments updated with explanations.

Comment on lines +1807 to +1809
startInAnInterval := false
if startItem != nil {
startInAnInterval = (bytes.Compare(startItem.GetStartKey(), startKey) <= 0) && (bytes.Compare(startKey, startItem.GetEndKey()) <= 0)
Copy link
Member

Choose a reason for hiding this comment

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

If the startItem != nil (L1799), startInAnInterval is true?

}
endInAnInterval := false
if endItem != nil {
endInAnInterval = (bytes.Compare(endItem.GetStartKey(), endKey) <= 0) && (bytes.Compare(endKey, endItem.GetEndKey()) <= 0)
Copy link
Member

Choose a reason for hiding this comment

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

ditto

eit = r.tree.tree.Len()
endInAnInterval = false
if endItem != nil {
endInAnInterval = (bytes.Compare(endItem.GetEndKey(), endKey) <= 0) && (bytes.Compare(endKey, endItem.GetEndKey()) <= 0)
Copy link
Member

Choose a reason for hiding this comment

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

why do you check endkey when it is empty?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has signed the dco. ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants