Skip to content

Commit

Permalink
store/tikv: add sanity check for startTS in 2pc (#9555) (#9559)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing authored and jackysp committed Mar 5, 2019
1 parent 10ec9ee commit 899b7fc
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 @@ -142,6 +142,13 @@ func newTwoPhaseCommitter(txn *tikvTxn, connID uint64) (*twoPhaseCommitter, erro
connID, tableID, size, len(keys), putCnt, delCnt, lockCnt, txn.startTS)
}

// 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)
}

commitDetail := &execdetails.CommitDetails{WriteSize: size, WriteKeys: len(keys)}
metrics.TiKVTxnWriteKVCountHistogram.Observe(float64(commitDetail.WriteKeys))
metrics.TiKVTxnWriteSizeHistogram.Observe(float64(commitDetail.WriteSize))
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 @@ -319,6 +319,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 899b7fc

Please sign in to comment.