lucasbru commented on code in PR #14710:
URL: https://github.com/apache/kafka/pull/14710#discussion_r1400862984


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/CommitRequestManager.java:
##########
@@ -202,6 +210,40 @@ public CompletableFuture<Void> 
maybeAutoCommitAllConsumed() {
         return maybeAutoCommit(subscriptions.allConsumed());
     }
 
+    /**
+     * The consumer needs to send an auto commit during the shutdown if 
autocommit is enabled.
+     */
+    Optional<NetworkClientDelegate.UnsentRequest> 
maybeCreateAutoCommitRequest() {
+        if (!autoCommitState.isPresent()) {
+            return Optional.empty();
+        }
+
+        OffsetCommitRequestState request = 
pendingRequests.createOffsetCommitRequest(subscriptions.allConsumed(), jitter);
+        
request.future.whenComplete(autoCommitCallback(subscriptions.allConsumed()));
+        return Optional.of(request.toUnsentRequest());
+    }
+
+    private CompletableFuture<Void> sendAutoCommit(final Map<TopicPartition, 
OffsetAndMetadata> allConsumedOffsets) {
+        log.debug("Enqueuing autocommit offsets: {}", allConsumedOffsets);
+        return 
addOffsetCommitRequest(allConsumedOffsets).whenComplete(autoCommitCallback(allConsumedOffsets));
+    }
+
+    private BiConsumer<? super Void, ? super Throwable> 
autoCommitCallback(final Map<TopicPartition, OffsetAndMetadata> 
allConsumedOffsets) {
+        return (response, throwable) -> {
+            autoCommitState.ifPresent(autoCommitState -> 
autoCommitState.setInflightCommitStatus(false));

Review Comment:
   Yeah, makes sense. We are just going to end up in a weird state here because 
we may have multiple autocommits in-flight, but when the first one returns we 
will set `inFlightCommitStatus` to false, although there are more in-flight. I 
can't point to anything that will break, but it seems a little off. 



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