-
Notifications
You must be signed in to change notification settings - Fork 6k
unistore: fix the fair locking mechanism in unistore and make foreign key work #56821
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #56821 +/- ##
=================================================
- Coverage 73.3005% 58.0606% -15.2400%
=================================================
Files 1636 1803 +167
Lines 453230 651824 +198594
=================================================
+ Hits 332220 378453 +46233
- Misses 100659 248382 +147723
- Partials 20351 24989 +4638
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Signed-off-by: Yang Keao <[email protected]>
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.
@MyonKeminta PTAL
/cc @MyonKeminta |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: MyonKeminta, you06 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 |
[LGTM Timeline notifier]Timeline:
|
/retest |
What problem does this PR solve?
Issue Number: close #56663
Problem Summary:
When there is an update for the same row in other transactions, it's necessary to update the
for_update_ts
to use the latest data to verify the constraint. Meanwhile, TiDB/TiKV has a mechanism called fair locking to lock the key with conflict.Therefore, when a key is locked, the storage layer (unistore or TiKV) should verify whether other transactions have written this key. If so, it should return the conflict info to TiDB, and TiDB can retry and update the
for_update_ts
.However, the implementation of unistore has a little bug:
For TiKV, it returns the latest TS of both WRITE and LOCK, because they share the similar key (but with different value):
And in the
acquire_pessimistic_lock.rs
:For unistore, the logic of handling pessimistic lock is similar, but unistore stores the LOCK info in a different key:
What changed and how does it work?
We need to also iterate (backward) through the extra txn status keys to get the latest startTS/commitTS.
Check List
Tests
Release note