From c098dbb6463a9864390e8204090d03931d85998a Mon Sep 17 00:00:00 2001 From: gladiator Date: Tue, 26 Sep 2017 11:16:11 +0800 Subject: [PATCH] raft: promotable check raft suffrage --- raft/raft.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/raft/raft.go b/raft/raft.go index 8ad59eacd23..2afaaca83d3 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -587,9 +587,7 @@ func (r *raft) tickElection() { if r.promotable() && r.pastElectionTimeout() { r.electionElapsed = 0 - if r.suffrage == pb.Voter { - r.Step(pb.Message{From: r.id, Type: pb.MsgHup}) - } + r.Step(pb.Message{From: r.id, Type: pb.MsgHup}) } } @@ -1237,10 +1235,10 @@ func (r *raft) restore(s pb.Snapshot) bool { } // promotable indicates whether state machine can be promoted to leader, -// which is true when its own id is in progress list. +// which is true when its own id is in progress list and suffrage is Voter func (r *raft) promotable() bool { _, ok := r.prs[r.id] - return ok + return ok && r.suffrage == pb.Voter } func (r *raft) addNode(id uint64) {