junrao commented on code in PR #22989:
URL: https://github.com/apache/kafka/pull/22989#discussion_r3848164020


##########
clients/src/main/java/org/apache/kafka/common/requests/Kip219ClientThrottleVersion.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.common.requests;
+
+import org.apache.kafka.common.protocol.ApiKeys;
+
+import java.util.Map;
+
+final class Kip219ClientThrottleVersion {
+
+    // These values represent immutable historical version boundaries for 
KIP-219 client-side throttling.

Review Comment:
   It would be useful to document that these are the first version after 
KIP-219 was introduced. 



##########
clients/src/test/java/org/apache/kafka/common/requests/RequestResponseTest.java:
##########
@@ -366,57 +360,24 @@ public void testSerialization() {
     }
 
     @Test
-    public void testClientThrottlesResponsesWithThrottleTime() {
-        Map<ApiKeys, Short> postKip219Version = Map.ofEntries(
-            Map.entry(ApiKeys.PRODUCE, (short) 6),
-            Map.entry(ApiKeys.FETCH, (short) 8),
-            Map.entry(ApiKeys.LIST_OFFSETS, (short) 3),
-            Map.entry(ApiKeys.METADATA, (short) 6),
-            Map.entry(ApiKeys.OFFSET_COMMIT, (short) 4),
-            Map.entry(ApiKeys.OFFSET_FETCH, (short) 4),
-            Map.entry(ApiKeys.FIND_COORDINATOR, (short) 2),
-            Map.entry(ApiKeys.JOIN_GROUP, (short) 3),
-            Map.entry(ApiKeys.HEARTBEAT, (short) 2),
-            Map.entry(ApiKeys.LEAVE_GROUP, (short) 2),
-            Map.entry(ApiKeys.SYNC_GROUP, (short) 2),
-            Map.entry(ApiKeys.DESCRIBE_GROUPS, (short) 2),
-            Map.entry(ApiKeys.LIST_GROUPS, (short) 2),
-            Map.entry(ApiKeys.API_VERSIONS, (short) 2),
-            Map.entry(ApiKeys.CREATE_TOPICS, (short) 3),
-            Map.entry(ApiKeys.DELETE_TOPICS, (short) 2),
-            Map.entry(ApiKeys.DELETE_RECORDS, (short) 1),
-            Map.entry(ApiKeys.INIT_PRODUCER_ID, (short) 1),
-            Map.entry(ApiKeys.ADD_PARTITIONS_TO_TXN, (short) 1),
-            Map.entry(ApiKeys.ADD_OFFSETS_TO_TXN, (short) 1),
-            Map.entry(ApiKeys.END_TXN, (short) 1),
-            Map.entry(ApiKeys.TXN_OFFSET_COMMIT, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_ACLS, (short) 1),
-            Map.entry(ApiKeys.CREATE_ACLS, (short) 1),
-            Map.entry(ApiKeys.DELETE_ACLS, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_CONFIGS, (short) 2),
-            Map.entry(ApiKeys.ALTER_CONFIGS, (short) 1),
-            Map.entry(ApiKeys.ALTER_REPLICA_LOG_DIRS, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_LOG_DIRS, (short) 1),
-            Map.entry(ApiKeys.CREATE_PARTITIONS, (short) 1),
-            Map.entry(ApiKeys.CREATE_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.RENEW_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.EXPIRE_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.DELETE_GROUPS, (short) 1)
-        );
+    public void testKip219BoundariesHaveThrottleTimeField() {
+        Kip219ClientThrottleVersion.BOUNDARIES.forEach((apiKey, boundary) ->
+            
assertNotNull(apiKey.messageType.responseSchemas()[boundary].get("throttle_time_ms"),
+                apiKey + " KIP-219 boundary " + boundary +
+                    " precedes the version that added throttle_time_ms"));
+    }
 
-        for (ApiKeys apiKey : ApiKeys.values()) {
-            for (short version : apiKey.allVersions()) {
-                boolean responseHasThrottleTime =
-                    
apiKey.messageType.responseSchemas()[version].get("throttle_time_ms") != null;
-                short firstPostKip219Version = 
postKip219Version.getOrDefault(apiKey, apiKey.oldestVersion());
-                boolean shouldClientThrottle = responseHasThrottleTime &&
-                    version >= firstPostKip219Version;
-                assertEquals(shouldClientThrottle, getResponse(apiKey, 
version).shouldClientThrottle(version),
-                    "Unexpected shouldClientThrottle result for " + apiKey + " 
version " + version +
-                        ": responseHasThrottleTime=" + responseHasThrottleTime 
+
-                        ", firstPostKip219Version=" + firstPostKip219Version);
-            }
+    @Test
+    public void testClientThrottleBoundariesForCommonResponses() {

Review Comment:
   testClientThrottleBoundariesForCommonResponses => 
testClientThrottleForCommonResponses ?



##########
clients/src/test/java/org/apache/kafka/common/requests/RequestResponseTest.java:
##########
@@ -366,57 +360,24 @@ public void testSerialization() {
     }
 
     @Test
-    public void testClientThrottlesResponsesWithThrottleTime() {
-        Map<ApiKeys, Short> postKip219Version = Map.ofEntries(
-            Map.entry(ApiKeys.PRODUCE, (short) 6),
-            Map.entry(ApiKeys.FETCH, (short) 8),
-            Map.entry(ApiKeys.LIST_OFFSETS, (short) 3),
-            Map.entry(ApiKeys.METADATA, (short) 6),
-            Map.entry(ApiKeys.OFFSET_COMMIT, (short) 4),
-            Map.entry(ApiKeys.OFFSET_FETCH, (short) 4),
-            Map.entry(ApiKeys.FIND_COORDINATOR, (short) 2),
-            Map.entry(ApiKeys.JOIN_GROUP, (short) 3),
-            Map.entry(ApiKeys.HEARTBEAT, (short) 2),
-            Map.entry(ApiKeys.LEAVE_GROUP, (short) 2),
-            Map.entry(ApiKeys.SYNC_GROUP, (short) 2),
-            Map.entry(ApiKeys.DESCRIBE_GROUPS, (short) 2),
-            Map.entry(ApiKeys.LIST_GROUPS, (short) 2),
-            Map.entry(ApiKeys.API_VERSIONS, (short) 2),
-            Map.entry(ApiKeys.CREATE_TOPICS, (short) 3),
-            Map.entry(ApiKeys.DELETE_TOPICS, (short) 2),
-            Map.entry(ApiKeys.DELETE_RECORDS, (short) 1),
-            Map.entry(ApiKeys.INIT_PRODUCER_ID, (short) 1),
-            Map.entry(ApiKeys.ADD_PARTITIONS_TO_TXN, (short) 1),
-            Map.entry(ApiKeys.ADD_OFFSETS_TO_TXN, (short) 1),
-            Map.entry(ApiKeys.END_TXN, (short) 1),
-            Map.entry(ApiKeys.TXN_OFFSET_COMMIT, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_ACLS, (short) 1),
-            Map.entry(ApiKeys.CREATE_ACLS, (short) 1),
-            Map.entry(ApiKeys.DELETE_ACLS, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_CONFIGS, (short) 2),
-            Map.entry(ApiKeys.ALTER_CONFIGS, (short) 1),
-            Map.entry(ApiKeys.ALTER_REPLICA_LOG_DIRS, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_LOG_DIRS, (short) 1),
-            Map.entry(ApiKeys.CREATE_PARTITIONS, (short) 1),
-            Map.entry(ApiKeys.CREATE_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.RENEW_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.EXPIRE_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.DELETE_GROUPS, (short) 1)
-        );
+    public void testKip219BoundariesHaveThrottleTimeField() {
+        Kip219ClientThrottleVersion.BOUNDARIES.forEach((apiKey, boundary) ->
+            
assertNotNull(apiKey.messageType.responseSchemas()[boundary].get("throttle_time_ms"),

Review Comment:
   Should we call getResponse() here?



##########
clients/src/test/java/org/apache/kafka/common/requests/RequestResponseTest.java:
##########
@@ -366,57 +360,24 @@ public void testSerialization() {
     }
 
     @Test
-    public void testClientThrottlesResponsesWithThrottleTime() {
-        Map<ApiKeys, Short> postKip219Version = Map.ofEntries(
-            Map.entry(ApiKeys.PRODUCE, (short) 6),
-            Map.entry(ApiKeys.FETCH, (short) 8),
-            Map.entry(ApiKeys.LIST_OFFSETS, (short) 3),
-            Map.entry(ApiKeys.METADATA, (short) 6),
-            Map.entry(ApiKeys.OFFSET_COMMIT, (short) 4),
-            Map.entry(ApiKeys.OFFSET_FETCH, (short) 4),
-            Map.entry(ApiKeys.FIND_COORDINATOR, (short) 2),
-            Map.entry(ApiKeys.JOIN_GROUP, (short) 3),
-            Map.entry(ApiKeys.HEARTBEAT, (short) 2),
-            Map.entry(ApiKeys.LEAVE_GROUP, (short) 2),
-            Map.entry(ApiKeys.SYNC_GROUP, (short) 2),
-            Map.entry(ApiKeys.DESCRIBE_GROUPS, (short) 2),
-            Map.entry(ApiKeys.LIST_GROUPS, (short) 2),
-            Map.entry(ApiKeys.API_VERSIONS, (short) 2),
-            Map.entry(ApiKeys.CREATE_TOPICS, (short) 3),
-            Map.entry(ApiKeys.DELETE_TOPICS, (short) 2),
-            Map.entry(ApiKeys.DELETE_RECORDS, (short) 1),
-            Map.entry(ApiKeys.INIT_PRODUCER_ID, (short) 1),
-            Map.entry(ApiKeys.ADD_PARTITIONS_TO_TXN, (short) 1),
-            Map.entry(ApiKeys.ADD_OFFSETS_TO_TXN, (short) 1),
-            Map.entry(ApiKeys.END_TXN, (short) 1),
-            Map.entry(ApiKeys.TXN_OFFSET_COMMIT, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_ACLS, (short) 1),
-            Map.entry(ApiKeys.CREATE_ACLS, (short) 1),
-            Map.entry(ApiKeys.DELETE_ACLS, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_CONFIGS, (short) 2),
-            Map.entry(ApiKeys.ALTER_CONFIGS, (short) 1),
-            Map.entry(ApiKeys.ALTER_REPLICA_LOG_DIRS, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_LOG_DIRS, (short) 1),
-            Map.entry(ApiKeys.CREATE_PARTITIONS, (short) 1),
-            Map.entry(ApiKeys.CREATE_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.RENEW_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.EXPIRE_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.DESCRIBE_DELEGATION_TOKEN, (short) 1),
-            Map.entry(ApiKeys.DELETE_GROUPS, (short) 1)
-        );
+    public void testKip219BoundariesHaveThrottleTimeField() {
+        Kip219ClientThrottleVersion.BOUNDARIES.forEach((apiKey, boundary) ->
+            
assertNotNull(apiKey.messageType.responseSchemas()[boundary].get("throttle_time_ms"),
+                apiKey + " KIP-219 boundary " + boundary +
+                    " precedes the version that added throttle_time_ms"));
+    }
 
-        for (ApiKeys apiKey : ApiKeys.values()) {
-            for (short version : apiKey.allVersions()) {
-                boolean responseHasThrottleTime =
-                    
apiKey.messageType.responseSchemas()[version].get("throttle_time_ms") != null;
-                short firstPostKip219Version = 
postKip219Version.getOrDefault(apiKey, apiKey.oldestVersion());
-                boolean shouldClientThrottle = responseHasThrottleTime &&
-                    version >= firstPostKip219Version;
-                assertEquals(shouldClientThrottle, getResponse(apiKey, 
version).shouldClientThrottle(version),
-                    "Unexpected shouldClientThrottle result for " + apiKey + " 
version " + version +
-                        ": responseHasThrottleTime=" + responseHasThrottleTime 
+
-                        ", firstPostKip219Version=" + firstPostKip219Version);
-            }
+    @Test
+    public void testClientThrottleBoundariesForCommonResponses() {
+        assertClientThrottleBoundary(PRODUCE, (short) 6);
+        assertClientThrottleBoundary(FETCH, (short) 8);
+        assertClientThrottleBoundary(METADATA, (short) 6);
+    }
+
+    private void assertClientThrottleBoundary(ApiKeys apiKey, short boundary) {

Review Comment:
   assertClientThrottleBoundary => assertClientThrottle?
   boundary => boundaryVersion ?



##########
clients/src/main/java/org/apache/kafka/common/requests/Kip219ClientThrottleVersion.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.common.requests;
+
+import org.apache.kafka.common.protocol.ApiKeys;
+
+import java.util.Map;
+
+final class Kip219ClientThrottleVersion {
+
+    // These values represent immutable historical version boundaries for 
KIP-219 client-side throttling.
+    // They do not change when older API versions are deprecated.

Review Comment:
   If we deprecate say produce request up to version 6 in the future, should we 
still leave it here?



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