Skip to content

Conversation

morgo
Copy link
Contributor

@morgo morgo commented May 31, 2021

What problem does this PR solve?

Problem Summary:

Previously the sysvar tidb_txn_mode permitted three values:

  • optimistic
  • pessimistic
  • empty string (behaves the same as optimistic)

This improves the normalization of system variables to be in upper case (consistent with most other ENUM variables), and the validation function converts "" to OPTIMISTIC.

Because the state is cleaned up internally, the helper function GetReadableTxnMode() is no longer required.

Additionally, the default is changed to PESSIMISTIC so that it can support the use case of SET tidb_txn_mode = DEFAULT (users effectively think pessmistic is the default, but from a code point of view it's not). To support this, the bootstrap logic of changing the value of tidb_txn_mode to PESSIMISTIC if the store is tikv is inverted to be if the store != tikv.

Note: This means there is a slight behavior change: Upgrading from 2.1 directly to master will change the txn-mode from optimistic to pessimistic. But if you step through any version in between it will stay as optimistic. I think this is easy enough to describe in the docs, but long term it might be better to say that direct upgrades that skip more than 1 major digit are not supported. That way we can avoid the excessive language in docs describing edge-cases (which hurt readability).

What is changed and how it works?

What's Changed:

Code cleanup, mostly function neutral to users. Improves usability because the behavior of "" is confusing to me, and likely to other users.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test

Side effects

  • None (the code supports the upgrade case)

Release note

  • The handling of the tidb_txn_mode system variable has been improved. It is recommended to set the value to OPTIMISTIC or PESSIMISTIC, and no longer the special empty string ('') value.

@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 31, 2021
@morgo morgo added sig/transaction SIG:Transaction sig/sql-infra SIG: SQL Infra labels May 31, 2021
Copy link
Contributor

@xhebox xhebox left a comment

Choose a reason for hiding this comment

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

Rest LGTM

if v.Name == variable.TiDBTxnMode && config.GetGlobalConfig().Store == "tikv" {
vVal = "pessimistic"
if v.Name == variable.TiDBTxnMode && config.GetGlobalConfig().Store != "tikv" {
vVal = "OPTIMISTIC"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use DefTiDBTxnMode directly, is it possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DefTiDBTxnMode is now pessimistic, but here we are saying if the store is not tikv use OPTIMISTIC. I can use ast.Optimistic if that helps?

Copy link
Contributor

@xhebox xhebox Jun 1, 2021

Choose a reason for hiding this comment

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

Oops, I did not notice that... No, just keep it unchanged. Do we need to change the document or inform the transaction guys?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the user documents should change. But I am hoping we can merge the automated docs generation and incorporate it here: pingcap/docs#5720

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • xhebox

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 submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 2, 2021
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 10, 2021
@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jun 10, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 14, 2021
Copy link
Contributor

@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

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

I'm afraid it's a big decision to change the default txn mode. @cfzjywxk

@morgo
Copy link
Contributor Author

morgo commented Jun 17, 2021

I'm afraid it's a big decision to change the default txn mode. @cfzjywxk

To clarify: it's not a default change unless the user upgrades directly from 3.0 2.1 to 5.2. This is because on bootstrap clusters are set to be pessimistic mode already.

This PR is trying to reduce the confusion which is caused by having 3 states; at the cost of an unlikely (and should not be supported) upgrade path.

1 similar comment
@morgo
Copy link
Contributor Author

morgo commented Jun 17, 2021

I'm afraid it's a big decision to change the default txn mode. @cfzjywxk

To clarify: it's not a default change unless the user upgrades directly from 3.0 2.1 to 5.2. This is because on bootstrap clusters are set to be pessimistic mode already.

This PR is trying to reduce the confusion which is caused by having 3 states; at the cost of an unlikely (and should not be supported) upgrade path.

@cfzjywxk
Copy link
Contributor

I'm afraid it's a big decision to change the default txn mode. @cfzjywxk

To clarify: it's not a default change unless the user upgrades directly from 3.0 to 5.2. This is because on bootstrap clusters are set to be pessimistic mode already.

This PR is trying to reduce the confusion which is caused by having 3 states; at the cost of an unlikely (and should not be supported) upgrade path.

@morgo
There are some key customers who will do the cross version upgrade, we may need to discuss this behaviour change together with the bussines team and support team.

@morgo
Copy link
Contributor Author

morgo commented Jun 18, 2021

@morgo
There are some key customers who will do the cross version upgrade, we may need to discuss this behaviour change together with the bussines team and support team.

OK let me know :-)

@ti-chi-bot
Copy link
Member

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

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 31, 2021
@morgo morgo closed this Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. sig/sql-infra SIG: SQL Infra sig/transaction SIG:Transaction size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants