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: set txn options in txn provider which avoid data race #52304

Merged
merged 11 commits into from
Apr 8, 2024

Conversation

you06
Copy link
Contributor

@you06 you06 commented Apr 2, 2024

What problem does this PR solve?

Issue Number: ref #50215

Problem Summary:

Move most SetOption usages into txn provider, manage them together, this can help us avoid data race in clear way.

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.

The test in sessiontxn package is passed with this PR's modification.

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 release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 2, 2024
Copy link

tiprow bot commented Apr 2, 2024

Hi @you06. 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/test-infra repository.

Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Merging #52304 (7df782c) into master (7a20e43) will increase coverage by 1.9470%.
Report is 30 commits behind head on master.
The diff coverage is 79.4594%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #52304        +/-   ##
================================================
+ Coverage   72.1416%   74.0886%   +1.9470%     
================================================
  Files          1467       1467                
  Lines        426665     429290      +2625     
================================================
+ Hits         307803     318055     +10252     
+ Misses        99697      91320      -8377     
- Partials      19165      19915       +750     
Flag Coverage Δ
integration 28.4150% <71.8918%> (?)

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

Components Coverage Δ
dumpling 53.9957% <ø> (ø)
parser ∅ <ø> (∅)
br 49.5528% <ø> (+8.9886%) ⬆️

@hawkingrei
Copy link
Member

/ok-to-test

@ti-chi-bot ti-chi-bot bot added ok-to-test Indicates a PR is ready to be tested. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 2, 2024
@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 2, 2024
Signed-off-by: you06 <[email protected]>
pkg/sessiontxn/isolation/base.go Outdated Show resolved Hide resolved
pkg/sessiontxn/isolation/base.go Show resolved Hide resolved
pkg/sessiontxn/isolation/base.go Show resolved Hide resolved
}

if interceptor := temptable.SessionSnapshotInterceptor(p.sctx, p.infoSchema); interceptor != nil {
txn.SetOption(kv.SnapInterceptor, interceptor)
Copy link
Contributor

Choose a reason for hiding this comment

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

The txnSetOption should be deprecated to avoid mis-usages in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

txn.SetOption is widely used in some internal packages, I don't have confidence to deprecate it since it takes too many capabilities.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or is it possible to also check the newly added isCommitterworking inside the tikvTxn.SetOption?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Why just check in test? I think checking the txn status when SetOption is the key to avoid future mistakes.

@you06
Copy link
Contributor Author

you06 commented Apr 3, 2024

/retest


sessiontxn.GetTxnManager(s)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of this call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, that's a mistake

}
return nil
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we forget to set kv.CommitTSUpperBoundCheck when commitTSChecker is not nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

Signed-off-by: you06 <[email protected]>
}

if interceptor := temptable.SessionSnapshotInterceptor(p.sctx, p.infoSchema); interceptor != nil {
txn.SetOption(kv.SnapInterceptor, interceptor)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why just check in test? I think checking the txn status when SetOption is the key to avoid future mistakes.

@@ -200,6 +214,9 @@ func (txn *tikvTxn) GetMemBuffer() kv.MemBuffer {
}

func (txn *tikvTxn) SetOption(opt int, val any) {
if intest.InTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why just check in tests?

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 suppose the current implementation is ok, if this check only works in tests, we can just panic rather than returning and checking error. Another reason, compile with intest.InTest won't impact the performance of release builds.

@@ -78,6 +81,10 @@ func (txn *tikvTxn) CacheTableInfo(id int64, info *model.TableInfo) {
}

func (txn *tikvTxn) LockKeys(ctx context.Context, lockCtx *kv.LockCtx, keysInput ...kv.Key) error {
if intest.InTest {
txn.isCommitterWorking.Store(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 set isCommitterWorking when InTest? The InTest is a little confusing.

@cfzjywxk cfzjywxk requested a review from zyguan April 4, 2024 01:55
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Apr 4, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Apr 4, 2024
Copy link

ti-chi-bot bot commented Apr 4, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-04-04 01:55:46.962630041 +0000 UTC m=+495408.490170585: ☑️ agreed by cfzjywxk.
  • 2024-04-04 09:07:08.923274114 +0000 UTC m=+521290.450814660: ☑️ agreed by zyguan.

@cfzjywxk
Copy link
Contributor

cfzjywxk commented Apr 6, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cfzjywxk, zyguan Once this PR has been reviewed and has the lgtm label, please assign tangenta, 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

@you06 Need approvements from the owners.

@cfzjywxk
Copy link
Contributor

cfzjywxk commented Apr 7, 2024

@easonn7 PTAL

@cfzjywxk
Copy link
Contributor

cfzjywxk commented Apr 7, 2024

@wjhuang2016 @tangenta
PTAL

@easonn7
Copy link

easonn7 commented Apr 7, 2024

/approve

Copy link

ti-chi-bot bot commented Apr 8, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, easonn7, zimulala, 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 the approved label Apr 8, 2024
@you06
Copy link
Contributor Author

you06 commented Apr 8, 2024

/merge

Copy link

ti-chi-bot bot commented Apr 8, 2024

@you06: We have migrated to builtin LGTM and approve plugins for reviewing.

Please use /approve when you want approve this pull request.

The changes announcement: LGTM plugin changes

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 ti-chi-bot bot merged commit c39d79f into pingcap:master Apr 8, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants