kevin-wu24 commented on code in PR #23168:
URL: https://github.com/apache/kafka/pull/23168#discussion_r4349303050
##########
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:
Please use the most recent value for `RaftProtocol`. That contains pre-vote
too.
##########
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:
What is the motivation behind checking that the local node is a follower
repeatedly?
##########
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
Review Comment:
```suggestion
// Once the leader has resigned, the follower can now grant the same
PreVote that was previously rejected
```
##########
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 {
Review Comment:
We do not need to parametrize over the `kraftVersion`. That feature and
pre-vote are not related.
##########
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:
It might be good to store `context.preVoteRequest` in a variable. That way,
it is clear to the test reader that the same pre-vote request first gets
rejected, and then after the leader resigns, the same request now gets granted.
--
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]