Skip to content

Commit

Permalink
raft: promotable check raft suffrage
Browse files Browse the repository at this point in the history
  • Loading branch information
lishuai87 committed Sep 26, 2017
1 parent a91a51d commit c098dbb
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c098dbb

Please sign in to comment.