Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Jan 20, 2025
1 parent 7c30b3f commit 95bd45e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (c *client) UpdateOption(option opt.DynamicOption, value any) error {
}
case opt.EnableTSOFollowerProxy:
if c.inner.getServiceMode() != pdpb.ServiceMode_PD_SVC_MODE {
return errors.New("[pd] tso follower proxy is only supported in non-microservice environment")
return errors.New("[pd] tso follower proxy is only supported when PD provides TSO")
}
enable, ok := value.(bool)
if !ok {
Expand Down
23 changes: 20 additions & 3 deletions client/inner_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,31 @@ func (c *innerClient) setServiceMode(newMode pdpb.ServiceMode) {
// If we are using TSO server proxy, we always use PD_SVC_MODE.
newMode = pdpb.ServiceMode_PD_SVC_MODE
}

if newMode == c.serviceMode {
return
}
log.Info("[pd] changing TSO provider",
zap.String("old", convertToString(c.serviceMode)),
zap.String("new", convertToString(newMode)))
c.resetTSOClientLocked(newMode)
oldMode := c.serviceMode
c.serviceMode = newMode
log.Info("[pd] TSO provider changed",
zap.String("old", convertToString(oldMode)),
zap.String("new", convertToString(newMode)))
}

func convertToString(mode pdpb.ServiceMode) string {
switch mode {
case pdpb.ServiceMode_PD_SVC_MODE:
return "pd"
case pdpb.ServiceMode_API_SVC_MODE:
return "tso server"
case pdpb.ServiceMode_UNKNOWN_SVC_MODE:
return "unknown"
default:
return "invalid"

Check warning on line 93 in client/inner_client.go

View check run for this annotation

Codecov / codecov/patch

client/inner_client.go#L92-L93

Added lines #L92 - L93 were not covered by tests
}
}

// Reset a new TSO client.
Expand All @@ -84,11 +103,9 @@ func (c *innerClient) resetTSOClientLocked(mode pdpb.ServiceMode) {
)
switch mode {
case pdpb.ServiceMode_PD_SVC_MODE:
log.Info("[pd] use PD service discovery for tso")
newTSOCli = tso.NewClient(c.ctx, c.option,
c.serviceDiscovery, &tso.PDStreamBuilderFactory{})
case pdpb.ServiceMode_API_SVC_MODE:
log.Info("[pd] use independent tso service discovery for tso")
newTSOSvcDiscovery = sd.NewTSOServiceDiscovery(
c.ctx, c, c.serviceDiscovery,
c.keyspaceID, c.tlsCfg, c.option)
Expand Down

0 comments on commit 95bd45e

Please sign in to comment.