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

pkg/autoid_service: add lock to make API thread-safe #50820

Merged
merged 3 commits into from
Jan 31, 2024

Conversation

tiancaiamao
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #50819

Problem Summary:

What changed and how does it work?

The exposed API should be thread-safe, and forceRebase allocAutoID alloc4Unsigned alloc4Signed ... all those internal functions should be called under lock.

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 the release-note-none Denotes a PR that doesn't merit a release note. label Jan 30, 2024
@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 30, 2024
Copy link

tiprow bot commented Jan 30, 2024

Hi @tiancaiamao. 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 Jan 30, 2024

Codecov Report

Merging #50820 (45b5b09) into master (ff050bb) will increase coverage by 2.4664%.
Report is 17 commits behind head on master.
The diff coverage is 100.0000%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #50820        +/-   ##
================================================
+ Coverage   70.5750%   73.0414%   +2.4664%     
================================================
  Files          1463       1466         +3     
  Lines        433255     438466      +5211     
================================================
+ Hits         305770     320262     +14492     
+ Misses       108339      98414      -9925     
- Partials      19146      19790       +644     
Flag Coverage Δ
integration 49.3922% <100.0000%> (?)
unit 70.6178% <100.0000%> (+0.2288%) ⬆️

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

Components Coverage Δ
dumpling 54.2940% <ø> (ø)
parser ∅ <ø> (∅)
br 51.5002% <ø> (+5.7111%) ⬆️

@@ -453,6 +453,8 @@ func (s *Service) allocAutoID(ctx context.Context, req *autoid.AutoIDRequest) (*
})

val := s.getAlloc(req.DbID, req.TblID, req.IsUnsigned)
val.Lock()
Copy link
Member

Choose a reason for hiding this comment

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

What is the expected performance impact since we're using locks in wider scope.

Could you provide some kind of benchmark result, if 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.

For the AllocID API, I think it's almost the same with before, because the old code did use lock here too ... the only difference is req.N == 0 code branch which means a "get current autoid value" query.

For the Rebase API, the performance could be worse than before, but this query is rare comparing to the AllocID API, so the performance is not as sensitive.

From my experience data, simple insert into SQL query on AUTO_ID_CACHE=1 tables workload on my local machine get 140K QPS, and the AllocID API itself performs better than that. @bb7133

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 30, 2024
Copy link

ti-chi-bot bot commented Jan 31, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, hawkingrei

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 Jan 31, 2024
Copy link

ti-chi-bot bot commented Jan 31, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-01-30 09:45:56.317054261 +0000 UTC m=+1472397.881351968: ☑️ agreed by bb7133.
  • 2024-01-31 04:21:58.40377274 +0000 UTC m=+1539359.968070429: ☑️ agreed by hawkingrei.

@ti-chi-bot ti-chi-bot bot merged commit ede0d69 into pingcap:master Jan 31, 2024
22 of 23 checks passed
@tiancaiamao tiancaiamao added the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label Feb 1, 2024
@tiancaiamao tiancaiamao deleted the concurrent-api branch February 1, 2024 07:49
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #50892.

@tiancaiamao tiancaiamao added the needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. label Feb 26, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Feb 26, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #51322.

@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. label Mar 25, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #52059.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Mar 25, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
mittalrishabh pushed a commit to mittalrishabh/tidb that referenced this pull request May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. release-note-none Denotes a PR that doesn't merit a release note. 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.

autoid service rebase internal SQL should not meet transaction conflict
4 participants