Skip to content

Commit

Permalink
Fix the missing unlock in extractKeyExistsErr (#604)
Browse files Browse the repository at this point in the history
Signed-off-by: Yilin Chen <sticnarf@gmail.com>

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
  • Loading branch information
sticnarf committed Oct 12, 2022
1 parent cc4fbe7 commit 624e0ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions integration_tests/2pc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1742,3 +1742,24 @@ func (s *testCommitterSuite) TestFlagsInMemBufferMutations() {
s.Equal(assertNotExist, mutations.IsAssertNotExist(i))
})
}

func (s *testCommitterSuite) TestExtractKeyExistsErr() {
txn := s.begin()
err := txn.Set([]byte("de"), []byte("ef"))
s.Nil(err)
err = txn.Commit(context.Background())
s.Nil(err)

txn = s.begin()
err = txn.GetMemBuffer().SetWithFlags([]byte("de"), []byte("fg"), kv.SetPresumeKeyNotExists)
s.Nil(err)
committer, err := txn.NewCommitter(0)
s.Nil(err)
// Forcibly construct a case when Op_Insert is prewritten while not having KeyNotExists flag.
// In real use cases, it should only happen when enabling amending transactions.
txn.GetMemBuffer().UpdateFlags([]byte("de"), kv.DelPresumeKeyNotExists)
err = committer.PrewriteAllMutations(context.Background())
s.ErrorContains(err, "existErr")
s.True(txn.GetMemBuffer().TryLock())
txn.GetMemBuffer().Unlock()
}
2 changes: 1 addition & 1 deletion txnkv/transaction/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,10 @@ func newTwoPhaseCommitter(txn *KVTxn, sessionID uint64) (*twoPhaseCommitter, err

func (c *twoPhaseCommitter) extractKeyExistsErr(err *tikverr.ErrKeyExist) error {
c.txn.GetMemBuffer().RLock()
defer c.txn.GetMemBuffer().RUnlock()
if !c.txn.us.HasPresumeKeyNotExists(err.GetKey()) {
return errors.Errorf("session %d, existErr for key:%s should not be nil", c.sessionID, err.GetKey())
}
c.txn.GetMemBuffer().RUnlock()
return errors.WithStack(err)
}

Expand Down

0 comments on commit 624e0ed

Please sign in to comment.