Skip to content

Commit

Permalink
Reset timer instead of start() when stepDown (sofastack#408)
Browse files Browse the repository at this point in the history
* Fix

* Refine

* address comment

* Fix
  • Loading branch information
jovany-wang authored Mar 27, 2020
1 parent 74684dc commit 6b66aa6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ private void stepDown(final long term, final boolean wakeupCandidate, final Stat
}
// Learner node will not trigger the election timer.
if (!isLearner()) {
this.electionTimer.start();
this.electionTimer.restart();
} else {
LOG.info("Node {} is a learner, election timer is not started.", this.nodeId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ public void start() {
}
}

/**
* Restart the timer.
* It will be started if it's stopped, and it will be restarted if it's running.
*
* @author Qing Wang ([email protected])
*
* 2020-Mar-26 20:38:37 PM
*/
public void restart() {
this.lock.lock();
try {
if (this.destroyed) {
return;
}
this.stopped = false;
this.running = true;
schedule();
} finally {
this.lock.unlock();
}
}

private void schedule() {
if (this.timeout != null) {
this.timeout.cancel();
Expand Down

0 comments on commit 6b66aa6

Please sign in to comment.