leadership: pause and unpause workers consistently

This fixes a bug where leadership establishment pauses 3/4 of workers
but stepping down unpause only 1/2!
This commit is contained in:
Mahmood Ali
2020-06-01 10:57:53 -04:00
parent 764cdac01a
commit 01fcd2ba9b

View File

@@ -206,12 +206,8 @@ func (s *Server) establishLeadership(stopCh chan struct{}) error {
// Disable workers to free half the cores for use in the plan queue and
// evaluation broker
if numWorkers := len(s.workers); numWorkers > 1 {
// Disabling 3/4 of the workers frees CPU for raft and the
// plan applier which uses 1/2 the cores.
for i := 0; i < (3 * numWorkers / 4); i++ {
s.workers[i].SetPause(true)
}
for _, w := range s.pausableWorkers() {
w.SetPause(true)
}
// Initialize and start the autopilot routine
@@ -913,14 +909,29 @@ func (s *Server) revokeLeadership() error {
}
// Unpause our worker if we paused previously
if len(s.workers) > 1 {
for i := 0; i < len(s.workers)/2; i++ {
s.workers[i].SetPause(false)
}
for _, w := range s.pausableWorkers() {
w.SetPause(false)
}
return nil
}
// pausableWorkers returns a slice of the workers
// to pause on leader transitions.
//
// Upon leadership establishment, pause workers to free half
// the cores for use in the plan queue and evaluation broker
func (s *Server) pausableWorkers() []*Worker {
n := len(s.workers)
if n <= 1 {
return []*Worker{}
}
// Disabling 3/4 of the workers frees CPU for raft and the
// plan applier which uses 1/2 the cores.
return s.workers[:3*n/4]
}
// reconcile is used to reconcile the differences between Serf
// membership and what is reflected in our strongly consistent store.
func (s *Server) reconcile() error {