From 051907b3d98749eb26939502b576f1f0922bb269 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Thu, 7 Nov 2024 15:24:34 +0800 Subject: [PATCH] cluster: fix tso fallback when pd leader switch (#8783) (#8784) close tikv/pd#8781 Signed-off-by: lhy1024 Co-authored-by: lhy1024 --- server/cluster/cluster.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index 46a525a3e09..9d6f51b48e7 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -461,7 +461,14 @@ 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 + // ref: https://github.com/tikv/pd/issues/8781 + c.RLock() + if c.running { + c.checkTSOService() + } + c.RUnlock() } } } @@ -489,6 +496,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)