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

variable: session variable tidb_enable_commit_ts_order_check #57313

Closed
wants to merge 1 commit into from

Conversation

b6g
Copy link
Contributor

@b6g b6g commented Nov 12, 2024

What problem does this PR solve?

Issue Number: ref #57165

Problem Summary:

Add a session variable tidb_enable_commit_ts_order_check to enable checking commit_ts in #57305.

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Nov 12, 2024
Copy link

ti-chi-bot bot commented Nov 12, 2024

Hi @b6g. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

Copy link

tiprow bot commented Nov 12, 2024

Hi @b6g. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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-sigs/prow repository.

@dveeden
Copy link
Contributor

dveeden commented Nov 18, 2024

/ok-to-test

@ti-chi-bot ti-chi-bot bot added ok-to-test Indicates a PR is ready to be tested. and removed needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Nov 18, 2024
Copy link

ti-chi-bot bot commented Nov 18, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dveeden
Once this PR has been reviewed and has the lgtm label, please assign benmeadowcroft for approval. For more information see the Code Review Process.

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

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 18, 2024
Copy link

ti-chi-bot bot commented Nov 18, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-18 06:41:49.933464172 +0000 UTC m=+856872.124333162: ☑️ agreed by dveeden.

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.4246%. Comparing base (058d947) to head (02c28aa).
Report is 62 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #57313        +/-   ##
================================================
+ Coverage   72.8577%   73.4246%   +0.5668%     
================================================
  Files          1672       1672                
  Lines        462711     462756        +45     
================================================
+ Hits         337121     339777      +2656     
+ Misses       104809     102274      -2535     
+ Partials      20781      20705        -76     
Flag Coverage Δ
integration 43.3628% <100.0000%> (?)
unit 72.2396% <100.0000%> (-0.0055%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 45.0969% <ø> (+0.0153%) ⬆️
---- 🚨 Try these New Features:

@@ -1915,6 +1915,10 @@ var defaultSysVars = []*SysVar{
s.allowTiFlashCop = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBEnableCommitTSOrderCheck, Value: Off, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.EnableCommitTSOrderCheck = TiDBOptOn(val)
Copy link
Contributor

Choose a reason for hiding this comment

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

The already exists tidb_last_txn_info could be used to track the last transaction information in current session.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It stores the json encoded TxnInfo. We have to json decode to use the last commit_ts, which seems hacky.

#57305 implements the check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this make sense?

Copy link
Contributor

@cfzjywxk cfzjywxk Nov 21, 2024

Choose a reason for hiding this comment

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

Since this check condition should always hold, it can always be verified without introducing a dedicated parameter. Introducing system variables or configuration items typically increases the using complexity for users.

From an implementation perspective, introducing a separate interface to expose the commit_ts of the previous transaction is also costly. The last_txn_info cannot be directly used as it requires deserialization.

Another possible way is to modify the txn commit hook function interface, allowing the KV client to set the commit_ts into a specific field within the session variable's statement context during the commit process like sessVars.stmtContext.commitTS = commitTS.

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 will try txn commit hook function. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cfzjywxk Is this what you suggested 571c73e#diff-3749ef84f018df1c4d5541271a230702b5c8200c8f44268ffdff63886842f268R521?

I feel commitTS should be stored in the SessionVars.LastCommitTS instead of StmtCtx, because StmtCtx is for the current txn, while LastCommitTS is from the last txn.

I can refactor CommitHook to take *TxnInfo in a separate PR, which involves client-go.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that using the commit hook approach would still require modifying the client-go interface if we want to avoid deserializing txn info.

Perhaps the original approach in [PR #1489 of client-go] is better, by adding a commit_ts interface to the transaction in client-go for TiDB to use. It would avoid the performance impact caused by deserializing txn info.

If there are future scenarios requiring access to the last transaction info, we could consider extending the newly exported commit_ts interface into a last_txn_info interface. This would allow it to return structured info instead of a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sgtm

As you pointed out, this session variable is not necessary, as we should always check commit_s. I will close this PR.

@b6g b6g closed this Nov 25, 2024
@b6g b6g deleted the b6g/tsvar1 branch November 25, 2024 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-1-more-lgtm Indicates a PR needs 1 more LGTM. ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants