Browse Source

raft: Set the RecentActive flag for newly added nodes

I found that enabling the CheckQuorum flag led to spurious leader
elections when new nodes joined. It looks like in the time between a new
node joining the cluster, and that node first communicating with the
leader, the quorum check could fail because the new node looks inactive.
To solve this, set the RecentActive flag when nodes are first added.
This gives a grace period for the node to communicate before it causes
the quorum check to fail.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Aaron Lehmann 8 years ago
parent
commit
52613b262b
1 changed files with 4 additions and 0 deletions
  1. 4 0
      raft/raft.go

+ 4 - 0
raft/raft.go

@@ -1159,6 +1159,10 @@ func (r *raft) addNode(id uint64) {
 	}
 	}
 
 
 	r.setProgress(id, 0, r.raftLog.lastIndex()+1)
 	r.setProgress(id, 0, r.raftLog.lastIndex()+1)
+	// When a node is first added, we should mark it as recently active.
+	// Otherwise, CheckQuorum may cause us to step down if it is invoked
+	// before the added node has a chance to communicate with us.
+	r.prs[id].RecentActive = true
 }
 }
 
 
 func (r *raft) removeNode(id uint64) {
 func (r *raft) removeNode(id uint64) {