Skip to content

Commit

Permalink
issue #200: update leader timeouts after disk write
Browse files Browse the repository at this point in the history
in cases where disk writes can take longer than the leader election,
a follower can call for an election when one is not necessary. this
change resets the election related timers after all disk writes.
  • Loading branch information
Nate Hardt committed Dec 7, 2015
1 parent e9e5c50 commit 1f6f597
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Server/RaftConsensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,10 @@ RaftConsensus::handleAppendEntries(
// 'response' accordingly.
response.set_term(request.term());
}
// This request is a sign of life from the current leader. Update our term
// and convert to follower if necessary; reset the election timer.
// This request is a sign of life from the current leader. Update
// our term and convert to follower if necessary; reset the
// election timer. set it here in case we exit early, we will set
// it again after the write
stepDown(request.term());
setElectionTimer();
withholdVotesUntil = Clock::now() + ELECTION_TIMEOUT;
Expand Down Expand Up @@ -1416,6 +1418,11 @@ RaftConsensus::handleAppendEntries(
stateChanged.notify_all();
VERBOSE("New commitIndex: %lu", commitIndex);
}

// reset election timer to avoid punishing the leader for our own
// long disk writes
setElectionTimer();
withholdVotesUntil = Clock::now() + ELECTION_TIMEOUT;
}

void
Expand Down

0 comments on commit 1f6f597

Please sign in to comment.