ahuang98 commented on code in PR #20318:
URL: https://github.com/apache/kafka/pull/20318#discussion_r2376598490


##########
raft/src/main/java/org/apache/kafka/raft/LeaderState.java:
##########
@@ -188,6 +188,18 @@ public void resetBeginQuorumEpochTimer(long currentTimeMs) 
{
         beginQuorumEpochTimer.reset(beginQuorumEpochTimeoutMs);
     }
 
+    public Set<ReplicaKey> needToSendBeginQuorumRequests(long currentTimeMs) {

Review Comment:
   this could use a code comment to explain we don't need to send begin quorum 
requests to replicas which have fetched recently



##########
raft/src/main/java/org/apache/kafka/raft/LeaderState.java:
##########
@@ -188,6 +188,18 @@ public void resetBeginQuorumEpochTimer(long currentTimeMs) 
{
         beginQuorumEpochTimer.reset(beginQuorumEpochTimeoutMs);
     }
 
+    public Set<ReplicaKey> needToSendBeginQuorumRequests(long currentTimeMs) {
+        Set<ReplicaKey> replicaKeys = new HashSet<>();
+        beginQuorumEpochTimer.update(currentTimeMs);
+        for (ReplicaState state : voterStates.values()) {
+            if (beginQuorumEpochTimer.currentTimeMs() - 
state.lastFetchTimestamp >= beginQuorumEpochTimeoutMs

Review Comment:
   slight preference to use `currentTimeMs` so it's obvious we're using that 
same value



##########
raft/src/test/java/org/apache/kafka/raft/KafkaRaftClientTest.java:
##########
@@ -633,6 +634,47 @@ public void testBeginQuorumEpochHeartbeat(boolean 
withKip853Rpc) throws Exceptio
         context.assertSentBeginQuorumEpochRequest(epoch, Set.of(remoteId1, 
remoteId2));
     }
 
+    @Test
+    public void testBeginQuorumShouldNotSendAfterFetchRequest() throws 
Exception {

Review Comment:
   nit, let's test both variants (withKip853Rpc)



##########
raft/src/test/java/org/apache/kafka/raft/KafkaRaftClientTest.java:
##########
@@ -633,6 +634,47 @@ public void testBeginQuorumEpochHeartbeat(boolean 
withKip853Rpc) throws Exceptio
         context.assertSentBeginQuorumEpochRequest(epoch, Set.of(remoteId1, 
remoteId2));
     }
 
+    @Test
+    public void testBeginQuorumShouldNotSendAfterFetchRequest() throws 
Exception {
+        ReplicaKey localId = replicaKey(randomReplicaId(), true);
+        int remoteId1 = localId.id() + 1;
+        int remoteId2 = localId.id() + 2;
+        ReplicaKey replicaKey1 = replicaKey(remoteId1, true);
+        ReplicaKey replicaKey2 = replicaKey(remoteId2, true);
+
+        RaftClientTestContext context = new 
RaftClientTestContext.Builder(localId.id(), localId.directoryId().get())
+                .withRaftProtocol(KIP_853_PROTOCOL)
+                .withStartingVoters(VoterSetTest.voterSet(Stream.of(localId, 
replicaKey1, replicaKey2)), KRaftVersion.KRAFT_VERSION_1)
+                .build();
+
+        context.unattachedToLeader();
+        int epoch = context.currentEpoch();
+        assertEquals(OptionalInt.of(localId.id()), context.currentLeader());
+
+        // begin epoch requests should be sent out every 
beginQuorumEpochTimeoutMs

Review Comment:
   same comment modification here



##########
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java:
##########
@@ -1476,6 +1475,7 @@ private boolean hasValidClusterId(String 
requestClusterId) {
      * - {@link Errors#INVALID_REQUEST} if the request epoch is larger than 
the leader's current epoch
      *     or if either the fetch offset or the last fetched epoch is invalid
      */
+    @SuppressWarnings("CyclomaticComplexity")

Review Comment:
   do we need this? seems like you didn't add any changes to 
`handleFetchRequest`



##########
raft/src/test/java/org/apache/kafka/raft/KafkaRaftClientTest.java:
##########
@@ -633,6 +634,47 @@ public void testBeginQuorumEpochHeartbeat(boolean 
withKip853Rpc) throws Exceptio
         context.assertSentBeginQuorumEpochRequest(epoch, Set.of(remoteId1, 
remoteId2));
     }
 
+    @Test
+    public void testBeginQuorumShouldNotSendAfterFetchRequest() throws 
Exception {

Review Comment:
   let's also add/modify a code comment in `testBeginQuorumEpochHeartbeat` 
   
   ```
   // begin epoch requests should be sent out every beginQuorumEpochTimeoutMs
   ```
   ->
   ```
   // begin epoch requests sent out every beginQuorumEpochTimeoutMs if replicas 
have not fetched
   ```



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