From 2f0a502b237fe1c08b17ba17528974ae441842a5 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Wed, 30 Oct 2024 13:40:00 +0800 Subject: [PATCH] address the comment Signed-off-by: Ryan Leung --- server/cluster/cluster.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index 0bc656bb41ee..a9ab43579cf4 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -406,14 +406,14 @@ func (c *RaftCluster) checkTSOService() { if c.opt.GetMicroServiceConfig().IsTSODynamicSwitchingEnabled() { servers, err := discovery.Discover(c.etcdClient, strconv.FormatUint(c.clusterID, 10), constant.TSOServiceName) if err != nil || len(servers) == 0 { - if err := c.startTSOJobs(); err != nil { + if err := c.startTSOJobsIfNeeded(); err != nil { log.Error("failed to start TSO jobs", errs.ZapError(err)) return } log.Info("TSO is provided by PD") c.UnsetServiceIndependent(constant.TSOServiceName) } else { - if err := c.stopTSOJobs(); err != nil { + if err := c.startTSOJobsIfNeeded(); err != nil { log.Error("failed to stop TSO jobs", errs.ZapError(err)) return } @@ -426,7 +426,7 @@ func (c *RaftCluster) checkTSOService() { return } - if err := c.startTSOJobs(); err != nil { + if err := c.startTSOJobsIfNeeded(); err != nil { log.Error("failed to start TSO jobs", errs.ZapError(err)) return } @@ -457,7 +457,7 @@ func (c *RaftCluster) runServiceCheckJob() { } } -func (c *RaftCluster) startTSOJobs() error { +func (c *RaftCluster) startTSOJobsIfNeeded() error { allocator, err := c.tsoAllocator.GetAllocator(tso.GlobalDCLocation) if err != nil { log.Error("failed to get global TSO allocator", errs.ZapError(err)) @@ -473,7 +473,7 @@ func (c *RaftCluster) startTSOJobs() error { return nil } -func (c *RaftCluster) stopTSOJobs() error { +func (c *RaftCluster) stopTSOJobsIfNeeded() error { allocator, err := c.tsoAllocator.GetAllocator(tso.GlobalDCLocation) if err != nil { log.Error("failed to get global TSO allocator", errs.ZapError(err)) @@ -841,7 +841,7 @@ func (c *RaftCluster) Stop() { if !c.IsServiceIndependent(constant.SchedulingServiceName) { c.stopSchedulingJobs() } - if err := c.stopTSOJobs(); err != nil { + if err := c.stopTSOJobsIfNeeded(); err != nil { log.Error("failed to stop tso jobs", errs.ZapError(err)) } c.heartbeatRunner.Stop()