Skip to content

Commit

Permalink
Allow election timer on restart_election_timer API (#82)
Browse files Browse the repository at this point in the history
* Election timer flag should be updated on election timer restart,
as the flag will not be effective anymore if timer is initiated.
  • Loading branch information
greensky00 authored Dec 8, 2019
1 parent da4a1aa commit 9eddae8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/libnuraft/raft_server.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public:

/**
* Start the election timer on this server, if this server is a follower.
* It will allow the election timer permanently, if it was disabled
* by state manager.
*/
void restart_election_timer();

Expand Down
6 changes: 6 additions & 0 deletions src/handle_timeout.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ void raft_server::restart_election_timer() {
return;
}

// If election timer was not allowed, clear the flag.
if (!state_->is_election_timer_allowed()) {
state_->allow_election_timer(true);
ctx_->state_mgr_->save_state(*state_);
}

if (election_task_) {
p_tr("cancel existing timer");
cancel_task(election_task_);
Expand Down
4 changes: 0 additions & 4 deletions src/raft_server.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -960,10 +960,6 @@ bool raft_server::update_term(ulong term) {
become_follower();
return true;
}
if (!state_->is_election_timer_allowed()) {
state_->allow_election_timer(true);
ctx_->state_mgr_->save_state(*state_);
}
return false;
}

Expand Down

0 comments on commit 9eddae8

Please sign in to comment.