diff --git a/store/tikv/2pc.go b/store/tikv/2pc.go index dfbbff3f24d28..794e3c2656a9b 100644 --- a/store/tikv/2pc.go +++ b/store/tikv/2pc.go @@ -99,6 +99,7 @@ type twoPhaseCommitter struct { testingKnobs struct { acAfterCommitPrimary chan struct{} bkAfterCommitPrimary chan struct{} + noFallBack bool } useAsyncCommit uint32 diff --git a/store/tikv/2pc_test.go b/store/tikv/2pc_test.go index 486981c4dcdb3..a849003689a6f 100644 --- a/store/tikv/2pc_test.go +++ b/store/tikv/2pc_test.go @@ -47,6 +47,7 @@ var _ = SerialSuites(&testCommitterSuite{}) func (s *testCommitterSuite) SetUpSuite(c *C) { atomic.StoreUint64(&ManagedLockTTL, 3000) // 3s s.OneByOneSuite.SetUpSuite(c) + CommitMaxBackoff = 1000 } func (s *testCommitterSuite) SetUpTest(c *C) { @@ -77,7 +78,6 @@ func (s *testCommitterSuite) SetUpTest(c *C) { // c.Assert(err, IsNil) s.store = store - CommitMaxBackoff = 1000 } func (s *testCommitterSuite) TearDownSuite(c *C) { @@ -1137,7 +1137,7 @@ func (s *testCommitterSuite) TestResolveMixed(c *C) { // TestSecondaryKeys tests that when async commit is enabled, each prewrite message includes an // accurate list of secondary keys. -func (s *testCommitterSuite) TestPrewiteSecondaryKeys(c *C) { +func (s *testCommitterSuite) TestPrewriteSecondaryKeys(c *C) { defer config.RestoreFunc()() config.UpdateGlobal(func(conf *config.Config) { conf.TiKVClient.EnableAsyncCommit = true @@ -1169,9 +1169,11 @@ func (s *testCommitterSuite) TestPrewiteSecondaryKeys(c *C) { ctx := context.Background() // TODO remove this when minCommitTS is returned from mockStore prewrite response. committer.minCommitTS = committer.startTS + 10 + committer.testingKnobs.noFallBack = true err = committer.execute(ctx) c.Assert(err, IsNil) - c.Assert(mock.seenPrimaryReq > 0 && mock.seenSecondaryReq > 0, IsTrue) + c.Assert(mock.seenPrimaryReq > 0, IsTrue) + c.Assert(mock.seenSecondaryReq > 0, IsTrue) } func (s *testCommitterSuite) TestAsyncCommit(c *C) { diff --git a/store/tikv/prewrite.go b/store/tikv/prewrite.go index 825a2c88f0dbc..eceaafec79282 100644 --- a/store/tikv/prewrite.go +++ b/store/tikv/prewrite.go @@ -135,6 +135,9 @@ func (action actionPrewrite) handleSingleBatch(c *twoPhaseCommitter, bo *Backoff // commit cannot proceed. The client can then fallback to normal way to // continue committing the transaction if prewrite are all finished. if prewriteResp.MinCommitTs == 0 { + if c.testingKnobs.noFallBack { + return nil + } logutil.Logger(bo.ctx).Warn("async commit cannot proceed since the returned minCommitTS is zero, "+ "fallback to normal path", zap.Uint64("startTS", c.startTS)) c.setAsyncCommit(false)