From aed6ace7ffd68eec9fb44216bec6b7d3b12d109b Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Thu, 7 Nov 2024 13:08:06 +0800 Subject: [PATCH] cluster: fix tso fallback when pd leader switch Signed-off-by: lhy1024 --- server/cluster/cluster.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index 46a525a3e09..796a5963630 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -461,7 +461,13 @@ func (c *RaftCluster) runServiceCheckJob() { case <-schedulingTicker.C: c.checkSchedulingService() case <-tsoTicker.C: - c.checkTSOService() + // ensure raft cluster is running + // avoid unexpected startTSOJobsIfNeeded when raft cluster is stopping + c.RLock() + if c.running { + c.checkTSOService() + } + c.RUnlock() } } } @@ -489,6 +495,7 @@ func (c *RaftCluster) stopTSOJobsIfNeeded() error { return err } if allocator.IsInitialize() { + log.Info("closing the global TSO allocator") c.tsoAllocator.ResetAllocatorGroup(tso.GlobalDCLocation, true) failpoint.Inject("updateAfterResetTSO", func() { allocator, _ := c.tsoAllocator.GetAllocator(tso.GlobalDCLocation)