Skip to content

Commit

Permalink
Fix comments; remove unnecessary deep copy (#31945)
Browse files Browse the repository at this point in the history
Co-authored-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
  • Loading branch information
MyonKeminta and MyonKeminta authored Jan 25, 2022
1 parent f1c52ca commit f95b022
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 3 additions & 5 deletions store/driver/txn/txn_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,16 @@ func (txn *tikvTxn) extractKeyExistsErr(key kv.Key) error {
return extractKeyExistsErrFromIndex(key, value, tblInfo, indexID)
}

// SetAssertion sets a assertion for the key operation.
// SetAssertion sets an assertion for the key operation.
func (txn *tikvTxn) SetAssertion(key []byte, assertion ...kv.FlagsOp) error {
// Deep copy the key since it's memory is referenced from union store and overwrite change later.
key1 := append([]byte{}, key...)
f, err := txn.GetUnionStore().GetMemBuffer().GetFlags(key1)
f, err := txn.GetUnionStore().GetMemBuffer().GetFlags(key)
if err != nil && !tikverr.IsErrNotFound(err) {
return err
}
if err == nil && f.HasAssertionFlags() {
return nil
}
txn.GetUnionStore().GetMemBuffer().UpdateFlags(key1, getTiKVFlagsOps(assertion)...)
txn.GetUnionStore().GetMemBuffer().UpdateFlags(key, getTiKVFlagsOps(assertion)...)
return nil
}

Expand Down
2 changes: 0 additions & 2 deletions table/tables/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,6 @@ func TestConstraintCheckForOptimisticUntouched(t *testing.T) {
func TestTxnAssertion(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
// TODO: Locks produced by this test may be left without cleaning up, causing the test runs longer than expected.
// This is caused by that client-go didn't clean up the transaction when `initKeysAndMutations` returns error.

se, err := session.CreateSession4Test(store)
se.SetConnectionID(1)
Expand Down

0 comments on commit f95b022

Please sign in to comment.