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

executor: fix update global index return duplicate key error #42311

Merged
merged 1 commit into from Mar 25, 2023

Conversation

L-maple
Copy link
Contributor

@L-maple L-maple commented Mar 16, 2023

What problem does this PR solve?

Issue Number: close #42312

Problem Summary:

What is changed and how it works?

Check List

Tests

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

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

ti-chi-bot commented Mar 16, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Defined2014
  • mjonss

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note-none size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test labels Mar 16, 2023
@ti-chi-bot
Copy link
Member

Hi @L-maple. Thanks for your PR.

I'm waiting for a pingcap 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.

@Defined2014 Defined2014 changed the title fix: fix update global index and update reorg partition for global index executor: fix update global index and update reorg partition for global index Mar 16, 2023
table/tables/index.go Outdated Show resolved Hide resolved
@L-maple L-maple force-pushed the feature/write_for_global_index branch 2 times, most recently from 20def73 to 41af99a Compare March 16, 2023 12:35
errno/errcode.go Outdated Show resolved Hide resolved
@L-maple L-maple force-pushed the feature/write_for_global_index branch from 41af99a to 59384c6 Compare March 17, 2023 02:38
@CbcWestwolf
Copy link
Member

To pass the check_dev, please run make errdoc and generate a new errors.toml

@L-maple L-maple force-pushed the feature/write_for_global_index branch from 59384c6 to 9dc4187 Compare March 17, 2023 06:16
@L-maple
Copy link
Contributor Author

L-maple commented Mar 17, 2023

To pass the check_dev, please run make errdoc and generate a new errors.toml

resolved

@L-maple L-maple force-pushed the feature/write_for_global_index branch 4 times, most recently from 71a6f7e to 28d808d Compare March 17, 2023 11:15
@L-maple L-maple changed the title executor: fix update global index and update reorg partition for global index executor: fix update global index return duplicate key error Mar 17, 2023
@L-maple L-maple force-pushed the feature/write_for_global_index branch from 28d808d to ed7b12b Compare March 20, 2023 03:52
Copy link
Contributor

@Defined2014 Defined2014 left a comment

Choose a reason for hiding this comment

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

LGTM for this PR, Not sure should we concerned about rollback for this situation. /cc @tiancaiamao

tidb/table/tables/partition.go

Lines 1604 to 1609 in fc166ff

// UpdateRecord should be side effect free, but there're two steps here.
// What would happen if step1 succeed but step2 meets error? It's hard
// to rollback.
// So this special order is chosen: add record first, errors such as
// 'Key Already Exists' will generally happen during step1, errors are
// unlikely to happen in step2.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 20, 2023
Copy link
Contributor

@mjonss mjonss left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1952,6 +1953,106 @@ func TestDropPartitionWithGlobalIndex(t *testing.T) {
require.Equal(t, 2, cnt)
}

func TestGlobalIndexInsertInDropPartition(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this test suppose to hit the change/bug or just there for completeness?

tk.MustQuery("select * from test_global use index(idx_b) order by a").Check(testkit.Rows("1 1 1", "2 11 11", "8 8 8", "13 12 12"))
}

func TestGlobalIndexUpdateInDropPartition(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, is this test suppose to hit the change/bug or just there for completeness?

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 22, 2023
@L-maple
Copy link
Contributor Author

L-maple commented Mar 22, 2023 via email

Comment on lines +415 to +428
if c.idxInfo.Global {
if val, err := txn.GetMemBuffer().Get(context.Background(), key); err == nil {
segs := tablecodec.SplitIndexValue(val)
if len(segs.PartitionID) != 0 {
_, pid, err := codec.DecodeInt(segs.PartitionID)
if err != nil {
return err
}
if pid != c.phyTblID {
continue
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I was a bit curious and I wonder if we should change the way we add the indexes here?
I mean if it is a global index, why add it with the physical table ids of the partitions?

@tiancaiamao
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: ed7b12b

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 24, 2023
@mjonss
Copy link
Contributor

mjonss commented Mar 24, 2023

/retest

@hawkingrei
Copy link
Member

/test all

@hawkingrei
Copy link
Member

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test release-note-none size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

executor: for global index update partition keys but returns "Duplicate Key" error
7 participants