szetszwo commented on code in PR #844:
URL: https://github.com/apache/ratis/pull/844#discussion_r1130258477
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java:
##########
@@ -196,6 +196,13 @@ public String toString() {
this.skipPreVote = skipPreVote ||
!RaftServerConfigKeys.LeaderElection.preVote(
server.getRaftServer().getProperties());
+ if (this.skipPreVote) {
+ try {
+ server.getState().initElection(Phase.ELECTION);
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to initialize election", e);
Review Comment:
Let's include the name
```java
throw new IllegalStateException(name + ": Failed to initElection", e);
```
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java:
##########
@@ -301,7 +308,10 @@ private boolean askForVotes(Phase phase) throws
InterruptedException, IOExceptio
if (!shouldRun()) {
return false;
}
- final ConfAndTerm confAndTerm = server.getState().initElection(phase);
+ // If skipPreVote=true, we have already called initElection in the
constructor,
+ // call initElection(Phase.PRE_VOTE) to skip term increment for the
first round
+ final Phase filteredPhase = (skipPreVote && round == 0) ?
Phase.PRE_VOTE : phase;
+ final ConfAndTerm confAndTerm =
server.getState().initElection(filteredPhase);
Review Comment:
Then use `round0` here
```java
final ConfAndTerm confAndTerm = round == 0 && round0 != null?
round0 : server.getState().initElection(phase);
```
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java:
##########
@@ -196,6 +196,13 @@ public String toString() {
this.skipPreVote = skipPreVote ||
!RaftServerConfigKeys.LeaderElection.preVote(
server.getRaftServer().getProperties());
+ if (this.skipPreVote) {
+ try {
+ server.getState().initElection(Phase.ELECTION);
Review Comment:
Let's store the returned `ConfAndTerm`.
```java
this.round0 = skipPreVote?
server.getState().initElection(Phase.ELECTION): null;
```
--
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]