diff --git a/pkg/schedule/coordinator.go b/pkg/schedule/coordinator.go index b64ec88b47a..cb36a367165 100644 --- a/pkg/schedule/coordinator.go +++ b/pkg/schedule/coordinator.go @@ -316,7 +316,7 @@ func (c *Coordinator) RunUntilStop() { c.Run() <-c.ctx.Done() log.Info("Coordinator is stopping") - c.GetSchedulersController().GetWaitGroup().Wait() + c.GetSchedulersController().Wait() c.wg.Wait() log.Info("Coordinator has been stopped") } diff --git a/pkg/schedule/schedulers/scheduler_controller.go b/pkg/schedule/schedulers/scheduler_controller.go index 635b14b11fe..ec6b07196b5 100644 --- a/pkg/schedule/schedulers/scheduler_controller.go +++ b/pkg/schedule/schedulers/scheduler_controller.go @@ -59,9 +59,9 @@ func NewController(ctx context.Context, cluster sche.ScheduleCluster, storage en } } -// GetWaitGroup returns the waitGroup of the controller. -func (c *Controller) GetWaitGroup() *sync.WaitGroup { - return &c.wg +// Wait waits on all schedulers to exit. +func (c *Controller) Wait() { + c.wg.Wait() } // GetScheduler returns a schedule controller by name. diff --git a/server/cluster/cluster_test.go b/server/cluster/cluster_test.go index e6f2cf9e2c2..35e2ba9fa9a 100644 --- a/server/cluster/cluster_test.go +++ b/server/cluster/cluster_test.go @@ -2440,7 +2440,7 @@ func prepare(setCfg func(*config.ScheduleConfig), setTc func(*testCluster), run } return tc, co, func() { co.Stop() - co.GetSchedulersController().GetWaitGroup().Wait() + co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() hbStreams.Close() cancel() @@ -2723,7 +2723,7 @@ func TestCheckCache(t *testing.T) { re.Len(oc.GetOperators(), 1) re.Empty(co.GetCheckerController().GetWaitingRegions()) - co.GetSchedulersController().GetWaitGroup().Wait() + co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/schedule/break-patrol")) } @@ -2976,7 +2976,7 @@ func TestPersistScheduler(t *testing.T) { re.Len(sc.GetSchedulerNames(), defaultCount-3) re.NoError(co.GetCluster().GetPersistOptions().Persist(storage)) co.Stop() - co.GetSchedulersController().GetWaitGroup().Wait() + co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() // make a new coordinator for testing // whether the schedulers added or removed in dynamic way are recorded in opt @@ -3006,7 +3006,7 @@ func TestPersistScheduler(t *testing.T) { sc = co.GetSchedulersController() re.Len(sc.GetSchedulerNames(), 3) co.Stop() - co.GetSchedulersController().GetWaitGroup().Wait() + co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() // suppose restart PD again _, newOpt, err = newTestScheduleConfig() @@ -3034,7 +3034,7 @@ func TestPersistScheduler(t *testing.T) { re.Len(sc.GetSchedulerNames(), 4) re.NoError(co.GetCluster().GetPersistOptions().Persist(co.GetCluster().GetStorage())) co.Stop() - co.GetSchedulersController().GetWaitGroup().Wait() + co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() _, newOpt, err = newTestScheduleConfig() re.NoError(err) @@ -3091,7 +3091,7 @@ func TestRemoveScheduler(t *testing.T) { re.Empty(sc.GetSchedulerNames()) re.NoError(co.GetCluster().GetPersistOptions().Persist(co.GetCluster().GetStorage())) co.Stop() - co.GetSchedulersController().GetWaitGroup().Wait() + co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() // suppose restart PD again @@ -3105,7 +3105,7 @@ func TestRemoveScheduler(t *testing.T) { // the option remains default scheduler re.Len(co.GetCluster().GetPersistOptions().GetSchedulers(), defaultCount) co.Stop() - co.GetSchedulersController().GetWaitGroup().Wait() + co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() } @@ -3137,7 +3137,7 @@ func TestRestart(t *testing.T) { re.NoError(dispatchHeartbeat(co, region, stream)) region = waitPromoteLearner(re, stream, region, 2) co.Stop() - co.GetSchedulersController().GetWaitGroup().Wait() + co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() // Recreate coordinator then add another replica on store 3.