OneSizeFitsQuorum commented on code in PR #1327:
URL: https://github.com/apache/ratis/pull/1327#discussion_r2616623004


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java:
##########
@@ -306,23 +306,30 @@ public String toString() {
   private final boolean skipPreVote;
   private final ConfAndTerm round0;
 
-  LeaderElection(RaftServerImpl server, boolean force) {
-    this(ServerInterface.get(server), force);
+  static LeaderElection newInstance(RaftServerImpl server, boolean force) {
+    return newInstance(ServerInterface.get(server), force);
   }
 
-  LeaderElection(ServerInterface server, boolean force) {
+  static LeaderElection newInstance(ServerInterface server, boolean force) {
+    try {
+      // increase term of the candidate in advance if it's forced to election
+      final ConfAndTerm round0 = force ? server.initElection(Phase.ELECTION) : 
null;
+      return new LeaderElection(server, force, round0);
+    } catch (IOException e) {
+      throw new 
IllegalStateException(ServerStringUtils.generateUnifiedName(server.getMemberId(),
+              LeaderElection.class) + ": Failed to initialize election", e);
+    }
+  }
+
+
+  private LeaderElection(ServerInterface server, boolean force, ConfAndTerm 
round0) {
     this.name = ServerStringUtils.generateUnifiedName(server.getMemberId(), 
getClass()) + COUNT.incrementAndGet();

Review Comment:
   Good idea!



##########
ratis-server/dev-support/findbugsExcludeFile.xml:
##########


Review Comment:
   Fixed!



-- 
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