-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: upgrade the CheckTxnStatus API #13123
Conversation
CheckTxnStatus introduces a non-block read mode. In this mode, TiDB can ignore the secondary lock TTL check and send the CheckTxnStatus request.
Codecov Report
@@ Coverage Diff @@
## master #13123 +/- ##
================================================
- Coverage 80.8733% 80.1926% -0.6807%
================================================
Files 469 469
Lines 115012 111519 -3493
================================================
- Hits 93014 89430 -3584
- Misses 15054 15197 +143
+ Partials 6944 6892 -52 |
We don't need |
Removed. @coocood Note, we have no switch, so after this PR the resolve lock logic is changed. |
/run-all-tests |
@@ -919,7 +919,7 @@ func rollbackKey(db *leveldb.DB, batch *leveldb.Batch, key []byte, startTS uint6 | |||
return nil | |||
} | |||
|
|||
func rollbackLock(batch *leveldb.Batch, lock mvccLock, key []byte, startTS uint64) error { |
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.
This parameter is not used in the function, so I remove it
return lr.getTxnStatus(bo, l.TxnID, l.Primary, callerStartTS, currentTS) | ||
|
||
rollbackIfNotExist := false | ||
for { |
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.
There is already a for loop in getTxnStatus
why not handle retry in getTxnStatus
directly?
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.
To make the unit test easier.
} | ||
// Call getTxnStatusFromLock to cover the retry logic. | ||
status, err := resolver.getTxnStatusFromLock(bo, lock, currentTS) | ||
c.Assert(err, IsNil) |
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.
At this time, the lock may still not written, we can only be sure it is written after <-errCh
.
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 lock may still not written, and getTxnStatusFromLock
should retry in that case, so we cover the retry logic.
The lock TTL is set to 10s, long enough for the goroutine to finish, the result should be stable.
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.
or we add some sleep before errCh <- xxx
to ensure covering the retry path
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.
or we add some sleep before
errCh <- xxx
to ensure covering the retry path
So as to make the CI slower?
/run-all-tests |
/rebuild |
LGTM |
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
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.
Mostly LGTM
@@ -663,22 +663,22 @@ func (s *testMVCCLevelDB) TestErrors(c *C) { | |||
func (s *testMVCCLevelDB) TestCheckTxnStatus(c *C) { | |||
s.mustPrewriteWithTTLOK(c, putMutations("pk", "val"), "pk", 5, 666) | |||
|
|||
ttl, commitTS, err := s.store.CheckTxnStatus([]byte("pk"), 5, 0, 666) | |||
ttl, commitTS, err := s.store.CheckTxnStatus([]byte("pk"), 5, 0, 666, false) |
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.
I think you need to cover the case where the last parameter is true
.
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.
Done
if _, ok := errors.Cause(err).(txnNotFoundErr); !ok { | ||
return TxnStatus{}, err | ||
} |
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.
I think here it needs comments to explain it.
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.
Done
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
/run-all-tests |
1 similar comment
/run-all-tests |
/run-unit-test |
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
/run-unit-test |
/run-all-tests |
CheckTxnStatus introduces a non-block read mode. In this mode, TiDB can ignore the secondary lock TTL check and send the CheckTxnStatus request.
What problem does this PR solve?
CheckTxnStatus introduces a non-block read mode.
In this mode, TiDB can ignore the secondary lock TTL check and send the CheckTxnStatus request.
What is changed and how it works?
The 2PC prewrite operation writes the primary and the secondary regions concurrently.
When the CheckTxnStatus request arrives, the primary key lock may be still ongoing (secondary locks exist while the primary lock doesn't).
We can back off and retry CheckTxnStatus in that case.
noWait
parameter to the ResolveLocks() functionTxnNotFound
error and retry in getTxnStatusFromLock()RollbackIfNotExist
field of theCheckTxnStatus
request in the mocktikvCheck List
Tests
Code changes
Side effects