Skip to content

txn: also update the @@tidb_last_txn_info for readyonly or rollback txns #61057

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

Merged
merged 3 commits into from
May 13, 2025

Conversation

lcwangchao
Copy link
Collaborator

What problem does this PR solve?

Issue Number: close #61056

What changed and how does it work?

also update the @@tidb_last_txn_info for readyonly or rollback transactions

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.

@@tidb_last_txn_info will also be updated when readonly transaction ends or transaction rollback

@ti-chi-bot ti-chi-bot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label May 9, 2025
@lcwangchao lcwangchao added the compatibility-breaker Violation of forwards/backwards compatibility in a design-time piece. label May 9, 2025
@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 9, 2025
@lcwangchao
Copy link
Collaborator Author

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 9, 2025
Copy link

codecov bot commented May 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.5264%. Comparing base (f4d2318) to head (d467fda).
Report is 19 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #61057        +/-   ##
================================================
+ Coverage   73.1387%   73.5264%   +0.3876%     
================================================
  Files          1724       1724                
  Lines        477000     480744      +3744     
================================================
+ Hits         348872     353474      +4602     
+ Misses       106705     105846       -859     
- Partials      21423      21424         +1     
Flag Coverage Δ
integration 42.8106% <100.0000%> (?)
unit 72.4814% <100.0000%> (+0.1140%) ⬆️

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

Components Coverage Δ
dumpling 52.7804% <ø> (ø)
parser ∅ <ø> (∅)
br 46.7415% <ø> (-0.8126%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -919,6 +919,7 @@ func (s *session) CommitTxn(ctx context.Context) error {
r, ctx := tracing.StartRegionEx(ctx, "session.CommitTxn")
defer r.End()

s.setLastTxnInfoBeforeTxnEnd()
Copy link
Member

Choose a reason for hiding this comment

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

How about putting it in onTxnEnd?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems onTxnEnd,the txn info has been cleared

Copy link
Contributor

Choose a reason for hiding this comment

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

After this line, in doCommitWithRetry -> doCommit, it seems it still have possibility to finally enter a rolled-back state or encounter error. Perhaps it's better to consider put it in a later place where the commit/rollback result is finally determined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems if a txn comitted or fails to commit, the CommitHook will update it:

txn.SetOption(kv.CommitHook, func(info string, _ error) { sessVars.LastTxnInfo = info })

setLastTxnInfoBeforeTxnEnd in CommitTxn will be overridden at this time. So setLastTxnInfoBeforeTxnEnd is only affects some readonly txns.

Copy link
Contributor

Choose a reason for hiding this comment

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

Better to add comments to explain why it is put here.

@lcwangchao
Copy link
Collaborator Author

/retest

@@ -919,6 +919,7 @@ func (s *session) CommitTxn(ctx context.Context) error {
r, ctx := tracing.StartRegionEx(ctx, "session.CommitTxn")
defer r.End()

s.setLastTxnInfoBeforeTxnEnd()
Copy link
Contributor

Choose a reason for hiding this comment

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

After this line, in doCommitWithRetry -> doCommit, it seems it still have possibility to finally enter a rolled-back state or encounter error. Perhaps it's better to consider put it in a later place where the commit/rollback result is finally determined.

@lcwangchao
Copy link
Collaborator Author

/retest

@cfzjywxk cfzjywxk requested a review from zyguan May 13, 2025 09:26
@lcwangchao lcwangchao removed the compatibility-breaker Violation of forwards/backwards compatibility in a design-time piece. label May 13, 2025
@lcwangchao
Copy link
Collaborator Author

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 13, 2025
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

@@ -919,6 +919,7 @@ func (s *session) CommitTxn(ctx context.Context) error {
r, ctx := tracing.StartRegionEx(ctx, "session.CommitTxn")
defer r.End()

s.setLastTxnInfoBeforeTxnEnd()
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to add comments to explain why it is put here.

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 13, 2025
Copy link

ti-chi-bot bot commented May 13, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, zyguan

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

The pull request process is described 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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 13, 2025
Copy link

ti-chi-bot bot commented May 13, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-05-13 11:21:40.306737111 +0000 UTC m=+444166.454698358: ☑️ agreed by cfzjywxk.
  • 2025-05-13 13:21:59.834890015 +0000 UTC m=+451385.982851234: ☑️ agreed by zyguan.

@ti-chi-bot ti-chi-bot bot merged commit 41045f1 into pingcap:master May 13, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

also update @@tidb_last_txn_info for readonly and rollback txn
5 participants