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

*: check delete unique key's handle to handle corner case (#52975) #56886

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions table/tables/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,28 @@

if distinct {
if len(key) > 0 {
err = txn.GetMemBuffer().DeleteWithFlags(key, kv.SetNeedLocked)
if err != nil {
return err
okToDelete := true
if c.idxInfo.BackfillState != model.BackfillStateInapplicable {
// #52914: the delete key is covered by the new ingested key, which shouldn't be deleted.
originVal, err := getKeyInTxn(context.TODO(), txn, key)
if err != nil {
return err
}

Check warning on line 440 in table/tables/index.go

View check run for this annotation

Codecov / codecov/patch

table/tables/index.go#L439-L440

Added lines #L439 - L440 were not covered by tests
if len(originVal) > 0 {
oh, err := tablecodec.DecodeHandleInUniqueIndexValue(originVal, c.tblInfo.IsCommonHandle)
if err != nil {
return err
}

Check warning on line 445 in table/tables/index.go

View check run for this annotation

Codecov / codecov/patch

table/tables/index.go#L444-L445

Added lines #L444 - L445 were not covered by tests
if !h.Equal(oh) {
okToDelete = false
}

Check warning on line 448 in table/tables/index.go

View check run for this annotation

Codecov / codecov/patch

table/tables/index.go#L447-L448

Added lines #L447 - L448 were not covered by tests
}
}
if okToDelete {
err = txn.GetMemBuffer().DeleteWithFlags(key, kv.SetNeedLocked)
if err != nil {
return err
}

Check warning on line 455 in table/tables/index.go

View check run for this annotation

Codecov / codecov/patch

table/tables/index.go#L454-L455

Added lines #L454 - L455 were not covered by tests
}
}
if len(tempKey) > 0 {
Expand Down