diff --git a/store/tikv/2pc.go b/store/tikv/2pc.go index 7d87e8a7b4740..2f8684d3ca22f 100644 --- a/store/tikv/2pc.go +++ b/store/tikv/2pc.go @@ -550,10 +550,6 @@ func (c *twoPhaseCommitter) prewriteSingleBatch(bo *Backoffer, batch batchKeys) prewriteResp := resp.Resp.(*pb.PrewriteResponse) 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 @@ -712,10 +708,6 @@ func (c *twoPhaseCommitter) pessimisticLockSingleBatch(bo *Backoffer, batch batc lockResp := resp.Resp.(*pb.PessimisticLockResponse) 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 e90c5a1046928..45edc068eaa00 100644 --- a/store/tikv/txn.go +++ b/store/tikv/txn.go @@ -442,6 +442,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...)