Skip to content

Commit

Permalink
test:stablize test case prewrite secondaries (#18751)
Browse files Browse the repository at this point in the history
* stablize test case prewrite secondaries

* try to fix race

Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
  • Loading branch information
cfzjywxk and ti-srebot authored Jul 24, 2020
1 parent a4c9f81 commit bd733c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions store/tikv/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type twoPhaseCommitter struct {
testingKnobs struct {
acAfterCommitPrimary chan struct{}
bkAfterCommitPrimary chan struct{}
noFallBack bool
}

useAsyncCommit uint32
Expand Down
8 changes: 5 additions & 3 deletions store/tikv/2pc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions store/tikv/prewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bd733c3

Please sign in to comment.