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

mcs: support batch allocating ids #9092

Merged
merged 6 commits into from
Feb 24, 2025
Merged

Conversation

rleungx
Copy link
Member

@rleungx rleungx commented Feb 21, 2025

What problem does this PR solve?

Issue Number: Close #9085.

What is changed and how does it work?

kvproto PR: pingcap/kvproto#1296

Check List

Tests

  • Unit test

Release note

None.

Copy link
Contributor

ti-chi-bot bot commented Feb 21, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed do-not-merge/needs-linked-issue labels Feb 21, 2025
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 8 lines in your changes missing coverage. Please review.

Project coverage is 76.35%. Comparing base (8428133) to head (9b54e05).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9092      +/-   ##
==========================================
+ Coverage   76.22%   76.35%   +0.13%     
==========================================
  Files         468      468              
  Lines       71696    71708      +12     
==========================================
+ Hits        54648    54751     +103     
+ Misses      13629    13532      -97     
- Partials     3419     3425       +6     
Flag Coverage Δ
unittests 76.35% <85.71%> (+0.13%) ⬆️

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

@rleungx rleungx marked this pull request as ready for review February 21, 2025 07:23
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 21, 2025
@rleungx rleungx changed the title mcs: support batch allcating ids mcs: support batch allocating ids Feb 21, 2025
@rleungx rleungx requested review from JmPotato and lhy1024 February 21, 2025 07:25
@rleungx
Copy link
Member Author

rleungx commented Feb 21, 2025

/cc @ystaticy

Copy link
Contributor

ti-chi-bot bot commented Feb 21, 2025

@rleungx: GitHub didn't allow me to request PR reviews from the following users: ystaticy.

Note that only tikv members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @ystaticy

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.

Signed-off-by: Ryan Leung <[email protected]>
@rleungx
Copy link
Member Author

rleungx commented Feb 21, 2025

/retest

1 similar comment
@rleungx
Copy link
Member Author

rleungx commented Feb 21, 2025

/retest

Copy link
Contributor

ti-chi-bot bot commented Feb 21, 2025

@ystaticy: adding LGTM is restricted to approvers and reviewers in OWNERS files.

In response to this:

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.

@rleungx
Copy link
Member Author

rleungx commented Feb 21, 2025

/hold
Need to merge kvproto PR first.

@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 Feb 21, 2025
return 0, err
for range count {
if alloc.base == alloc.end {
if err := alloc.rebaseLocked(true); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

It may generate many etcd requests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Only when alloc.base == alloc.end, it will rebase.

Copy link
Member

Choose a reason for hiding this comment

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

What about just calculating if the rebase is necessary rather than passively waiting for the loop to do it?


return alloc.base, nil
return alloc.base, count, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

the result of count can be skipped

Copy link
Member Author

@rleungx rleungx Feb 21, 2025

Choose a reason for hiding this comment

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

The Alloc needs the count as the return value due to the interface limitation in the current implementation. We do have another way that does not add count in the response but I prefer to leave it.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 21, 2025
@@ -839,15 +839,15 @@ func newRegionInfoIDRandom(idAllocator id.Allocator) *RegionInfo {
// Randomly select a peer as the leader.
leaderIdx := mrand.Intn(peerNum)
for i := range peerNum {
id, _ := idAllocator.Alloc()
id, _, _ := idAllocator.Alloc(1)
Copy link
Member

Choose a reason for hiding this comment

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

A lot of places are using idAllocator.Alloc(1), what about providing a function named AllocOne()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Then we need to add one more interface.

return 0, err
for range count {
if alloc.base == alloc.end {
if err := alloc.rebaseLocked(true); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

What about just calculating if the rebase is necessary rather than passively waiting for the loop to do it?

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 21, 2025
Copy link
Contributor

ti-chi-bot bot commented Feb 21, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bufferflies, JmPotato, ystaticy

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:
  • OWNERS [JmPotato,bufferflies]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

ti-chi-bot bot commented Feb 21, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-02-21 08:36:26.834349011 +0000 UTC m=+1209629.230571066: ☑️ agreed by bufferflies.
  • 2025-02-21 09:57:07.519325989 +0000 UTC m=+4175.472484249: ☑️ agreed by JmPotato.

Signed-off-by: Ryan Leung <[email protected]>
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 24, 2025
@rleungx
Copy link
Member Author

rleungx commented Feb 24, 2025

/retest

1 similar comment
@rleungx
Copy link
Member Author

rleungx commented Feb 24, 2025

/retest

@rleungx
Copy link
Member Author

rleungx commented Feb 24, 2025

/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 Feb 24, 2025
@rleungx
Copy link
Member Author

rleungx commented Feb 24, 2025

/retest

2 similar comments
@rleungx
Copy link
Member Author

rleungx commented Feb 24, 2025

/retest

@rleungx
Copy link
Member Author

rleungx commented Feb 24, 2025

/retest

@rleungx
Copy link
Member Author

rleungx commented Feb 24, 2025

/retest

@ti-chi-bot ti-chi-bot bot merged commit a5c1101 into tikv:master Feb 24, 2025
25 checks passed
@rleungx rleungx deleted the batch-alloc-id branch February 24, 2025 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm 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.

Batch alloc ID for scheduling service
4 participants