kaijchen commented on code in PR #844:
URL: https://github.com/apache/ratis/pull/844#discussion_r1130329308


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java:
##########
@@ -186,16 +186,23 @@ public String toString() {
 
   private final RaftServerImpl server;
   private final boolean skipPreVote;
+  private final ConfAndTerm round0;
 
-  LeaderElection(RaftServerImpl server, boolean skipPreVote) {
+  LeaderElection(RaftServerImpl server, boolean force) {
     this.name = server.getMemberId() + "-" + 
JavaUtils.getClassSimpleName(getClass()) + COUNT.incrementAndGet();
     this.lifeCycle = new LifeCycle(this);
     this.daemon = Daemon.newBuilder().setName(name).setRunnable(this)
         .setThreadGroup(server.getThreadGroup()).build();
     this.server = server;
-    this.skipPreVote = skipPreVote ||
+    this.skipPreVote = force ||
         !RaftServerConfigKeys.LeaderElection.preVote(
             server.getRaftServer().getProperties());
+    try {
+      // increase term of the candidate early if it's forced to election
+      this.round0 = force ? server.getState().initElection(Phase.ELECTION) : 
null;

Review Comment:
   Check `force` instead of `this.skipPreVote` here, so it reflects the 
caller's intention and won't be affected by configKeys.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to