Skip to content

Commit

Permalink
checkLeaderLease: count only voters into quorum (hashicorp#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
santhosh-tekuri authored and schristoff committed Jul 17, 2019
1 parent 904f3b9 commit 6e41709
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,27 +846,34 @@ func (r *Raft) leadershipTransfer(id ServerID, address ServerAddress, repl *foll
// contact. This must only be called from the main thread.
func (r *Raft) checkLeaderLease() time.Duration {
// Track contacted nodes, we can always contact ourself
contacted := 1
contacted := 0

// Check each follower
var maxDiff time.Duration
now := time.Now()
for peer, f := range r.leaderState.replState {
diff := now.Sub(f.LastContact())
if diff <= r.conf.LeaderLeaseTimeout {
contacted++
if diff > maxDiff {
maxDiff = diff
for _, server := range r.configurations.latest.Servers {
if server.Suffrage == Voter {
if server.ID == r.localID {
contacted++
continue
}
} else {
// Log at least once at high value, then debug. Otherwise it gets very verbose.
if diff <= 3*r.conf.LeaderLeaseTimeout {
r.logger.Warn(fmt.Sprintf("Failed to contact %v in %v", peer, diff))
f := r.leaderState.replState[server.ID]
diff := now.Sub(f.LastContact())
if diff <= r.conf.LeaderLeaseTimeout {
contacted++
if diff > maxDiff {
maxDiff = diff
}
} else {
r.logger.Debug(fmt.Sprintf("Failed to contact %v in %v", peer, diff))
// Log at least once at high value, then debug. Otherwise it gets very verbose.
if diff <= 3*r.conf.LeaderLeaseTimeout {
r.logger.Warn(fmt.Sprintf("Failed to contact %v in %v", server.ID, diff))
} else {
r.logger.Debug(fmt.Sprintf("Failed to contact %v in %v", server.ID, diff))
}
}
metrics.AddSample([]string{"raft", "leader", "lastContact"}, float32(diff/time.Millisecond))
}
metrics.AddSample([]string{"raft", "leader", "lastContact"}, float32(diff/time.Millisecond))
}

// Verify we can contact a quorum
Expand Down

0 comments on commit 6e41709

Please sign in to comment.