-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: avoid pass session ID by context & fix no schemaChecker error log #24696
Conversation
[REVIEW NOTIFICATION] This pull request has not been approved. To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by writing |
@@ -369,9 +368,7 @@ func (txn *KVTxn) Commit(ctx context.Context) error { | |||
// pessimistic transaction should also bypass latch. | |||
if txn.store.txnLatches == nil || txn.IsPessimistic() { | |||
err = committer.execute(ctx) | |||
if val == nil || sessionID > 0 { |
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.
Will this make the following logic executed unexpected for the inner session statements whose session id is 0?
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.
For internal queries, val
is always nil; for external queries sessionID > 0
always hold,
so val == nil || sessionID > 0
is basically always true
? @MyonKeminta
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.
Now I've change it to:
sessionID > 0
=> onCommit
sessionID == 0
=> nothing
The original author means to call onCommit
for external queries (although val == nil
may be confusing in the old code).
@cfzjywxk
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.
maybe it's hard to distinguish external from internal queries form sessionID
?
InRestrictedSQL also can call doCommit
Line 521 in c3f9b08
s.txn.SetOption(kv.SessionID, s.GetSessionVars().ConnectionID) |
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.
If we take a session from the session pool to execute the SQL, sessionID
is not set.
However, if we direct use the session to execute a internal SQL, that might be a problem.
@@ -306,7 +306,6 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) { | |||
}() | |||
|
|||
sctx := a.Ctx | |||
ctx = util.SetSessionID(ctx, sctx.GetSessionVars().ConnectionID) |
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.
it seems some other test case
tidb/store/tikv/region_request.go
Line 413 in 18cbfaa
if v := bo.GetCtx().Value(util.SessionID); v != nil { |
@MyonKeminta PTAL
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 have updated the test, you can see the _test.go
file changes in this PR
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.
it seems the previous
tidb/store/tikv/region_request.go
Line 465 in 18cbfaa
inject = false |
will be used in some test case that out of tidb repo
https://github.com/pingcap/automated-tests/blob/cc44a56fd59cfdb71eaf37210e0861ba7acdc925/ticases/transaction/asynccommit/linearizability.go#L445
I'm not sure whether it works 😞
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.
Seems we may change the session id related logic too or abstract a isInnerExecution
accordingly.
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.
Yes that's a problem. Some failpoints that's used by tests outside the repo checks the session id and works only when session id != 0. These kind of usages also occurs in 2pc.go, prewrite.go, etc.
@tiancaiamao: PR needs rebase. 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. |
Close for now, it's not a very easy fix. |
What problem does this PR solve?
Issue Number: close #22783
Problem Summary:
Pass important argument by
context.WithValue
is a bad idea.The callee need the data in the
context.Context
, but the caller maybe passing acontext.Bacground()
#22783 is caused by such kind of refactoring.
In the beginning, we just use the session ID for logging.
Now I review the code and find we're using
sessionID == 0
to check whether it's an internal transaction or a user's transaction.What is changed and how it works?
Introduce a
txn.SetOption(kv.SessionID, id)
to replace the old way of passing session ID bycontext.Context
.What's Changed:
Use
txn.SetOption(kv.SessionID, id)
instead oftxn.Commit(tikvutil.SetSessionID(ctx, s.GetSessionVars().ConnectionID))
to pass the session ID.How it Works:
Related changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Release note