diff --git a/pkg/schedule/coordinator.go b/pkg/schedule/coordinator.go index 1603bb01c34..bdb7fcb464d 100644 --- a/pkg/schedule/coordinator.go +++ b/pkg/schedule/coordinator.go @@ -217,7 +217,11 @@ func (c *Coordinator) runPrepareChecker() { case <-c.ctx.Done(): return case <-ticker.C: - c.prepareChecker.Check(c.cluster.GetBasicCluster()) + if !c.prepareChecker.IsPrepared() { + if c.prepareChecker.Check(c.cluster.GetBasicCluster()) { + log.Info("prepare checker is finished") + } + } } } } diff --git a/pkg/schedule/core/prepare_checker.go b/pkg/schedule/core/prepare_checker.go index 3c5432a9812..ffc2a507175 100644 --- a/pkg/schedule/core/prepare_checker.go +++ b/pkg/schedule/core/prepare_checker.go @@ -41,9 +41,6 @@ func NewPrepareChecker() *PrepareChecker { // Check checks if the coordinator has finished cluster information preparation. func (checker *PrepareChecker) Check(c *core.BasicCluster) bool { - if checker.IsPrepared() { - return true - } checker.Lock() defer checker.Unlock() diff --git a/server/cluster/cluster_test.go b/server/cluster/cluster_test.go index cbb4574ca7e..9b856ebc390 100644 --- a/server/cluster/cluster_test.go +++ b/server/cluster/cluster_test.go @@ -2873,6 +2873,7 @@ func TestCheckCache(t *testing.T) { cfg.ReplicaScheduleLimit = 0 }, nil, nil, re) defer cleanup() + co.GetPrepareChecker().SetPrepared() oc := co.GetOperatorController() checker := co.GetCheckerController() @@ -3028,6 +3029,7 @@ func TestPeerState(t *testing.T) { tc, co, cleanup := prepare(nil, nil, func(co *schedule.Coordinator) { co.Run() }, re) defer cleanup() + co.GetPrepareChecker().SetPrepared() // Transfer peer from store 4 to store 1. re.NoError(tc.addRegionStore(1, 10)) @@ -3072,6 +3074,7 @@ func TestAddScheduler(t *testing.T) { tc, co, cleanup := prepare(nil, nil, func(co *schedule.Coordinator) { co.Run() }, re) defer cleanup() + co.GetPrepareChecker().SetPrepared() controller := co.GetSchedulersController() re.Len(controller.GetSchedulerNames(), len(sc.DefaultSchedulers)) re.NoError(controller.RemoveScheduler(types.BalanceLeaderScheduler.String()))