Fix the missing unlock in extractKeyExistsErr (#603)

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
This commit is contained in:
Yilin Chen 2022-10-12 15:48:56 +08:00 committed by GitHub
parent dc130aa0d3
commit 6def8d7b90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -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()
}

View File

@ -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)
}