Skip to content

Commit

Permalink
store/tikv: add sanity check for startTS in 2pc (#9555) (#9558)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing authored and jackysp committed Mar 5, 2019
1 parent ad8e7c5 commit f15460a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions store/tikv/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ func newTwoPhaseCommitter(txn *tikvTxn, connID uint64) (*twoPhaseCommitter, erro
// Convert from sec to ms
maxTxnTimeUse := uint64(config.GetGlobalConfig().TiKVClient.MaxTxnTimeUse) * 1000

// Sanity check for startTS.
if txn.StartTS() == math.MaxUint64 {
err = errors.Errorf("try to commit with invalid startTS: %d", txn.StartTS())
log.Errorf("con:%d 2PC commit err: %v", connID, err)
return nil, errors.Trace(err)
}

metrics.TiKVTxnWriteKVCountHistogram.Observe(float64(len(keys)))
metrics.TiKVTxnWriteSizeHistogram.Observe(float64(size))
return &twoPhaseCommitter{
Expand Down
1 change: 1 addition & 0 deletions store/tikv/2pc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func (s *testCommitterSuite) TestIllegalTso(c *C) {
txn.startTS = uint64(math.MaxUint64)
err := txn.Commit(context.Background())
c.Assert(err, NotNil)
errMsgMustContain(c, err, "invalid startTS")
}

func errMsgMustContain(c *C, err error, msg string) {
Expand Down

0 comments on commit f15460a

Please sign in to comment.