Skip to content

Commit

Permalink
Use more simple namings
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Jan 22, 2025
1 parent f0753d0 commit 62b7b61
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions client/clients/tso/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func NewClient(
},
}

c.svcDiscovery.ExecuteAndAddServingURLSwitchedCallback(c.updateTSOLeaderURL)
c.svcDiscovery.AddServiceURLsSwitchedCallback(c.scheduleUpdateTSOConnectionCtxs)
c.svcDiscovery.ExecAndAddLeaderSwitchedCallback(c.updateTSOLeaderURL)
c.svcDiscovery.AddMembersChangedCallback(c.scheduleUpdateTSOConnectionCtxs)

return c
}
Expand Down
2 changes: 1 addition & 1 deletion client/inner_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *innerClient) setup() error {
}

// Register callbacks
c.serviceDiscovery.AddServingURLSwitchedCallback(c.scheduleUpdateTokenConnection)
c.serviceDiscovery.AddLeaderSwitchedCallback(c.scheduleUpdateTokenConnection)

// Create dispatchers
c.createTokenDispatcher()
Expand Down
4 changes: 2 additions & 2 deletions client/servicediscovery/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func (c *serviceCallbacks) setServiceModeUpdateCallback(cb func(pdpb.ServiceMode
c.serviceModeUpdateCb = cb
}

func (c *serviceCallbacks) addServingURLSwitchedCallback(cb leaderSwitchedCallbackFunc) {
func (c *serviceCallbacks) addLeaderSwitchedCallback(cb leaderSwitchedCallbackFunc) {
c.Lock()
defer c.Unlock()
c.leaderSwitchedCbs = append(c.leaderSwitchedCbs, cb)
}

func (c *serviceCallbacks) addServiceURLsSwitchedCallback(cb func()) {
func (c *serviceCallbacks) addMembersChangedCallback(cb func()) {
c.Lock()
defer c.Unlock()
c.membersChangedCbs = append(c.membersChangedCbs, cb)
Expand Down
12 changes: 6 additions & 6 deletions client/servicediscovery/mock_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func (*mockServiceDiscovery) ScheduleCheckMemberChanged() {}
// CheckMemberChanged implements the ServiceDiscovery interface.
func (*mockServiceDiscovery) CheckMemberChanged() error { return nil }

// ExecuteAndAddServingURLSwitchedCallback implements the ServiceDiscovery interface.
func (*mockServiceDiscovery) ExecuteAndAddServingURLSwitchedCallback(leaderSwitchedCallbackFunc) {}
// ExecAndAddLeaderSwitchedCallback implements the ServiceDiscovery interface.
func (*mockServiceDiscovery) ExecAndAddLeaderSwitchedCallback(leaderSwitchedCallbackFunc) {}

Check warning on line 104 in client/servicediscovery/mock_service_discovery.go

View check run for this annotation

Codecov / codecov/patch

client/servicediscovery/mock_service_discovery.go#L104

Added line #L104 was not covered by tests

// AddServingURLSwitchedCallback implements the ServiceDiscovery interface.
func (*mockServiceDiscovery) AddServingURLSwitchedCallback(leaderSwitchedCallbackFunc) {}
// AddLeaderSwitchedCallback implements the ServiceDiscovery interface.
func (*mockServiceDiscovery) AddLeaderSwitchedCallback(leaderSwitchedCallbackFunc) {}

Check warning on line 107 in client/servicediscovery/mock_service_discovery.go

View check run for this annotation

Codecov / codecov/patch

client/servicediscovery/mock_service_discovery.go#L107

Added line #L107 was not covered by tests

// AddServiceURLsSwitchedCallback implements the ServiceDiscovery interface.
func (*mockServiceDiscovery) AddServiceURLsSwitchedCallback(func()) {}
// AddMembersChangedCallback implements the ServiceDiscovery interface.
func (*mockServiceDiscovery) AddMembersChangedCallback(func()) {}

Check warning on line 110 in client/servicediscovery/mock_service_discovery.go

View check run for this annotation

Codecov / codecov/patch

client/servicediscovery/mock_service_discovery.go#L110

Added line #L110 was not covered by tests
30 changes: 15 additions & 15 deletions client/servicediscovery/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +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)
// AddServingURLSwitchedCallback adds callbacks which will be called when the leader
// ExecAndAddLeaderSwitchedCallback executes the callback once and adds it to the callback list then.
ExecAndAddLeaderSwitchedCallback(cb leaderSwitchedCallbackFunc)
// AddLeaderSwitchedCallback adds callbacks which will be called when the leader
// in a quorum-based cluster or the primary in a primary/secondary configured cluster
// is switched.
AddServingURLSwitchedCallback(cb leaderSwitchedCallbackFunc)
// AddServiceURLsSwitchedCallback adds callbacks which will be called when any leader/follower
AddLeaderSwitchedCallback(cb leaderSwitchedCallbackFunc)
// AddMembersChangedCallback adds callbacks which will be called when any leader/follower
// in a quorum-based cluster or any primary/secondary in a primary/secondary configured cluster
// is changed.
AddServiceURLsSwitchedCallback(cb func())
AddMembersChangedCallback(cb func())
}

// ServiceClient is an interface that defines a set of operations for a raw PD gRPC client to specific PD server.
Expand Down Expand Up @@ -776,29 +776,29 @@ func (c *serviceDiscovery) CheckMemberChanged() error {
return c.updateMember()
}

// ExecuteAndAddServingURLSwitchedCallback executes the callback once and adds it to the callback list then.
func (c *serviceDiscovery) ExecuteAndAddServingURLSwitchedCallback(callback leaderSwitchedCallbackFunc) {
// ExecAndAddLeaderSwitchedCallback executes the callback once and adds it to the callback list then.
func (c *serviceDiscovery) ExecAndAddLeaderSwitchedCallback(callback leaderSwitchedCallbackFunc) {
url := c.getLeaderURL()
if len(url) > 0 {
if err := callback(url); err != nil {
log.Error("[pd] failed to run a callback with the current leader url",
zap.String("url", url), errs.ZapError(err))

Check warning on line 785 in client/servicediscovery/service_discovery.go

View check run for this annotation

Codecov / codecov/patch

client/servicediscovery/service_discovery.go#L784-L785

Added lines #L784 - L785 were not covered by tests
}
}
c.AddServingURLSwitchedCallback(callback)
c.AddLeaderSwitchedCallback(callback)
}

// AddServingURLSwitchedCallback adds callbacks which will be called when the leader
// AddLeaderSwitchedCallback adds callbacks which will be called when the leader
// in a quorum-based cluster or the primary in a primary/secondary configured cluster
// is switched.
func (c *serviceDiscovery) AddServingURLSwitchedCallback(callback leaderSwitchedCallbackFunc) {
c.callbacks.addServingURLSwitchedCallback(callback)
func (c *serviceDiscovery) AddLeaderSwitchedCallback(callback leaderSwitchedCallbackFunc) {
c.callbacks.addLeaderSwitchedCallback(callback)
}

// AddServiceURLsSwitchedCallback adds callbacks which will be called when any primary/secondary
// AddMembersChangedCallback adds callbacks which will be called when any primary/secondary
// in a primary/secondary configured cluster is changed.
func (c *serviceDiscovery) AddServiceURLsSwitchedCallback(callback func()) {
c.callbacks.addServiceURLsSwitchedCallback(callback)
func (c *serviceDiscovery) AddMembersChangedCallback(callback func()) {
c.callbacks.addMembersChangedCallback(callback)
}

// getLeaderURL returns the leader URL.
Expand Down
12 changes: 6 additions & 6 deletions client/servicediscovery/tso_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ func (c *tsoServiceDiscovery) CheckMemberChanged() error {
return nil
}

// ExecuteAndAddServingURLSwitchedCallback executes the callback once and adds it to the callback list then.
func (c *tsoServiceDiscovery) ExecuteAndAddServingURLSwitchedCallback(callback leaderSwitchedCallbackFunc) {
// ExecAndAddLeaderSwitchedCallback executes the callback once and adds it to the callback list then.
func (c *tsoServiceDiscovery) ExecAndAddLeaderSwitchedCallback(callback leaderSwitchedCallbackFunc) {
url := c.getPrimaryURL()
if len(url) > 0 {
if err := callback(url); err != nil {
Expand All @@ -369,13 +369,13 @@ func (c *tsoServiceDiscovery) ExecuteAndAddServingURLSwitchedCallback(callback l
c.tsoLeaderUpdatedCb = callback
}

// AddServingURLSwitchedCallback adds callbacks which will be called when the primary in
// AddLeaderSwitchedCallback adds callbacks which will be called when the primary in
// a primary/secondary configured cluster is switched.
func (*tsoServiceDiscovery) AddServingURLSwitchedCallback(leaderSwitchedCallbackFunc) {}
func (*tsoServiceDiscovery) AddLeaderSwitchedCallback(leaderSwitchedCallbackFunc) {}

Check warning on line 374 in client/servicediscovery/tso_service_discovery.go

View check run for this annotation

Codecov / codecov/patch

client/servicediscovery/tso_service_discovery.go#L374

Added line #L374 was not covered by tests

// AddServiceURLsSwitchedCallback adds callbacks which will be called when any primary/secondary
// AddMembersChangedCallback adds callbacks which will be called when any primary/secondary
// in a primary/secondary configured cluster is changed.
func (*tsoServiceDiscovery) AddServiceURLsSwitchedCallback(func()) {}
func (*tsoServiceDiscovery) AddMembersChangedCallback(func()) {}

// GetServiceClient implements ServiceDiscovery
func (c *tsoServiceDiscovery) GetServiceClient() ServiceClient {
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func TestGetTSAfterTransferLeader(t *testing.T) {
defer cli.Close()

var leaderSwitched atomic.Bool
cli.GetServiceDiscovery().AddServingURLSwitchedCallback(func(string) error {
cli.GetServiceDiscovery().AddLeaderSwitchedCallback(func(string) error {
leaderSwitched.Store(true)
return nil
})
Expand Down

0 comments on commit 62b7b61

Please sign in to comment.