Merge pull request #6286 from bdarnell/initial-election-check-quorum

raft: Allow an election immediately after start with checkQuorum
This commit is contained in:
Xiang Li 2016-08-29 17:59:32 -07:00 committed by GitHub
commit 48f4a7d037
2 changed files with 3 additions and 5 deletions

View File

@ -598,7 +598,7 @@ func (r *raft) Step(m pb.Message) error {
lead := m.From
if m.Type == pb.MsgVote {
force := bytes.Equal(m.Context, []byte(campaignTransfer))
inLease := r.checkQuorum && r.state != StateCandidate && r.electionElapsed < r.electionTimeout
inLease := r.checkQuorum && r.lead != None && r.electionElapsed < r.electionTimeout
if !force && inLease {
// If a server receives a RequestVote request within the minimum election timeout
// of hearing from a current leader, it does not update its term or grant its vote

View File

@ -1281,10 +1281,8 @@ func TestLeaderElectionWithCheckQuorum(t *testing.T) {
setRandomizedElectionTimeout(a, a.electionTimeout+1)
setRandomizedElectionTimeout(b, b.electionTimeout+2)
// Letting b's electionElapsed reach to timeout so that it can vote for a
for i := 0; i < b.electionTimeout; i++ {
b.tick()
}
// Immediately after creation, votes are cast regardless of the
// election timeout.
nt.send(pb.Message{From: 1, To: 1, Type: pb.MsgHup})
if a.state != StateLeader {