Skip to content

Commit

Permalink
Merge branch 'release-5.1' into release-5.1-8dcebd12395d
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 committed Sep 7, 2021
2 parents 9577fb3 + ce45483 commit 20a8b66
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions store/tikv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,16 +593,20 @@ func (txn *KVTxn) LockKeys(ctx context.Context, lockCtx *tikv.LockCtx, keysInput
keyMayBeLocked := !(tikverr.IsErrWriteConflict(err) || tikverr.IsErrKeyExist(err))
// If there is only 1 key and lock fails, no need to do pessimistic rollback.
if len(keys) > 1 || keyMayBeLocked {
dl, ok := errors.Cause(err).(*tikverr.ErrDeadlock)
if ok && lockCtx.OnDeadlock != nil {
// Call OnDeadlock before pessimistic rollback.
lockCtx.OnDeadlock(dl)
dl, isDeadlock := errors.Cause(err).(*tikverr.ErrDeadlock)
if isDeadlock {
if hashInKeys(dl.DeadlockKeyHash, keys) {
dl.IsRetryable = true
}
if lockCtx.OnDeadlock != nil {
// Call OnDeadlock before pessimistic rollback.
lockCtx.OnDeadlock(dl)
}
}
wg := txn.asyncPessimisticRollback(ctx, keys)
if ok {
if isDeadlock {
logutil.Logger(ctx).Debug("deadlock error received", zap.Uint64("startTS", txn.startTS), zap.Stringer("deadlockInfo", dl))
if hashInKeys(dl.DeadlockKeyHash, keys) {
dl.IsRetryable = true
if dl.IsRetryable {
// Wait for the pessimistic rollback to finish before we retry the statement.
wg.Wait()
// Sleep a little, wait for the other transaction that blocked by this transaction to acquire the lock.
Expand Down

0 comments on commit 20a8b66

Please sign in to comment.