RequestVote Receiver behavior questions

56 views
Skip to first unread message

Hao Ren

unread,
Jul 27, 2017, 7:11:53 PM7/27/17
to raft-dev
The raft paper mentioned that:

For RequestVote RPC,

Receiver implementation:
1. Reply false if term < currentTerm (§5.1)
2. If votedFor is null or candidateId, and candidate’s log is at least as up-to-date as receiver’s log, grant vote (§5.2, §5.4)

Question 1:

Should VoteRequest also be rejected when term(received) == currentTerm ?
Because a follower in term T means it knows the leaders => election for Term T is already ended, a RequestVote with the same term as a follower's should be considered as outdated.

Question 2:

It is not clear when votedFor should be updated. More precisely, when to set VotedFor to None ? when to set VotedFor to some condidateId ?
A reasonable guess is that:
set to some candidateId when it received a RequestVote with a higher term
set to None when it recevied a Appendre

Thank you.


Henrik Ingo

unread,
Jul 28, 2017, 4:19:35 AM7/28/17
to raft...@googlegroups.com
Hi Hao

On Fri, Jul 28, 2017 at 2:11 AM, Hao Ren <inv...@gmail.com> wrote:
> The raft paper mentioned that:
>
> For RequestVote RPC,
>
> Receiver implementation:
> 1. Reply false if term < currentTerm (§5.1)
> 2. If votedFor is null or candidateId, and candidate’s log is at least as
> up-to-date as receiver’s log, grant vote (§5.2, §5.4)
>
> Question 1:
>
> Should VoteRequest also be rejected when term(received) == currentTerm ?
> Because a follower in term T means it knows the leaders => election for Term
> T is already ended, a RequestVote with the same term as a follower's should
> be considered as outdated.

When term == currentTerm, you send send the same response as you've
already done. In other words, if votedFor == candidateId, grant the
vote. For example, if the first response was somehow lost, such as due
to network issues, then you need to resend it. The important thing is
that when responding multiple times to the same RequestVote, you send
the same reply each time, so you don't vote for different candidates
in the same election.

If you read slowly enough, you will notice that the text you've quoted
above actually says exactly this, but it's not obvious.

> Question 2:
>
> It is not clear when votedFor should be updated. More precisely, when to set
> VotedFor to None ? when to set VotedFor to some condidateId ?
> A reasonable guess is that:
> set to some candidateId when it received a RequestVote with a higher term
> set to None when it recevied a Appendre

What I would do would be to store the term + votedFor. This way when
you get a new RequestVote, you compare whether term is the same as the
one you have stored. If Yes, return votedFor. If no, it is considered
None.

henrik

--
henri...@avoinelama.fi
+358-40-5697354 skype: henrik.ingo irc: hingo
www.openlife.cc

My LinkedIn profile: http://fi.linkedin.com/pub/henrik-ingo/3/232/8a7

Hao Ren

unread,
Jul 29, 2017, 11:23:08 AM7/29/17
to raft-dev, henri...@avoinelama.fi
Thank you, Henrik
Trying message is a good point.
Reply all
Reply to author
Forward
0 new messages