GlenGeng commented on a change in pull request #161:
URL: https://github.com/apache/incubator-ratis/pull/161#discussion_r466130097



##########
File path: 
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java
##########
@@ -188,89 +197,104 @@ private boolean shouldRun(long electionTerm) {
     return shouldRun() && server.getState().getCurrentTerm() == electionTerm;
   }
 
+  private ResultAndTerm submitRequestAndWaitResult(
+      final ServerState state, final RaftConfiguration conf, final long 
electionTerm, boolean preVote)
+      throws InterruptedException {
+    final ResultAndTerm r;
+    final Collection<RaftPeer> others = conf.getOtherPeers(server.getId());
+    if (others.isEmpty()) {
+      r = new ResultAndTerm(Result.PASSED, electionTerm);
+    } else {
+      TermIndex lastEntry = state.getLastEntry();
+      final Executor voteExecutor = new Executor(this, others.size());
+      try {
+        final int submitted = submitRequests(electionTerm, lastEntry, others, 
voteExecutor, preVote);
+        r = waitForResults(electionTerm, submitted, conf, voteExecutor, 
preVote);
+      } finally {
+        voteExecutor.shutdown();
+      }
+    }
+
+    return r;
+  }
+
   /**
    * After a peer changes its role to candidate, it invokes this method to
    * send out requestVote rpc to all other peers.
    */
-  private void askForVotes() throws InterruptedException, IOException {
+  private boolean askForVotes(boolean preVote) throws InterruptedException, 
IOException {

Review comment:
       `While (shouldRu())` may be omitted for preVote case, since it just need 
one round rpc.




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

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


Reply via email to