From a7fca8d6a765a8e34b5399522cbe798356cf099c Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Tue, 4 Apr 2017 15:42:17 -0700 Subject: [PATCH] Use voter count instead of server count for required quorum --- consul/autopilot.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/consul/autopilot.go b/consul/autopilot.go index e1a87479b..05cefae2b 100644 --- a/consul/autopilot.go +++ b/consul/autopilot.go @@ -311,8 +311,9 @@ func (s *Server) updateClusterHealth() error { // Build a current list of server healths leader := s.raft.Leader() var clusterHealth structs.OperatorHealthReply - healthyCount := 0 voterCount := 0 + healthyCount := 0 + healthyVoterCount := 0 for _, server := range servers { health := structs.ServerHealth{ ID: string(server.ID), @@ -336,10 +337,13 @@ func (s *Server) updateClusterHealth() error { health.SerfStatus = serf.StatusNone } + if health.Voter { + voterCount++ + } if health.Healthy { healthyCount++ if health.Voter { - voterCount++ + healthyVoterCount++ } } @@ -348,9 +352,9 @@ func (s *Server) updateClusterHealth() error { clusterHealth.Healthy = healthyCount == len(servers) // If we have extra healthy voters, update FailureTolerance - requiredQuorum := len(servers)/2 + 1 - if voterCount > requiredQuorum { - clusterHealth.FailureTolerance = voterCount - requiredQuorum + requiredQuorum := voterCount/2 + 1 + if healthyVoterCount > requiredQuorum { + clusterHealth.FailureTolerance = healthyVoterCount - requiredQuorum } // Heartbeat a metric for monitoring if we're the leader