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

ddl: fix unexpected duplicate entry error when adding unique index #56162

Merged
merged 3 commits into from
Sep 20, 2024

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented Sep 19, 2024

What problem does this PR solve?

Issue Number: close #56161

Problem Summary: when merge-temp-index workers check duplicate index keys, they use BatchGet() to get index KV from the origin index and record them as a map. However, this map is not updated while handling temp index records, there may be a false-positive detection.

For example, we have {key_1 -> handle_1, key_2 -> handle_2}. If there is a temp index record like key_1 -> handle_3, then there is a duplicate key.

In this issue, we have two temp index records:

key_1 -> handle_1(deleted)
key_1 -> handle_2

The first record passes the check because a delete operation cannot cause a duplicate key. The second record fails the check because handle_2 != handle_1, even if handle_1 is deleted in the previous operation.

What changed and how does it work?

Maintain the map while handling, and remove the delete keys if necessary.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed do-not-merge/needs-tests-checked labels Sep 19, 2024
Copy link

tiprow bot commented Sep 19, 2024

Hi @tangenta. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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-sigs/prow repository.

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.

Project coverage is 57.0243%. Comparing base (c13eb90) to head (1f6bafb).
Report is 285 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #56162         +/-   ##
=================================================
- Coverage   72.9321%   57.0243%   -15.9079%     
=================================================
  Files          1611       1761        +150     
  Lines        447557     639313     +191756     
=================================================
+ Hits         326413     364564      +38151     
- Misses       101153     249795     +148642     
- Partials      19991      24954       +4963     
Flag Coverage Δ
integration 40.3796% <64.7058%> (?)
unit 72.0600% <88.2352%> (+0.0491%) ⬆️

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

Components Coverage Δ
dumpling 52.9567% <ø> (ø)
parser ∅ <ø> (∅)
br 63.1196% <ø> (+17.2166%) ⬆️

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 19, 2024
Copy link
Collaborator

@Benjamin2037 Benjamin2037 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 20, 2024
Copy link

ti-chi-bot bot commented Sep 20, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-09-19 12:17:00.862277633 +0000 UTC m=+1136290.602701572: ☑️ agreed by wjhuang2016.
  • 2024-09-20 07:42:11.183277862 +0000 UTC m=+1206200.923701801: ☑️ agreed by Benjamin2037.

// checkTempIndexKey determines whether there is a duplicated index key entry according to value of temp index.
// For non-delete temp record, if the index values mismatch, it is duplicated.
// For delete temp record, we decode the handle from the origin index value and temp index value.
// - if the handles matche, we can delete the index key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// - if the handles matche, we can delete the index key.
// - if the handle matches, we can delete the index key.

Copy link

ti-chi-bot bot commented Sep 20, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Benjamin2037, lance6716, wjhuang2016

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

The pull request process is described 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 merged commit 083722a into pingcap:master Sep 20, 2024
22 of 25 checks passed
@tangenta tangenta deleted the rm-batch-val-on-hd-match branch September 24, 2024 03:30
@Benjamin2037 Benjamin2037 added the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label Sep 24, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #56264.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request could not be created: failed to create pull request against pingcap/tidb#release-7.1 from head ti-chi-bot:cherry-pick-56162-to-release-7.1: the GitHub API request returns a 403 error: {"message":"You have exceeded a secondary rate limit and have been temporarily blocked from content creation. Please retry your request again later. If you reach out to GitHub Support for help, please include the request ID ACA6:3F108B:1B76053:33BE970:671F4644 and timestamp 2024-10-28 08:07:33 UTC.","documentation_url":"https://docs.github.com/rest/overview/rate-limits-for-the-rest-api#about-secondary-rate-limits","status":"403"}

@MimeLyc
Copy link

MimeLyc commented Nov 8, 2024

/cherry-pick release-7.1

@ti-chi-bot
Copy link
Member

@MimeLyc: new pull request created to branch release-7.1: #57225.

In response to this:

/cherry-pick release-7.1

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 ti-community-infra/tichi repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

adding unique index reports "duplicate entry" unexpectedly
6 participants