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 the missing unlock in extractKeyExistsErr #603

Merged
merged 1 commit into from
Oct 12, 2022
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
21 changes: 21 additions & 0 deletions integration_tests/2pc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1953,3 +1953,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 @@ -459,10 +459,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