diff --git a/store/tikv/2pc.go b/store/tikv/2pc.go index 3064f6fe68417..42f053ee3ff5c 100644 --- a/store/tikv/2pc.go +++ b/store/tikv/2pc.go @@ -594,10 +594,6 @@ func (c *twoPhaseCommitter) prewriteSingleBatch(bo *Backoffer, batch batchKeys) } keyErrs := prewriteResp.GetErrors() if len(keyErrs) == 0 { - isPrimary := bytes.Equal(batch.keys[0], c.primary()) - if isPrimary && c.isPessimistic { - c.ttlManager.run(c) - } return nil } var locks []*Lock @@ -766,10 +762,6 @@ func (c *twoPhaseCommitter) pessimisticLockSingleBatch(bo *Backoffer, batch batc } keyErrs := lockResp.GetErrors() if len(keyErrs) == 0 { - isPrimary := bytes.Equal(batch.keys[0], c.primary()) - if isPrimary { // No need to check isPessimistic because this function is only called in that case. - c.ttlManager.run(c) - } return nil } var locks []*Lock diff --git a/store/tikv/txn.go b/store/tikv/txn.go index f6ecdc9b2213a..01a32795437d0 100644 --- a/store/tikv/txn.go +++ b/store/tikv/txn.go @@ -414,6 +414,9 @@ func (txn *tikvTxn) LockKeys(ctx context.Context, forUpdateTS uint64, keysInput } return err } + if assignedPrimaryKey { + txn.committer.ttlManager.run(txn.committer) + } } txn.mu.Lock() txn.lockKeys = append(txn.lockKeys, keys...)