-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: set txn options in txn provider which avoid data race #52304
Conversation
Signed-off-by: you06 <[email protected]>
Hi @you06. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Signed-off-by: you06 <[email protected]>
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #52304 +/- ##
================================================
+ Coverage 72.1416% 74.0886% +1.9470%
================================================
Files 1467 1467
Lines 426665 429290 +2625
================================================
+ Hits 307803 318055 +10252
+ Misses 99697 91320 -8377
- Partials 19165 19915 +750
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Signed-off-by: you06 <[email protected]>
Signed-off-by: you06 <[email protected]>
/ok-to-test |
Signed-off-by: you06 <[email protected]>
Signed-off-by: you06 <[email protected]>
} | ||
|
||
if interceptor := temptable.SessionSnapshotInterceptor(p.sctx, p.infoSchema); interceptor != nil { | ||
txn.SetOption(kv.SnapInterceptor, interceptor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The txnSetOption
should be deprecated to avoid mis-usages in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
txn.SetOption
is widely used in some internal packages, I don't have confidence to deprecate it since it takes too many capabilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is it possible to also check the newly added isCommitterworking
inside the tikvTxn.SetOption
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it so, but only in test environment, see https://github.com/pingcap/tidb/pull/52304/files#diff-2aa8e8b32ea03a38f0f9a2850ed09a21848ee98686785d3a7dcee9a4d530f8b9R217-R219
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why just check in test? I think checking the txn status when SetOption
is the key to avoid future mistakes.
Signed-off-by: you06 <[email protected]>
Signed-off-by: you06 <[email protected]>
Signed-off-by: you06 <[email protected]>
/retest |
pkg/session/session.go
Outdated
|
||
sessiontxn.GetTxnManager(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, that's a mistake
} | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we forget to set kv.CommitTSUpperBoundCheck
when commitTSChecker
is not nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
Signed-off-by: you06 <[email protected]>
} | ||
|
||
if interceptor := temptable.SessionSnapshotInterceptor(p.sctx, p.infoSchema); interceptor != nil { | ||
txn.SetOption(kv.SnapInterceptor, interceptor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why just check in test? I think checking the txn status when SetOption
is the key to avoid future mistakes.
@@ -200,6 +214,9 @@ func (txn *tikvTxn) GetMemBuffer() kv.MemBuffer { | |||
} | |||
|
|||
func (txn *tikvTxn) SetOption(opt int, val any) { | |||
if intest.InTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why just check in tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the current implementation is ok, if this check only works in tests, we can just panic rather than returning and checking error. Another reason, compile with intest.InTest
won't impact the performance of release builds.
@@ -78,6 +81,10 @@ func (txn *tikvTxn) CacheTableInfo(id int64, info *model.TableInfo) { | |||
} | |||
|
|||
func (txn *tikvTxn) LockKeys(ctx context.Context, lockCtx *kv.LockCtx, keysInput ...kv.Key) error { | |||
if intest.InTest { | |||
txn.isCommitterWorking.Store(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why set isCommitterWorking
when InTest
? The InTest
is a little confusing.
@you06 Need approvements from the owners. |
@easonn7 PTAL |
@wjhuang2016 @tangenta |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cfzjywxk, easonn7, zimulala, zyguan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/merge |
@you06: We have migrated to builtin Please use
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: ref #50215
Problem Summary:
Move most
SetOption
usages into txn provider, manage them together, this can help us avoid data race in clear way.What changed and how does it work?
Check List
Tests
The test in sessiontxn package is passed with this PR's modification.
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.