jsancio commented on code in PR #19668:
URL: https://github.com/apache/kafka/pull/19668#discussion_r2121679947


##########
raft/src/test/java/org/apache/kafka/raft/RequestManagerTest.java:
##########
@@ -408,24 +400,70 @@ public void testAnyInflightRequestWithAnyRequest() {
         );
 
         assertFalse(cache.hasAnyInflightRequest(time.milliseconds(), fetch));
+        assertFalse(cache.hasAnyInflightRequest(time.milliseconds(), 
fetchSnapshot));
 
         // Send a request and check state
-        cache.onRequestSent(otherNode, 11, time.milliseconds(), fetch);
+        cache.onRequestSent(otherNode, 11, time.milliseconds(), apiKey);
         assertTrue(cache.hasAnyInflightRequest(time.milliseconds(), fetch));
+        assertTrue(cache.hasAnyInflightRequest(time.milliseconds(), 
fetchSnapshot));
 
         // Wait until the request times out
         time.sleep(requestTimeoutMs);
         assertFalse(cache.hasAnyInflightRequest(time.milliseconds(), fetch));
+        assertFalse(cache.hasAnyInflightRequest(time.milliseconds(), 
fetchSnapshot));
 
         // Send another request and fail it
-        cache.onRequestSent(otherNode, 12, time.milliseconds(), fetch);
-        cache.onResponseResult(otherNode, 12, false, time.milliseconds(), 
fetch);
+        cache.onRequestSent(otherNode, 12, time.milliseconds(), apiKey);
+        cache.onResponseResult(otherNode, 12, false, time.milliseconds(), 
apiKey);
         assertFalse(cache.hasAnyInflightRequest(time.milliseconds(), fetch));
+        assertFalse(cache.hasAnyInflightRequest(time.milliseconds(), 
fetchSnapshot));
 
         // Send another request and mark it successful
-        cache.onRequestSent(otherNode, 12, time.milliseconds(), fetch);
-        cache.onResponseResult(otherNode, 12, true, time.milliseconds(), 
fetch);
+        cache.onRequestSent(otherNode, 12, time.milliseconds(), apiKey);
+        cache.onResponseResult(otherNode, 12, true, time.milliseconds(), 
apiKey);
         assertFalse(cache.hasAnyInflightRequest(time.milliseconds(), fetch));
+        assertFalse(cache.hasAnyInflightRequest(time.milliseconds(), 
fetchSnapshot));
+    }
+
+    @ParameterizedTest
+    @EnumSource(
+        value = ApiKeys.class,
+        names = {
+            "VOTE",
+            "BEGIN_QUORUM_EPOCH",
+            "END_QUORUM_EPOCH",
+            "API_VERSIONS",
+            "UPDATE_RAFT_VOTER"

Review Comment:
   How about adding ADD_RAFT_VOTER and REMOVE_RAFT_VOTER?



##########
raft/src/main/java/org/apache/kafka/raft/internals/RequestType.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.raft.internals;
+
+import org.apache.kafka.common.protocol.ApiKeys;
+
+/**
+ * This class is used to wrap the ApiKeys enum for KRaft RPCs so the KRaft 
request
+ * manager can treat the FETCH and FETCH_SNAPSHOT requests as the same type 
when
+ * managing in-flight requests. This is useful for satisfying the invariant
+ * that at most one FETCH or FETCH_SNAPSHOT request is pending at any time.
+ */
+public class RequestType {
+    public static final RequestType FETCH_AND_FETCH_SNAPSHOT = new 
RequestType(ApiKeys.FETCH);
+    private final ApiKeys apiKey;
+
+    private RequestType(ApiKeys apiKey) {
+        this.apiKey = apiKey;
+    }
+
+    public static RequestType of(ApiKeys apiKey) {
+        if (apiKey == ApiKeys.FETCH_SNAPSHOT) {
+            return FETCH_AND_FETCH_SNAPSHOT;
+        }
+        return new RequestType(apiKey);
+    }
+
+    public ApiKeys apiKey() {
+        return apiKey;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof RequestType)) {
+            return false;
+        }
+        RequestType other = (RequestType) obj;
+        return apiKey == other.apiKey;
+    }
+
+    @Override
+    public int hashCode() {
+        return apiKey.hashCode();
+    }

Review Comment:
   Let's also override the `toString` implementation something like 
`RequestType(apiKey=XXX)`.



##########
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java:
##########
@@ -2805,39 +2811,45 @@ private RequestSendResult maybeSendRequest(
                 messageQueue.add(response);
             });
 
-            requestManager.onRequestSent(destination, correlationId, 
currentTimeMs);
+            requestManager.onRequestSent(destination, correlationId, 
currentTimeMs, apiKey);
             channel.send(requestMessage);
             requestSent = true;
             logger.trace("Sent outbound request: {}", requestMessage);
         }
 
         return RequestSendResult.of(
             requestSent,
-            requestManager.remainingRequestTimeMs(destination, currentTimeMs)
+            requestManager.remainingRequestTimeMs(destination, currentTimeMs, 
apiKey)
         );
     }
 
-    private EndQuorumEpochRequestData buildEndQuorumEpochRequest(
+    private RequestSupplier buildEndQuorumEpochRequest(

Review Comment:
   Let's rename these methods since we changed the returned type. How about 
`endQuorumEpochRequestSupplier(...)`?



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to