Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store/tikv: add sanity check for startTS in 2pc (#9555) #9559

Merged
merged 1 commit into from Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions store/tikv/2pc.go
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
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