dajac commented on code in PR #24327:
URL: https://github.com/apache/kafka/pull/24327#discussion_r4663613674


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorService.java:
##########
@@ -2436,12 +2436,11 @@ public CompletableFuture<TxnOffsetCommitResponseData> 
commitTransactionalOffsets
             request.producerEpoch(),
             coordinator -> coordinator.commitTransactionalOffset(context, 
request),
             context.requestVersion()
-        ).exceptionally(exception -> handleOperationException(
+        ).exceptionally(exception -> handleOffsetCommitException(

Review Comment:
   Should we also add `INVALID_COMMIT_OFFSET_SIZE (version 0+)` to the 
supported errors in `TxnOffsetCommitResponse.json`? `OffsetCommitResponse.json` 
and the `TxnOffsetCommitResponse` Javadoc already list it.



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorService.java:
##########
@@ -2745,6 +2744,39 @@ private OffsetFetchResponseData.OffsetFetchResponseGroup 
handleOffsetFetchExcept
         };
     }
 
+    /**
+     * This is the handler used by offset commit operations to convert errors 
to coordinator errors.
+     * The handler also handles and logs unexpected errors.
+     *
+     * @param operationName     The name of the operation.
+     * @param request           The request for logging purposes.
+     * @param exception         The exception to handle.
+     * @param handler           A function which takes an Errors and builds 
the response.
+     * @return The response built by the handler.
+     * @param <IN> The type of the request. It must be a toString'able object.
+     * @param <OUT> The type of the response.
+     */
+    private <IN, OUT> OUT handleOffsetCommitException(
+        String operationName,
+        IN request,
+        Throwable exception,
+        Function<Errors, OUT> handler
+    ) {
+        ApiError apiError = ApiError.fromThrowable(exception);
+
+        return switch (apiError.error()) {
+            case MESSAGE_TOO_LARGE, RECORD_LIST_TOO_LARGE ->
+                handler.apply(Errors.INVALID_COMMIT_OFFSET_SIZE);

Review Comment:
   nit: Could we say why these two errors are remapped, like in 
`handleOffsetFetchException`?
   ```suggestion
               case MESSAGE_TOO_LARGE, RECORD_LIST_TOO_LARGE ->
                   // Remap MESSAGE_TOO_LARGE and RECORD_LIST_TOO_LARGE to 
INVALID_COMMIT_OFFSET_SIZE,
                   // since the offsets of a commit are written in a single 
batch and these errors
                   // mean that the commit is too large.
                   handler.apply(Errors.INVALID_COMMIT_OFFSET_SIZE);
   ```



##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupCoordinatorServiceTest.java:
##########
@@ -3072,7 +3074,58 @@ public void testCommitTransactionalOffsets(short 
txnOffsetCommitVersion) throws
     @ParameterizedTest
     @CsvSource({
         "NOT_ENOUGH_REPLICAS, COORDINATOR_NOT_AVAILABLE",
-        "NETWORK_EXCEPTION, COORDINATOR_LOAD_IN_PROGRESS"
+        "NETWORK_EXCEPTION, COORDINATOR_LOAD_IN_PROGRESS",
+        "MESSAGE_TOO_LARGE, INVALID_COMMIT_OFFSET_SIZE",
+        "RECORD_LIST_TOO_LARGE, INVALID_COMMIT_OFFSET_SIZE"
+    })
+    public void testCommitOffsetsWithWrappedError(

Review Comment:
   Could we also add a test with a real oversize commit? For instance, a 
`ClusterTest` in `OffsetCommitRequestTest` and `TxnOffsetCommitRequestTest` 
with `message.max.bytes=1000` and a commit with 2000 bytes of metadata.



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