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


##########
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:
   Perhaps you meant by this: `maybeCreateAutoCommitRequest`
   
   Debatable. Since we aren't sure what offset the previous autocommit was 
sending (if there is an inflight one) during the shutdown, we want to send an 
autocommit regardless.
   
   In fact, now makes me think, we might not need to check if there is an 
inflight autocommit at all, as we always want to make sure committing an offset 
on the clock.  I'll file a jira for investigation.  Thanks!



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