From dcfbff7ebc32cea0fedab0a09a3bb7e8254c386e Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Tue, 30 Nov 2021 14:09:39 +0800 Subject: [PATCH] cluster: speed scheduler exit (#4148) (#4198) * This is an automated cherry-pick of #4148 Signed-off-by: ti-chi-bot --- server/cluster/cluster.go | 2 +- server/cluster/coordinator.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index c99bc43671f..2dc3cc42743 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -359,8 +359,8 @@ func (c *RaftCluster) Stop() { } c.running = false - close(c.quit) c.coordinator.stop() + close(c.quit) c.Unlock() c.wg.Wait() log.Info("raftcluster is stopped") diff --git a/server/cluster/coordinator.go b/server/cluster/coordinator.go index f89a547019c..4fe6af422de 100644 --- a/server/cluster/coordinator.go +++ b/server/cluster/coordinator.go @@ -775,6 +775,12 @@ func (s *scheduleController) Stop() { func (s *scheduleController) Schedule() []*operator.Operator { for i := 0; i < maxScheduleRetries; i++ { + // no need to retry if schedule should stop to speed exit + select { + case <-s.ctx.Done(): + return nil + default: + } // If we have schedule, reset interval to the minimal interval. if op := s.Scheduler.Schedule(s.cluster); op != nil { s.nextInterval = s.Scheduler.GetMinInterval()