Move autopilot health loop into leader operations

This commit is contained in:
Kyle Havlovitz 2018-01-23 11:17:41 -08:00
parent a4c3a3433c
commit 6d1dbe6cc4
No known key found for this signature in database
GPG Key ID: 8A5E6B173056AD6C
2 changed files with 7 additions and 7 deletions

View File

@ -64,9 +64,10 @@ func NewAutopilot(logger *log.Logger, delegate Delegate, interval, healthInterva
func (a *Autopilot) Start() {
a.shutdownCh = make(chan struct{})
a.waitGroup = sync.WaitGroup{}
a.waitGroup.Add(1)
a.waitGroup.Add(2)
go a.run()
go a.serverHealthLoop()
}
func (a *Autopilot) Stop() {
@ -299,15 +300,17 @@ func (a *Autopilot) handlePromotions(promotions []raft.Server) error {
return nil
}
// ServerHealthLoop monitors the health of the servers in the cluster
func (a *Autopilot) ServerHealthLoop(shutdownCh <-chan struct{}) {
// serverHealthLoop monitors the health of the servers in the cluster
func (a *Autopilot) serverHealthLoop() {
defer a.waitGroup.Done()
// Monitor server health until shutdown
ticker := time.NewTicker(a.healthInterval)
defer ticker.Stop()
for {
select {
case <-shutdownCh:
case <-a.shutdownCh:
return
case <-ticker.C:
if err := a.updateClusterHealth(); err != nil {

View File

@ -418,9 +418,6 @@ func NewServerLogger(config *Config, logger *log.Logger, tokens *token.Store) (*
// Initialize Autopilot
s.initAutopilot(config)
// Start the server health checking.
go s.autopilot.ServerHealthLoop(s.shutdownCh)
return s, nil
}