From c54fc4290597453c1d1a90ffcb71b1c35aa9cf02 Mon Sep 17 00:00:00 2001 From: Bin Shi <39923490+binshi-bing@users.noreply.github.com> Date: Thu, 1 Jun 2023 02:44:42 -0700 Subject: [PATCH] mcs, tso: delete the tso ms discovery when switching away from API mode. (#6544) close tikv/pd#6543 When switching from the PD mode to the API mode, the old tso microservice discovery isn't needed anymore, and all resources can be released to avoid noisy error logs when the component trying to discover the non-existent tso microservice. Signed-off-by: Bin Shi --- client/client.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/client.go b/client/client.go index 69531ba4001..6bbe239814b 100644 --- a/client/client.go +++ b/client/client.go @@ -600,13 +600,13 @@ func (c *client) setServiceMode(newMode pdpb.ServiceMode) { oldTSOClient.Close() // Replace the old TSO service discovery if needed. oldTSOSvcDiscovery := c.tsoSvcDiscovery - if newTSOSvcDiscovery != nil { - c.tsoSvcDiscovery = newTSOSvcDiscovery - // Close the old TSO service discovery safely after both the old client - // and service discovery are replaced. - if oldTSOSvcDiscovery != nil { - oldTSOSvcDiscovery.Close() - } + // If newTSOSvcDiscovery is nil, that's expected, as it means we are switching to PD service mode and + // no tso microservice discovery is needed. + c.tsoSvcDiscovery = newTSOSvcDiscovery + // Close the old TSO service discovery safely after both the old client and service discovery are replaced. + if oldTSOSvcDiscovery != nil { + // We are switching from API service mode to PD service mode, so delete the old tso microservice discovery. + oldTSOSvcDiscovery.Close() } oldMode := c.serviceMode c.serviceMode = newMode