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
store/tikv: fix duplicated lock keys caused data inconsistency. #16752
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -3259,7 +3259,7 @@ func (b *PlanBuilder) buildUpdate(ctx context.Context, update *ast.UpdateStmt) ( | |||
} | |||
} | |||
if b.ctx.GetSessionVars().TxnCtx.IsPessimistic { | |||
if !update.MultipleTable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove these unused fields to avoid using mistakenly in the future, so dangerous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in another repo, we can do it later.
}) | ||
deduped := keys[:1] | ||
for i := 1; i < len(keys); i++ { | ||
if !bytes.Equal(deduped[len(deduped)-1], keys[i]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add warn logs here to remind there could be possible bugs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to support lock duplicated keys in the future.
@@ -3259,7 +3259,7 @@ func (b *PlanBuilder) buildUpdate(ctx context.Context, update *ast.UpdateStmt) ( | |||
} | |||
} | |||
if b.ctx.GetSessionVars().TxnCtx.IsPessimistic { | |||
if !update.MultipleTable { | |||
if update.TableRefs.TableRefs.Right == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to add some comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And does
tidb/planner/core/logical_plan_builder.go
Line 3535 in c601324
if !delete.IsMultiTable { |
work well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The world is too dangerous...
Codecov Report
@@ Coverage Diff @@
## master #16752 +/- ##
===========================================
Coverage 80.4432% 80.4432%
===========================================
Files 507 507
Lines 137477 137477
===========================================
Hits 110591 110591
Misses 18282 18282
Partials 8604 8604 |
@@ -357,6 +359,7 @@ func (txn *tikvTxn) LockKeys(ctx context.Context, lockCtx *kv.LockCtx, keysInput | |||
if len(keys) == 0 { | |||
return nil | |||
} | |||
keys = deduplicateKeys(keys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary after
https://github.com/pingcap/tidb/pull/16752/files#diff-b9e75a99170ea35a67074d5d3d3305adR3262
changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the second line of defense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it hurts the performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the proportion would be tiny.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
/run-all-tests |
@coocood merge failed. |
/run-integration-copr-test |
Signed-off-by: sre-bot <sre-bot@pingcap.com>
cherry pick to release-4.0 in PR #16769 |
What problem does this PR solve?
Problem Summary:
Update
MultipleTable
field is not correct, adding SelectLock operator for multiple table update causesLockKeys
contains duplicated keys.When LockKeys contains duplicated keys, the transaction may overwrite Put operation with Lock operation, cause admin check table failure.
What is changed and how it works?
What's Changed:
LockKeys
method.Related changes
Check List
Tests
Side effects
Release note
fix duplicated lock keys caused data inconsistency.