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

session: fix linearizability for non-autocommit async-commit txn #22879

Merged
merged 11 commits into from
Feb 24, 2021

Conversation

sticnarf
Copy link
Contributor

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 the COMMIT statement, we clear the ServerStatusInTrans flag, so InTxn() always returns false during the COMMIT statement.

What is changed and how it works?

This PR adds IsExplicit flag to txnCtx. We set the flag to true when we start a transaction explicitly. We use this flag to check if this transaction is auto-commit.

Check List

Tests

  • Unit test

Release note

  • No release note.

@sticnarf sticnarf added the sig/transaction SIG:Transaction label Feb 23, 2021
@sticnarf sticnarf requested a review from a team as a code owner February 23, 2021 03:52
@sticnarf sticnarf requested review from qw4990 and removed request for a team February 23, 2021 03:52
@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 23, 2021
@github-actions github-actions bot added sig/execution SIG execution sig/sql-infra SIG: SQL Infra labels Feb 23, 2021
@ekexium
Copy link
Contributor

ekexium commented Feb 23, 2021

/lgtm

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 23, 2021
Signed-off-by: Yilin Chen <[email protected]>
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 23, 2021
@sticnarf
Copy link
Contributor Author

The way to fix may depend on #22875

@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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

@ti-chi-bot
Copy link
Member

@AilinKid: Please use /LGTM instead of LGTM when you want to approve the pull request by comment.
If you use the GitHub review feature, please approve the PR directly, the comment will not take effect in the GitHub review feature.
If you have any qustions please refer to lgtm command help or lgtm plugin design.

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.

Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sticnarf
Copy link
Contributor Author

/run-all-tests

Copy link
Contributor

@youjiali1995 youjiali1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Isolation string
LockExpire uint32
ForUpdate uint32
// IsExplicit indicates whether the txn is an interactive txn started with a BEGIN statement
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@youjiali1995
Copy link
Contributor

/LGTM

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • ekexium
  • youjiali1995

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot removed the status/LGT1 Indicates that a PR has LGTM 1. label Feb 23, 2021
@ti-chi-bot ti-chi-bot added the status/LGT2 Indicates that a PR has LGTM 2. label Feb 23, 2021
Signed-off-by: Yilin Chen <[email protected]>
Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@youjiali1995
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

@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 /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: e7cb5b4

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 24, 2021
@sticnarf
Copy link
Contributor Author

/run-tics-test

@ti-chi-bot
Copy link
Member

@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.

@sticnarf
Copy link
Contributor Author

/run-tics-test

@ti-chi-bot ti-chi-bot merged commit b226130 into pingcap:master Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution sig/sql-infra SIG: SQL Infra sig/transaction SIG:Transaction size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants