GlenGeng commented on a change in pull request #161:
URL: https://github.com/apache/incubator-ratis/pull/161#discussion_r466128412
##########
File path:
ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
##########
@@ -221,10 +221,10 @@ boolean hasLeader() {
/**
* Become a candidate and start leader election
*/
- long initElection() {
+ long initElection(boolean preVote) {
Review comment:
If `preVote` is true, you will not change `currentTerm`, meanwhile
change `voteFor`, which may violate the raft algorithm that one can only vote
once in a specific term.
##########
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 roc.
----------------------------------------------------------------
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]