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


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java:
##########
@@ -306,23 +306,32 @@ 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) {
-    this.name = ServerStringUtils.generateUnifiedName(server.getMemberId(), 
getClass()) + COUNT.incrementAndGet();
+  static LeaderElection newInstance(ServerInterface server, boolean force) {
+      String name = "";
+      try {
+        // increase term of the candidate in advance if it's forced to election
+        final ConfAndTerm round0 = force ? server.initElection(Phase.ELECTION) 
: null;
+        name = ServerStringUtils.generateUnifiedName(server.getMemberId(), 
LeaderElection.class)
+              + COUNT.incrementAndGet();

Review Comment:
   - `name` should be set before `initElection`, otherwise it will still be 
`""` in `catch`.  I think it can be set even before `try`.
   - nit: indentation should be less by 2 spaces



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