jsancio commented on code in PR #18240:
URL: https://github.com/apache/kafka/pull/18240#discussion_r1900951176
##########
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java:
##########
@@ -667,7 +668,8 @@ private boolean maybeTransitionToLeader(CandidateState
state, long currentTimeMs
}
private boolean maybeTransitionToCandidate(ProspectiveState state, long
currentTimeMs) {
- if (state.epochElection().isVoteGranted()) {
+ // If replica is the only voter, it should transition to candidate
immediately
+ if (state.epochElection().isVoteGranted() || quorum.isOnlyVoter()) {
Review Comment:
If the quorum has a size of one and since the replica votes for itself when
transitioning to prospective, `isVoteGranted()` should always return true. If
so, the replica doesn't need to check if it is the only voter.
Let's confirm we have a test for this in KafkaRaftClientTest. If not, let's
add a test.
Let's also confirm that we have a test for this in ProspectiveStateTest and
CandidateStateTest. If not, let's add tests for these cases.
##########
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java:
##########
@@ -550,9 +550,10 @@ public void initialize(
onBecomeFollower(currentTimeMs);
}
- // When there is only a single voter, become candidate immediately
- if (quorum.isOnlyVoter() && !quorum.isCandidate()) {
- transitionToCandidate(currentTimeMs);
+ // When there is only a single voter, become prospective immediately.
+ // transitionToProspective will handle short-circuiting voter to
candidate state
+ if (quorum.isOnlyVoter() && !quorum.isNomineeState() &&
!quorum.isLeader()) {
Review Comment:
Why do you check that is not leader? In KRaft a replica should never start
as a leader. KRaft throws and illegal state exception if it starts as leader.
See line 545 above.
```java
if (quorum.isLeader()) {
throw new IllegalStateException("Voter cannot initialize as a
Leader");
```
--
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]