kevin-wu24 commented on code in PR #23168:
URL: https://github.com/apache/kafka/pull/23168#discussion_r4379411741
##########
raft/src/test/java/org/apache/kafka/raft/FollowerStateTest.java:
##########
@@ -122,6 +122,24 @@ public void
testPreVoteAfterSuccessfulFetchFromLeader(boolean isLogUpToDate) {
assertFalse(state.canGrantVote(ReplicaKey.of(10,
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, false));
}
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ public void testPreVoteAfterLeaderResigned(boolean isLogUpToDate) {
+ FollowerState state = newFollowerState(Set.of(1, 2, 3));
+ state.resetFetchTimeoutForSuccessfulFetch(time.milliseconds());
+ state.setHasLeaderResigned();
+
+ assertEquals(isLogUpToDate, state.canGrantVote(ReplicaKey.of(1,
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, true));
Review Comment:
```suggestion
assertEquals(
isLogUpToDate,
state.canGrantVote(ReplicaKey.of(1, ReplicaKey.NO_DIRECTORY_ID),
isLogUpToDate, true)
);
```
There is a convention in the `raft` module to keep lines under 100
characters in length. This applies to many places in this PR.
##########
raft/src/test/java/org/apache/kafka/raft/KafkaRaftClientPreVoteTest.java:
##########
@@ -670,6 +672,54 @@ public void
testFollowerGrantsPreVoteIfHasNotFetchedYet(KRaftVersion kraftVersio
assertTrue(context.client.quorum().isFollower());
}
+ @Test
+ public void testFollowerGrantsPreVoteAfterLeaderResigns() throws Exception
{
+ int localId = randomReplicaId();
+ ReplicaKey local = replicaKey(localId, true);
+ ReplicaKey leader = replicaKey(localId + 1, true);
+ ReplicaKey otherNodeKey = replicaKey(localId + 2, true);
+ int epoch = 2;
+
+ RaftClientTestContext context = new RaftClientTestContext.Builder(
+ local.id(),
+ local.directoryId().get()
+ )
+ .withStartingVoters(VoterSetTest.voterSet(Stream.of(local, leader,
otherNodeKey)), KRaftVersion.KRAFT_VERSION_0)
+ .withElectedLeader(epoch, leader.id())
+ .withRaftProtocol(RaftProtocol.KIP_1186_PROTOCOL)
+ .build();
+
+ context.assertElectedLeader(epoch, leader.id());
+
+ context.pollUntilRequest();
+ RaftRequest.Outbound fetchRequest = context.assertSentFetchRequest();
+ context.assertFetchRequestData(fetchRequest, epoch, 0L, 0,
context.client.highWatermark());
+ context.deliverResponse(
+ fetchRequest.correlationId(),
+ fetchRequest.destination(),
+ context.fetchResponse(epoch, leader.id(), MemoryRecords.EMPTY, 0L,
Errors.NONE)
+ );
+
+ // After fetching successfully from the leader, follower rejects
PreVotes even if the remote log is up to date
+ VoteRequestData preVote = context.preVoteRequest(epoch, otherNodeKey,
epoch, 1);
+ context.deliverRequest(preVote);
+ context.pollUntilResponse();
+ context.assertSentVoteResponse(Errors.NONE, epoch,
OptionalInt.of(leader.id()), false);
+ assertTrue(context.client.quorum().isFollower());
+
+ // Leader resigns by sending EndQuorumEpoch. This request can move the
node out of the follower state.
Review Comment:
```suggestion
// Leader resigns by sending EndQuorumEpoch. The local node is not
the top preferred
// successor and the clock doesn't advance, so it stays a follower
```
--
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]