-
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
session: fix linearizability for non-autocommit async-commit txn #22879
session: fix linearizability for non-autocommit async-commit txn #22879
Conversation
Signed-off-by: Yilin Chen <[email protected]>
Signed-off-by: Yilin Chen <[email protected]>
/lgtm |
Signed-off-by: Yilin Chen <[email protected]>
The way to fix may depend on #22875 |
executor/simple.go
Outdated
@@ -586,7 +586,8 @@ func (e *SimpleExec) executeBegin(ctx context.Context, s *ast.BeginStmt) error { | |||
// With START TRANSACTION, autocommit remains disabled until you end | |||
// the transaction with COMMIT or ROLLBACK. The autocommit mode then | |||
// reverts to its previous state. | |||
e.ctx.GetSessionVars().SetStatusFlag(mysql.ServerStatusInTrans, true) | |||
e.ctx.GetSessionVars().SetInTxn(true) | |||
txnCtx.IsExplicit = 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 do the assignment again?
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.
Sorry, I forgot to remove it during refactoring
Signed-off-by: Yilin Chen <[email protected]>
Signed-off-by: Yilin Chen <[email protected]>
Signed-off-by: Yilin Chen <[email protected]>
@AilinKid: Please use If you have approved this PR, please ignore this reply. This reply is being used as a temporary reply during the migration of the new bot and will be removed on April 1. 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. |
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.
LGTM
/run-all-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.
/lgtm
sessionctx/variable/session.go
Outdated
Isolation string | ||
LockExpire uint32 | ||
ForUpdate uint32 | ||
// IsExplicit indicates whether the txn is an interactive txn started with a BEGIN statement |
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's not accurate. A transaction can start with autocommit = 0
.
func (s *SessionVars) SetInTxn(val bool) { | ||
s.SetStatusFlag(mysql.ServerStatusInTrans, val) | ||
if val { | ||
s.TxnCtx.IsExplicit = 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.
Is it reset when startinging a new transaction?
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 think it is always reset by PrepareTxnCtx
or NewTxn
. I am not sure if there is anything missing.
However, at least the unit test in this PR passes, which I think covers the important cases.
/LGTM |
[REVIEW NOTIFICATION] This pull request has been approved by:
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 |
Signed-off-by: Yilin Chen <[email protected]>
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.
/lgtm
/merge |
@youjiali1995: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests You only need to trigger If you have any questions about the PR merge process, please refer to pr process. 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. |
This pull request has been accepted and is ready to merge. Commit hash: e7cb5b4
|
/run-tics-test |
@sticnarf: Your PR has out-of-dated, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests 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. |
/run-tics-test |
What problem does this PR solve?
#22746 made a mistake.
s.GetSessionVars().IsAutocommit()
cannot be used to decide whether the current transaction is an auto-commit transaction.Elsewhere we tend to use
s.GetSessionVars().IsAutocommit() && s.GetSessionVars().IsAutocommit().InTxn()
to check, but at the beginning of theCOMMIT
statement, we clear theServerStatusInTrans
flag, soInTxn()
always returns false during theCOMMIT
statement.What is changed and how it works?
This PR adds
IsExplicit
flag totxnCtx
. We set the flag totrue
when we start a transaction explicitly. We use this flag to check if this transaction is auto-commit.Check List
Tests
Release note