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

*: fix condition check push down for pessimistic transaction (#14141) #14175

Merged
merged 1 commit into from
Dec 23, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions session/pessimistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,22 @@ func (s *testPessimisticSuite) TestInnodbLockWaitTimeout(c *C) {
tk.MustExec("drop table if exists tk")
}

func (s *testPessimisticSuite) TestPushConditionCheckForPessimisticTxn(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk1 := testkit.NewTestKitWithInit(c, s.store)
defer tk.MustExec("drop table if exists t")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (i int key)")
tk.MustExec("insert into t values (1)")

tk.MustExec("set tidb_txn_mode = 'pessimistic'")
tk.MustExec("begin")
tk1.MustExec("delete from t where i = 1")
tk.MustExec("insert into t values (1) on duplicate key update i = values(i)")
tk.MustExec("commit")
tk.MustQuery("select * from t").Check(testkit.Rows("1"))
}

func (s *testPessimisticSuite) TestInnodbLockWaitTimeoutWaitStart(c *C) {
// prepare work
tk := testkit.NewTestKitWithInit(c, s.store)
Expand Down
4 changes: 3 additions & 1 deletion store/mockstore/mocktikv/mvcc_leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ func (mvcc *MVCCLevelDB) Prewrite(req *kvrpcpb.PrewriteRequest) []error {
mutations := req.Mutations
primary := req.PrimaryLock
startTS := req.StartVersion
forUpdateTS := req.GetForUpdateTs()
ttl := req.LockTtl
mvcc.mu.Lock()
defer mvcc.mu.Unlock()
Expand All @@ -639,7 +640,8 @@ func (mvcc *MVCCLevelDB) Prewrite(req *kvrpcpb.PrewriteRequest) []error {
for i, m := range mutations {
// If the operation is Insert, check if key is exists at first.
var err error
if m.GetOp() == kvrpcpb.Op_Insert {
// no need to check insert values for pessimistic transaction.
if m.GetOp() == kvrpcpb.Op_Insert && forUpdateTS == 0 {
v, err := mvcc.getValue(m.Key, startTS, kvrpcpb.IsolationLevel_SI)
if err != nil {
errs = append(errs, err)
Expand Down