Skip to content

Commit

Permalink
fix RequestVote bug. the leader will not become follower when network…
Browse files Browse the repository at this point in the history
… partition, and the candidate's log is smaller than leader but the candidate has larger term
  • Loading branch information
baotiao committed Aug 29, 2017
1 parent 01b71a6 commit ed66972
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 119 deletions.
7 changes: 7 additions & 0 deletions floyd/src/floyd_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,13 @@ void FloydImpl::ReplyRequestVote(const CmdRequest& request, CmdResponse* respons
CmdRequest_RequestVote request_vote = request.request_vote();
LOGV(DEBUG_LEVEL, info_log_, "FloydImpl::ReplyRequestVote: my_term=%lu request.term=%lu",
context_->current_term, request_vote.term());
/*
* If RPC request or response contains term T > currentTerm: set currentTerm = T, convert to follower (§5.1)
*/
if (request_vote.term() > context_->current_term) {
context_->BecomeFollower(request_vote.term());
raft_meta_->SetCurrentTerm(context_->current_term);
}
// if caller's term smaller than my term, then I will notice him
if (request_vote.term() < context_->current_term) {
LOGV(INFO_LEVEL, info_log_, "FloydImpl::ReplyRequestVote: Leader %s:%d term %lu is smaller than my %s:%d current term %lu",
Expand Down
12 changes: 0 additions & 12 deletions floyd/test/start_all.sh

This file was deleted.

7 changes: 0 additions & 7 deletions floyd/test/stop_all.sh

This file was deleted.

56 changes: 0 additions & 56 deletions floyd/test/test0.sh

This file was deleted.

44 changes: 0 additions & 44 deletions floyd/test/test1.sh

This file was deleted.

0 comments on commit ed66972

Please sign in to comment.