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

id: make id allocator general purpose #5284

Merged
merged 11 commits into from
Jul 20, 2022

Conversation

AmoebaProtozoa
Copy link
Contributor

@AmoebaProtozoa AmoebaProtozoa commented Jul 7, 2022

Signed-off-by: David 8039876+AmoebaProtozoa@users.noreply.github.com

What problem does this PR solve?

The current implementation of id allocator permits only one id allocator due to fixed alloc path $rootPath/alloc_id and metrics label.
This PR attempts to make it more general purpose by parametrize its alloc path and metrics label.
Issue Number: Close #5294

What is changed and how does it work?

make id allocator general purpose

Check List

Tests

  • Unit tests

Release note

None.

Signed-off-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jul 7, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • nolouch
  • rleungx

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jul 7, 2022
@codecov
Copy link

codecov bot commented Jul 7, 2022

Codecov Report

Merging #5284 (9e82cfb) into master (f5d4636) will increase coverage by 0.13%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #5284      +/-   ##
==========================================
+ Coverage   75.70%   75.84%   +0.13%     
==========================================
  Files         311      312       +1     
  Lines       30826    30978     +152     
==========================================
+ Hits        23338    23496     +158     
- Misses       5485     5487       +2     
+ Partials     2003     1995       -8     
Flag Coverage Δ
unittests 75.84% <100.00%> (+0.13%) ⬆️

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

Impacted Files Coverage Δ
server/id/metrics.go 100.00% <ø> (ø)
server/id/id.go 84.61% <100.00%> (+3.66%) ⬆️
server/server.go 75.36% <100.00%> (+1.22%) ⬆️
server/schedulers/shuffle_region_config.go 63.15% <0.00%> (-7.90%) ⬇️
pkg/dashboard/adapter/manager.go 79.31% <0.00%> (-6.90%) ⬇️
server/election/leadership.go 75.25% <0.00%> (-2.07%) ⬇️
server/member/member.go 64.21% <0.00%> (-1.58%) ⬇️
server/region_syncer/client.go 85.82% <0.00%> (-0.75%) ⬇️
server/tso/tso.go 71.75% <0.00%> (-0.57%) ⬇️
server/tso/allocator_manager.go 65.22% <0.00%> (-0.50%) ⬇️
... and 46 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f5d4636...9e82cfb. Read the comment docs.

@rleungx
Copy link
Member

rleungx commented Jul 7, 2022

Can you describe more details of your use case?

@AmoebaProtozoa
Copy link
Contributor Author

Can you describe more details of your use case?

This is mostly for the Keyspace management in PD.
Keyspace needs a new id everytime a keyspace is created, something very similar to what id allocator does. It would be great if we can reuse id allocator's logic.
However, since it need to be stored on a different storage path and impose some extra restrictions, using the same id allocator instance doesn't seems possible.

server/id/id.go Outdated Show resolved Hide resolved
server/server.go Outdated Show resolved Hide resolved
server/id/id.go Outdated Show resolved Hide resolved
Signed-off-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>
Signed-off-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>
server/id/id_test.go Outdated Show resolved Hide resolved
server/id/id_test.go Outdated Show resolved Hide resolved
Signed-off-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>
server/id/id.go Outdated Show resolved Hide resolved
server/id/id.go Outdated Show resolved Hide resolved
Signed-off-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>
@ystaticy
Copy link
Contributor

LGTM

@AmoebaProtozoa AmoebaProtozoa marked this pull request as ready for review July 14, 2022 03:17
@AmoebaProtozoa AmoebaProtozoa changed the title [WIP] id: make id allocator general purpose id: make id allocator general purpose Jul 14, 2022
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 14, 2022
server/id/id_test.go Outdated Show resolved Hide resolved
@ti-chi-bot
Copy link
Member

@ystaticy: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

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 ti-community-infra/tichi repository.

Copy link
Member

@rleungx rleungx left a comment

Choose a reason for hiding this comment

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

The rest LGTM.

server/id/id.go Outdated
Comment on lines 53 to 54
metrics *metrics
member string
Copy link
Member

Choose a reason for hiding this comment

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

please reorder these two fields

@@ -119,13 +135,13 @@ func (alloc *allocatorImpl) rebaseLocked() error {
return errs.ErrEtcdTxnConflict.FastGenByArgs()
}

log.Info("idAllocator allocates a new id", zap.Uint64("alloc-id", end))
idallocGauge.Set(float64(end))
log.Info("idAllocator allocates a new id", zap.String("label", alloc.label), zap.Uint64("alloc-id", end))
Copy link
Member

Choose a reason for hiding this comment

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

The docs of the PD recovery process may need to be updated.

Copy link
Member

Choose a reason for hiding this comment

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

Curiously, is there anything broken so we have to update PD recovery process?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Curiously, is there anything broken so we have to update PD recovery process?

It's this block related to finding the maximum allocated ID
https://github.com/pingcap/docs/blob/master/pd-recover.md#get-allocated-id-from-pd-log

Copy link
Member

Choose a reason for hiding this comment

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

Once we recover PD, do we also need to recover all id allocators?

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 14, 2022
Signed-off-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>
Signed-off-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>
}

// metrics is a collection of idAllocator's metrics
type metrics struct {
Copy link
Member

Choose a reason for hiding this comment

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

Why we need to have this type instead of using prometheus.Guage directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was to improve the readability and make it easier to add more metrics, as suggested #5284 (comment)

server/id/id.go Outdated Show resolved Hide resolved
Signed-off-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>
Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 18, 2022
@nolouch
Copy link
Contributor

nolouch commented Jul 18, 2022

ptal @sunxiaoguang

@nolouch
Copy link
Contributor

nolouch commented Jul 20, 2022

/merge

@ti-chi-bot
Copy link
Member

@nolouch: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

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
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 9e82cfb

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 20, 2022
@ti-chi-bot ti-chi-bot merged commit a7023b0 into tikv:master Jul 20, 2022
shhdgit pushed a commit to shhdgit/pd that referenced this pull request Jul 21, 2022
close tikv#5294

make id allocator general purpose

Signed-off-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
HuSharp pushed a commit to HuSharp/pd that referenced this pull request Jul 21, 2022
close tikv#5294

make id allocator general purpose

Signed-off-by: David <8039876+AmoebaProtozoa@users.noreply.github.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
@AmoebaProtozoa AmoebaProtozoa deleted the id_allocator branch August 7, 2022 06:05
ti-chi-bot added a commit that referenced this pull request Feb 2, 2023
close #5898

The old version of idalloc is a globally unique path, and keyspace needs to use id allocator to allocate keyspaceID, so in this pr the id allocator is changed to a general purpose, but not sync metrics.
#5284

Signed-off-by: husharp <jinhao.hu@pingcap.com>

Co-authored-by: JmPotato <ghzpotato@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
ti-chi-bot added a commit that referenced this pull request Feb 17, 2023
…6016)

close #5898, ref #5899

The old version of idalloc is a globally unique path, and keyspace needs to use id allocator to allocate keyspaceID, so in this pr the id allocator is changed to a general purpose, but not sync metrics.
#5284

Signed-off-by: husharp <jinhao.hu@pingcap.com>

Co-authored-by: husharp <jinhao.hu@pingcap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make id allocator more general purpose
6 participants