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

client/sd: unify the service discovery callbacks within a struct #9014

Merged
merged 3 commits into from
Jan 22, 2025

Conversation

JmPotato
Copy link
Member

What problem does this PR solve?

Issue Number: ref #8690.

What is changed and how does it work?

Unify the service discovery callbacks within a struct.

Check List

Tests

  • Unit test
  • Integration test

Release note

None.

@JmPotato JmPotato added the component/client Client logic. label Jan 20, 2025
@JmPotato JmPotato requested review from okJiang and rleungx January 20, 2025 09:25
@ti-chi-bot ti-chi-bot bot added 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 20, 2025
@JmPotato JmPotato force-pushed the sd_callback branch 3 times, most recently from be379e4 to 594be8e Compare January 21, 2025 02:12
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 79.48718% with 16 lines in your changes missing coverage. Please review.

Project coverage is 76.32%. Comparing base (b66703c) to head (62b7b61).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9014      +/-   ##
==========================================
+ Coverage   76.22%   76.32%   +0.09%     
==========================================
  Files         465      466       +1     
  Lines       70682    70727      +45     
==========================================
+ Hits        53879    53984     +105     
+ Misses      13445    13388      -57     
+ Partials     3358     3355       -3     
Flag Coverage Δ
unittests 76.32% <79.48%> (+0.09%) ⬆️

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

@JmPotato JmPotato requested a review from rleungx January 21, 2025 04:09
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 21, 2025
@JmPotato
Copy link
Member Author

/test pull-integration-realcluster-test

@okJiang
Copy link
Member

okJiang commented Jan 21, 2025

@JmPotato: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-integration-realcluster-test 65ed86d link true /test pull-integration-realcluster-test
Full PR test history. Your PR dashboard.

if ms {
runCommand("sh", "-c",
tiupBin+` playground nightly --pd.mode ms --kv 3 --tiflash 1 --db 1 --pd 3 --tso 1 --scheduling 1 \
--without-monitor --tag `+tag+` \
--pd.binpath ./bin/pd-server \
--kv.binpath ./third_bin/tikv-server \
--db.binpath ./third_bin/tidb-server \
--tiflash.binpath ./third_bin/tiflash \
--tso.binpath ./bin/pd-server \
--scheduling.binpath ./bin/pd-server \
--pd.config ./tests/integrations/realcluster/pd.toml \
> `+filepath.Join(playgroundLogDir, tag+".log")+` 2>&1 & `)

In the test report, it download the binaries when deploy ms cluster, which is unexpected because binaries exist🤔, maybe it is a tiup bug.

client/servicediscovery/callbacks.go Outdated Show resolved Hide resolved

// serviceCallbacks contains all the callback functions for service discovery events
type serviceCallbacks struct {
sync.RWMutex
Copy link
Member

Choose a reason for hiding this comment

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

Is this lock necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

This lock will be used in the next PR.

@@ -126,14 +126,16 @@ type ServiceDiscovery interface {
// CheckMemberChanged immediately check if there is any membership change among the leader/followers
// in a quorum-based cluster or among the primary/secondaries in a primary/secondary configured cluster.
CheckMemberChanged() error
// ExecuteAndAddServingURLSwitchedCallback executes the callback once and adds it to the callback list then.
ExecuteAndAddServingURLSwitchedCallback(cb leaderSwitchedCallbackFunc)
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 a ExecuteAndAddServingURLSwitchedCallback interface?

If we need execute some functions, I think we can execute them directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

serviceDiscovery is exposed as an interface, the caller cannot access those internal callbacks.

Copy link
Member

Choose a reason for hiding this comment

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

Because I find it is called in only one place. So maybe Execute is an unnecessary abstraction.

Copy link
Member Author

Choose a reason for hiding this comment

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

It will be used in the next PR also, this method is useful if we want to integrate a sub-client into the client, an immediate execution of the callback with the lastest leader URL is necessary, e.g., https://github.com/tikv/pd/pull/8939/files#diff-c2cd9790c2f82b378808c8f7326f85b46ab36aa388c95250865571df80a4679bR193.

@@ -0,0 +1,104 @@
// Copyright 2025 TiKV Project Authors.
Copy link
Member

Choose a reason for hiding this comment

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

How about moving this file to pkg?

Copy link
Member Author

Choose a reason for hiding this comment

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

Its code is highly related with the service discovery, pkg is for those components which are more common.

@ti-chi-bot ti-chi-bot bot added the lgtm label Jan 22, 2025
Copy link
Contributor

ti-chi-bot bot commented Jan 22, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: okJiang, rleungx

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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jan 22, 2025
Copy link
Contributor

ti-chi-bot bot commented Jan 22, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-01-21 04:14:08.972986987 +0000 UTC m=+154176.303906392: ☑️ agreed by rleungx.
  • 2025-01-22 03:37:26.348155199 +0000 UTC m=+238373.679074588: ☑️ agreed by okJiang.

@ti-chi-bot ti-chi-bot bot merged commit ae6df14 into tikv:master Jan 22, 2025
25 checks passed
@JmPotato JmPotato deleted the sd_callback branch January 22, 2025 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved component/client Client logic. 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/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.

3 participants