Skip to content

Commit

Permalink
store/tikv: set short pessimistic lock TTL through failpoints (#22431)
Browse files Browse the repository at this point in the history
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
  • Loading branch information
sticnarf authored Jan 21, 2021
1 parent dd8fd16 commit 90a98ce
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion store/tikv/pessimistic.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tikv

import (
"encoding/hex"
"math/rand"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -73,12 +74,22 @@ func (action actionPessimisticLock) handleSingleBatch(c *twoPhaseCommitter, bo *
mutations[i] = mut
}
elapsed := uint64(time.Since(c.txn.startTime) / time.Millisecond)
ttl := elapsed + atomic.LoadUint64(&ManagedLockTTL)
failpoint.Inject("shortPessimisticLockTTL", func() {
ttl = 1
keys := make([]string, 0, len(mutations))
for _, m := range mutations {
keys = append(keys, hex.EncodeToString(m.Key))
}
logutil.BgLogger().Info("[failpoint] injected lock ttl = 1 on pessimistic lock",
zap.Uint64("txnStartTS", c.startTS), zap.Strings("keys", keys))
})
req := tikvrpc.NewRequest(tikvrpc.CmdPessimisticLock, &pb.PessimisticLockRequest{
Mutations: mutations,
PrimaryLock: c.primary(),
StartVersion: c.startTS,
ForUpdateTs: c.forUpdateTS,
LockTtl: elapsed + atomic.LoadUint64(&ManagedLockTTL),
LockTtl: ttl,
IsFirstLock: c.isFirstLock,
WaitTimeout: action.LockWaitTime,
ReturnValues: action.ReturnValues,
Expand Down

0 comments on commit 90a98ce

Please sign in to comment.