Skip to content

Commit

Permalink
address the comment
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Oct 9, 2023
1 parent 035489c commit 891a322
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions pkg/mcs/scheduling/server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ func (c *Cluster) SwitchAPIServerLeader(new pdpb.PDClient) bool {
return c.apiServerLeader.CompareAndSwap(old, new)
}

func trySend(notifier chan struct{}) {
select {
case notifier <- struct{}{}:
// If the channel is not empty, it means the check is triggered.
default:
}
}

// updateScheduler listens on the schedulers updating notifier and manage the scheduler creation and deletion.
func (c *Cluster) updateScheduler() {
defer logutil.LogPanic()
Expand All @@ -214,12 +222,7 @@ func (c *Cluster) updateScheduler() {
// Establish a notifier to listen the schedulers updating.
notifier := make(chan struct{}, 1)
// Make sure the check will be triggered once later.
select {
case notifier <- struct{}{}:
// If the channel is not empty, it means the check is triggered.
default:
}

trySend(notifier)
c.persistConfig.SetSchedulersUpdatingNotifier(notifier)
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
Expand All @@ -240,11 +243,7 @@ func (c *Cluster) updateScheduler() {
return
case <-ticker.C:
// retry
select {
case notifier <- struct{}{}:
// If the channel is not empty, it means the check is triggered.
default:
}
trySend(notifier)
continue
}
}
Expand Down

0 comments on commit 891a322

Please sign in to comment.