Skip to content

Commit

Permalink
check_tso:make sure commit_ts > start_ts during commit in transaction (
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMouche authored and disksing committed Mar 21, 2017
1 parent b4f985f commit 24dd32c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions store/tikv/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,15 @@ func (c *twoPhaseCommitter) execute() error {
log.Warnf("2PC get commitTS failed: %v, tid: %d", err, c.startTS)
return errors.Trace(err)
}

// check commitTS
if commitTS <= c.startTS {
err = errors.Errorf("Invalid transaction tso with start_ts=%v while commit_ts=%v",
c.startTS,
commitTS)
log.Error(err)
return errors.Trace(err)
}
c.commitTS = commitTS
if err := c.checkSchemaValid(); err != nil {
return errors.Trace(err)
Expand Down
17 changes: 17 additions & 0 deletions store/tikv/2pc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tikv

import (
"math"
"math/rand"
"strings"
"time"
Expand Down Expand Up @@ -286,3 +287,19 @@ func (c *slowClient) SendCopReq(ctx goctx.Context, addr string, req *coprocessor
}
return c.Client.SendCopReq(ctx, addr, req, timeout)
}

func (s *testCommitterSuite) TestIllegalTso(c *C) {
txn := s.begin(c)
data := map[string]string{
"name": "aa",
"age": "12",
}
for k, v := range data {
err := txn.Set([]byte(k), []byte(v))
c.Assert(err, IsNil)
}
// make start ts bigger.
txn.startTS = uint64(math.MaxUint64)
err := txn.Commit()
c.Assert(err, NotNil)
}

0 comments on commit 24dd32c

Please sign in to comment.