-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Conversation
Hi @tiancaiamao. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with 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. |
Codecov Report
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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@@ -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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
[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 |
[LGTM Timeline notifier]Timeline:
|
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
In response to a cherrypick label: new pull request created to branch |
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
…ingcap#52059) (pingcap#95) close pingcap#50819 Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
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
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.