From c6699bdafef83622b29ee8ed407abe691d46273b Mon Sep 17 00:00:00 2001 From: Yilin Chen Date: Wed, 12 May 2021 16:34:45 +0800 Subject: [PATCH] store/tikv: use latest PD TS plus one as min commit ts Signed-off-by: Yilin Chen --- store/tikv/2pc.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/store/tikv/2pc.go b/store/tikv/2pc.go index 8703b1861c65d..5812f5d83791c 100644 --- a/store/tikv/2pc.go +++ b/store/tikv/2pc.go @@ -992,17 +992,18 @@ func (c *twoPhaseCommitter) execute(ctx context.Context) (err error) { // If we want to use async commit or 1PC and also want linearizability across // all nodes, we have to make sure the commit TS of this transaction is greater // than the snapshot TS of all existent readers. So we get a new timestamp - // from PD as our MinCommitTS. + // from PD and plus one as our MinCommitTS. if commitTSMayBeCalculated && c.needLinearizability() { failpoint.Inject("getMinCommitTSFromTSO", nil) - minCommitTS, err := c.store.oracle.GetTimestamp(ctx, &oracle.Option{TxnScope: oracle.GlobalTxnScope}) + latestTS, err := c.store.oracle.GetTimestamp(ctx, &oracle.Option{TxnScope: oracle.GlobalTxnScope}) // If we fail to get a timestamp from PD, we just propagate the failure // instead of falling back to the normal 2PC because a normal 2PC will // also be likely to fail due to the same timestamp issue. if err != nil { return errors.Trace(err) } - c.minCommitTS = minCommitTS + // Plus 1 to avoid producing the same commit TS with previously committed transactions + c.minCommitTS = latestTS + 1 } // Calculate maxCommitTS if necessary if commitTSMayBeCalculated {