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

txn: Fix data race of checking and exiting fair locking concurrently in LockKeys #42635

Merged
merged 3 commits into from
Mar 28, 2023
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
4 changes: 2 additions & 2 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4108,8 +4108,8 @@ def go_deps():
name = "com_github_tikv_client_go_v2",
build_file_proto_mode = "disable_global",
importpath = "github.com/tikv/client-go/v2",
sum = "h1:m5Y7tBW5Rq8L1ANxibitBa/DInDy3hA2Qvk1Ys9u1NU=",
version = "v2.0.7-0.20230317032622-884a634378d4",
sum = "h1:XpdZrei86oIrRjXbqvlQh23TdHXVtSxWmsxxwy/Zgc0=",
version = "v2.0.7-0.20230328084104-ea13e9700259",
)
go_repository(
name = "com_github_tikv_pd",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ require (
github.com/stretchr/testify v1.8.2
github.com/tdakkota/asciicheck v0.2.0
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tikv/client-go/v2 v2.0.7-0.20230317032622-884a634378d4
github.com/tikv/client-go/v2 v2.0.7-0.20230328084104-ea13e9700259
github.com/tikv/pd/client v0.0.0-20230324033443-79ec29cee8db
github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e
github.com/twmb/murmur3 v1.1.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,8 @@ github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJf
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU=
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW93SG+q0F8KI+yFrcIDT4c/RNoc4=
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM=
github.com/tikv/client-go/v2 v2.0.7-0.20230317032622-884a634378d4 h1:m5Y7tBW5Rq8L1ANxibitBa/DInDy3hA2Qvk1Ys9u1NU=
github.com/tikv/client-go/v2 v2.0.7-0.20230317032622-884a634378d4/go.mod h1:DPL03G+QwLmypNjDIl+B02UltorBMx3WzSh4yJbp+cw=
github.com/tikv/client-go/v2 v2.0.7-0.20230328084104-ea13e9700259 h1:XpdZrei86oIrRjXbqvlQh23TdHXVtSxWmsxxwy/Zgc0=
github.com/tikv/client-go/v2 v2.0.7-0.20230328084104-ea13e9700259/go.mod h1:J6zUseSVj8p+Uyr1QQugZsPuksazVE1P4lbhSPISQ/o=
github.com/tikv/pd/client v0.0.0-20230324033443-79ec29cee8db h1:hZ9gL1wq4dnIzEHjoTB4MHiqi3cA6pqANL4yxUtyCP0=
github.com/tikv/pd/client v0.0.0-20230324033443-79ec29cee8db/go.mod h1:3cTcfo8GRA2H/uSttqA3LvMfMSHVBJaXk3IgkFXFVxo=
github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e h1:MV6KaVu/hzByHP0UvJ4HcMGE/8a6A4Rggc/0wx2AvJo=
Expand Down
14 changes: 0 additions & 14 deletions store/driver/txn/txn_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (txn *tikvTxn) CacheTableInfo(id int64, info *model.TableInfo) {

func (txn *tikvTxn) LockKeys(ctx context.Context, lockCtx *kv.LockCtx, keysInput ...kv.Key) error {
keys := toTiKVKeys(keysInput)
txn.exitFairLockingIfInapplicable(ctx, keys)
err := txn.KVTxn.LockKeys(ctx, lockCtx, keys...)
if err != nil {
return txn.extractKeyErr(err)
Expand All @@ -89,7 +88,6 @@ func (txn *tikvTxn) LockKeys(ctx context.Context, lockCtx *kv.LockCtx, keysInput

func (txn *tikvTxn) LockKeysFunc(ctx context.Context, lockCtx *kv.LockCtx, fn func(), keysInput ...kv.Key) error {
keys := toTiKVKeys(keysInput)
txn.exitFairLockingIfInapplicable(ctx, keys)
err := txn.KVTxn.LockKeysFunc(ctx, lockCtx, fn, keys...)
if err != nil {
return txn.extractKeyErr(err)
Expand Down Expand Up @@ -357,18 +355,6 @@ func (txn *tikvTxn) UpdateMemBufferFlags(key []byte, flags ...kv.FlagsOp) {
txn.GetUnionStore().GetMemBuffer().UpdateFlags(key, getTiKVFlagsOps(flags)...)
}

func (txn *tikvTxn) exitFairLockingIfInapplicable(ctx context.Context, keys [][]byte) {
if len(keys) > 1 && txn.IsInAggressiveLockingMode() {
// Only allow fair locking if it only needs to lock one key. Considering that it's possible that a
// statement causes multiple calls to `LockKeys` (which means some keys may have been locked in fair
// locking mode), here we exit fair locking mode by calling DoneFairLocking instead of cancelling.
// Then the previously-locked keys during execution in this statement (if any) will be turned into the state
// as if they were locked in normal way.
// Note that the issue https://github.com/pingcap/tidb/issues/35682 also exists here.
txn.KVTxn.DoneAggressiveLocking(ctx)
}
}

func (txn *tikvTxn) generateWriteConflictForLockedWithConflict(lockCtx *kv.LockCtx) error {
if lockCtx.MaxLockedWithConflictTS != 0 {
failpoint.Inject("lockedWithConflictOccurs", func() {})
Expand Down