-
Notifications
You must be signed in to change notification settings - Fork 720
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
Support tso microservice auto service discovery in the pd client. #6065
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Hi @binshi-bing. Thanks for your PR. I'm waiting for a tikv member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
// tsoKeyspaceGroupPrimaryElectionPrefix defines the key prefix for keyspace group primary election. | ||
// The entire key is in the format of "/pd/<cluster-id>/microservice/tso/keyspace-group-XXXXX/primary" in which | ||
// XXXXX is 5 digits integer with leading zeros. For now we use 0 as the default cluster id. | ||
tsoKeyspaceGroupPrimaryElectionPrefix = "/pd/0/microservice/tso/keyspace-group-" |
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.
I noticed that there is a comment left previously. See #6008 (comment)
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.
Yes, we can certainly move "keyspace-group-" from the path to make it more compact. I'll make the change.
if err := proto.Unmarshal(value, member); err != nil { | ||
return errs.ErrClientProtoUnmarshal.Wrap(err).GenWithStackByCause() | ||
} | ||
return c.switchPrimary(addrsToUrls([]string{member.Name})) |
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.
member.Name?
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.
That's a hack by reusing pdpb.Member and the Name field as service endpoint. My next pr will introduce a new struct as the primary value type as we discussed before.
/ok-to-test |
client/client.go
Outdated
func NewTSOClientWithContext(ctx context.Context, svrAddrs []string, security SecurityOption, opts ...ClientOption) (Client, error) { | ||
log.Info("[pd(tso)] create tso client with endpoints", zap.Strings("tso-address", svrAddrs)) | ||
// TODO: | ||
// relace NewClientWithContext with this API after we enable auto service discovery. |
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.
// relace NewClientWithContext with this API after we enable auto service discovery. | |
// replace NewClientWithContext with this API after we enable auto service discovery. |
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.
changed locally.
f439ff7
to
9c08e78
Compare
Signed-off-by: Bin Shi <binshi.bing@gmail.com>
Signed-off-by: Bin Shi <binshi.bing@gmail.com>
5d2a332
to
bce8409
Compare
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.
mostly LGTM
@@ -290,21 +291,30 @@ func NewClientWithContext(ctx context.Context, svrAddrs []string, security Secur | |||
c, clientCtx, clientCancel, tlsCfg := createClient(ctx, &security) | |||
c.tsoStreamBuilderFactory = &pdTSOStreamBuilderFactory{} | |||
c.bc = newPDBaseClient(clientCtx, clientCancel, &c.wg, addrsToUrls(svrAddrs), tlsCfg, c.option) | |||
c.tsobc = c.bc |
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.
the same two clients?
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.
tsobc is an interface of tso baseclient which can be either tso in pd client or tso microservice client. For the former, tso in pd client is the pd client itself, that's why c.tsobc = c.bc. Actually, I planned one more refactor to make it much clearer -- Client contains pdServiceDiscovery by renaming pdBaseClient after we move all the tso related logic out of pdBaseClient. c.tsobc will be backed by either pdServiceDiscovery or tsoServiceDiscovery. After that, we won't see 'c.tsobc = c.bc' such thing which looks weird at the first sight.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #6065 +/- ##
==========================================
- Coverage 74.03% 73.82% -0.21%
==========================================
Files 383 383
Lines 37816 37874 +58
==========================================
- Hits 27996 27960 -36
- Misses 7359 7433 +74
- Partials 2461 2481 +20
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Signed-off-by: Bin Shi <binshi.bing@gmail.com>
bce8409
to
84494fc
Compare
/merge |
@lhy1024: 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. |
This pull request has been accepted and is ready to merge. Commit hash: 84494fc
|
What problem does this PR solve?
Issue Number: Ref #5836
What is changed and how does it work?
Check List
Tests
~/code/pingcap/my-pd/bin tso-client-svc-discovery ./pd-tso-bench -v -m -duration 10s -pd "127.0.0.1:2379" ✔ 5354 16:29:52
Start benchmark #0, duration: 10s
Create 1 client(s) for benchmark
[2023/02/28 16:29:56.663 -08:00] [INFO] [client.go:306] ["[pd(tso)] create tso client with endpoints"] [pd(api)-address="[127.0.0.1:2379]"]
[2023/02/28 16:29:56.665 -08:00] [INFO] [base_client.go:477] ["[pd] switch leader"] [new-leader=http://127.0.0.1:2379] [old-leader=]
[2023/02/28 16:29:56.665 -08:00] [INFO] [base_client.go:153] ["[pd] init cluster id"] [cluster-id=7203525516143219003]
[2023/02/28 16:29:56.666 -08:00] [INFO] [tso_client.go:353] ["[pd(tso)] switch primary"] [new-primary=http://127.0.0.1:3380] [old-primary=]
[2023/02/28 16:29:56.666 -08:00] [INFO] [tso_request_dispatcher.go:287] ["[pd/tso] tso dispatcher created"] [dc-location=global]
count: 498504, max: 4.2795ms, min: 0.3284ms, avg: 2.0016ms
<1ms: 684, >1ms: 271848, >2ms: 225972, >5ms: 0, >10ms: 0, >30ms: 0, >50ms: 0, >100ms: 0, >200ms: 0, >400ms: 0, >800ms: 0, >1s: 0
count: 494935, max: 3.9645ms, min: 0.3201ms, avg: 2.0182ms
<1ms: 562, >1ms: 257241, >2ms: 237132, >5ms: 0, >10ms: 0, >30ms: 0, >50ms: 0, >100ms: 0, >200ms: 0, >400ms: 0, >800ms: 0, >1s: 0
Release note