Use voter count instead of server count for required quorum

This commit is contained in:
Kyle Havlovitz 2017-04-04 15:42:17 -07:00
parent ed7a6526e9
commit a7fca8d6a7
No known key found for this signature in database
GPG Key ID: 8A5E6B173056AD6C
1 changed files with 9 additions and 5 deletions

View File

@ -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