sumanpal97 commented on code in PR #23168:
URL: https://github.com/apache/kafka/pull/23168#discussion_r4367579415


##########
raft/src/test/java/org/apache/kafka/raft/KafkaRaftClientPreVoteTest.java:
##########
@@ -670,6 +670,54 @@ public void 
testFollowerGrantsPreVoteIfHasNotFetchedYet(KRaftVersion kraftVersio
         assertTrue(context.client.quorum().isFollower());
     }
 
+    @ParameterizedTest
+    @EnumSource(value = KRaftVersion.class)
+    public void testFollowerGrantsPreVoteAfterLeaderResigns(KRaftVersion 
kraftVersion) 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)
+            .withElectedLeader(epoch, leader.id())
+            .withRaftProtocol(KIP_996_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
+        context.deliverRequest(context.preVoteRequest(epoch, otherNodeKey, 
epoch, 1));
+        context.pollUntilResponse();
+        context.assertSentVoteResponse(Errors.NONE, epoch, 
OptionalInt.of(leader.id()), false);
+        assertTrue(context.client.quorum().isFollower());
+
+        // Leader resigns by sending EndQuorumEpoch
+        context.deliverRequest(context.endEpochRequest(epoch, leader.id(), 
List.of(otherNodeKey, local)));
+        context.pollUntilResponse();
+        context.assertSentEndQuorumEpochResponse(Errors.NONE, epoch, 
OptionalInt.of(leader.id()));
+        assertTrue(context.client.quorum().isFollower());
+
+        // Once the leader has resigned, follower grants PreVotes again
+        context.deliverRequest(context.preVoteRequest(epoch, otherNodeKey, 
epoch, 1));
+        context.pollUntilResponse();
+        context.assertSentVoteResponse(Errors.NONE, epoch, 
OptionalInt.of(leader.id()), true);
+        assertTrue(context.client.quorum().isFollower());

Review Comment:
   A PreVote response does not change the node's role, so those checks were 
unnecessary. I kept only the check after EndQuorumEpoch, because that request 
can move the node out of the follower state.



##########
raft/src/test/java/org/apache/kafka/raft/KafkaRaftClientPreVoteTest.java:
##########
@@ -670,6 +670,54 @@ public void 
testFollowerGrantsPreVoteIfHasNotFetchedYet(KRaftVersion kraftVersio
         assertTrue(context.client.quorum().isFollower());
     }
 
+    @ParameterizedTest
+    @EnumSource(value = KRaftVersion.class)
+    public void testFollowerGrantsPreVoteAfterLeaderResigns(KRaftVersion 
kraftVersion) 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)
+            .withElectedLeader(epoch, leader.id())
+            .withRaftProtocol(KIP_996_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
+        context.deliverRequest(context.preVoteRequest(epoch, otherNodeKey, 
epoch, 1));

Review Comment:
   Agree. Stored the PreVote request and reused it, so the rejected and granted 
requests are the same object.



##########
raft/src/test/java/org/apache/kafka/raft/KafkaRaftClientPreVoteTest.java:
##########
@@ -670,6 +670,54 @@ public void 
testFollowerGrantsPreVoteIfHasNotFetchedYet(KRaftVersion kraftVersio
         assertTrue(context.client.quorum().isFollower());
     }
 
+    @ParameterizedTest
+    @EnumSource(value = KRaftVersion.class)
+    public void testFollowerGrantsPreVoteAfterLeaderResigns(KRaftVersion 
kraftVersion) 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)
+            .withElectedLeader(epoch, leader.id())
+            .withRaftProtocol(KIP_996_PROTOCOL)

Review Comment:
   Switched the test to KIP_1186_PROTOCOL, the latest protocol, which still 
includes pre-vote.



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

Reply via email to