From 95bd45e139f2325a3939abf4983d18519d96ee33 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Mon, 20 Jan 2025 11:48:28 +0800 Subject: [PATCH] address comments Signed-off-by: Ryan Leung --- client/client.go | 2 +- client/inner_client.go | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/client/client.go b/client/client.go index e1178733ae9..fa0a1473ba7 100644 --- a/client/client.go +++ b/client/client.go @@ -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 { diff --git a/client/inner_client.go b/client/inner_client.go index 8e40d88cbd7..918941f630a 100644 --- a/client/inner_client.go +++ b/client/inner_client.go @@ -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" + } } // Reset a new TSO client. @@ -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)