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

txn: fix the lock behaviours when for update is used outside transactions | tidb-test=pr/2365 #54694

Closed
wants to merge 5 commits into from

Conversation

cfzjywxk
Copy link
Contributor

@cfzjywxk cfzjywxk commented Jul 17, 2024

What problem does this PR solve?

Issue Number: close #54684 #54705

Problem Summary:

What changed and how does it work?

1. When `tidb_low_resolution_tso` is enabled, the in-transction `select for update` should be rejected.
2. When `for update` is used outside transactions, the lock operator should be skipped as there is 
no pessimsitic lock phase.

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.

Fix the execution behaviours when tidb_low_resolution_tso is enabled and for update is used outside transactions

@cfzjywxk cfzjywxk added type/bugfix This PR fixes a bug. sig/planner SIG: Planner sig/transaction SIG:Transaction labels Jul 17, 2024
@ti-chi-bot ti-chi-bot bot added 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. labels Jul 17, 2024
Copy link

tiprow bot commented Jul 17, 2024

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

Copy link

codecov bot commented Jul 17, 2024

Codecov Report

Attention: Patch coverage is 82.35294% with 3 lines in your changes missing coverage. Please review.

Project coverage is 56.0474%. Comparing base (26378cb) to head (3c174c8).

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54694         +/-   ##
=================================================
- Coverage   72.6796%   56.0474%   -16.6323%     
=================================================
  Files          1551       1667        +116     
  Lines        437176     604993     +167817     
=================================================
+ Hits         317738     339083      +21345     
- Misses        99819     242723     +142904     
- Partials      19619      23187       +3568     
Flag Coverage Δ
integration 36.5774% <52.9411%> (?)

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

Components Coverage Δ
dumpling 52.9656% <ø> (ø)
parser ∅ <ø> (∅)
br 52.5434% <ø> (+6.7030%) ⬆️

…tions

Signed-off-by: cfzjywxk <cfzjywxk@gmail.com>
Signed-off-by: cfzjywxk <cfzjywxk@gmail.com>
Signed-off-by: cfzjywxk <cfzjywxk@gmail.com>
@cfzjywxk cfzjywxk changed the title txn: fix the lock behaviours when for update is used outside transactions txn: fix the lock behaviours when for update is used outside transactions | tidb-test=pr/2365 Jul 18, 2024
@cfzjywxk
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Jul 18, 2024

@cfzjywxk: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

@pingcap pingcap deleted a comment from tiprow bot Jul 18, 2024
pkg/sessionctx/variable/session.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 18, 2024
cfzjywxk and others added 2 commits July 18, 2024 12:42
Co-authored-by: ekexium <eke@fastmail.com>
Signed-off-by: cfzjywxk <cfzjywxk@gmail.com>
Copy link

ti-chi-bot bot commented Jul 18, 2024

@cfzjywxk: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/unit-test 3c174c8 link true /test unit-test

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

Copy link

ti-chi-bot bot commented Jul 18, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ekexium, zyguan
Once this PR has been reviewed and has the lgtm label, please assign elsa0520, yudongusa for approval, ensuring that each of them provides their approval before proceeding. 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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 18, 2024
Copy link

ti-chi-bot bot commented Jul 18, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-18 04:37:47.416629532 +0000 UTC m=+501489.407571002: ☑️ agreed by ekexium.
  • 2024-07-18 06:04:46.792658326 +0000 UTC m=+506708.783599797: ☑️ agreed by zyguan.

@@ -1091,6 +1091,7 @@ type SessionVars struct {
TxnMode string

// LowResolutionTSO is used for reading data with low resolution TSO which is updated once every two seconds.
// Do not use it directly, use the `UseLowResolutionTSO` method below.
Copy link
Member

Choose a reason for hiding this comment

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

can we unexport it?

Comment on lines +585 to +587
if sctx.GetSessionVars().UseLowResolutionTSO() {
return nil, errors.New("can not execute select for update statement when 'tidb_low_resolution_tso' is set")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. When tidb_low_resolution_tso is enabled, the in-transction select for update should be rejected.

Is here sure to be in transaction?

if err != nil {
return nil, err
lock, _ := getLockWaitTime(b.ctx, l)
if lock {
Copy link
Contributor

Choose a reason for hiding this comment

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

If !lock, is the above for loop still necessary?

@cfzjywxk
Copy link
Contributor Author

It's complex to handle the plan with lock operator or executor in the same PR, would split them into differnt PRs.

@cfzjywxk cfzjywxk closed this Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner sig/transaction SIG:Transaction size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

txn: the tidb_low_resolution variable is used on select for update statement
5 participants