From 403ae9eed436f9bf0b2069c812e8d20b976ba2a3 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Thu, 7 Nov 2024 12:23:16 +0800 Subject: [PATCH] cluster: fix tso fallback when pd leader switch Signed-off-by: lhy1024 --- server/cluster/cluster.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index 7eb82c99b257..9d09be64fe1b 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -471,7 +471,7 @@ func (c *RaftCluster) startTSOJobsIfNeeded() error { log.Error("failed to get global TSO allocator", errs.ZapError(err)) return err } - if !allocator.IsInitialize() { + if !allocator.IsInitialize() && c.IsRunning() { log.Info("initializing the global TSO allocator") if err := allocator.Initialize(0); err != nil { log.Error("failed to initialize the global TSO allocator", errs.ZapError(err)) @@ -487,7 +487,8 @@ func (c *RaftCluster) stopTSOJobsIfNeeded() error { log.Error("failed to get global TSO allocator", errs.ZapError(err)) return err } - if allocator.IsInitialize() { + if allocator.IsInitialize() && c.IsRunning() { + log.Info("closing the global TSO allocator") c.tsoAllocator.ResetAllocatorGroup(tso.GlobalDCLocation, true) failpoint.Inject("updateAfterResetTSO", func() { allocator, _ := c.tsoAllocator.GetAllocator(tso.GlobalDCLocation)