You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "unknowntpo (via GitHub)" <gi...@apache.org> on 2026/09/02 08:04:58 UTC
Re: [PR] KAFKA-20166: Ensure consumer with auto-commit enabled commits offsets before switching partitions [kafka]
unknowntpo commented on code in PR #21584:
URL: https://github.com/apache/kafka/pull/21584#discussion_r3912015282
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/CommitRequestManager.java:
##########
@@ -276,15 +276,29 @@ private CompletableFuture<Map<TopicPartition, OffsetAndMetadata>> requestAutoCom
*/
private void maybeAutoCommitAsync() {
if (autoCommitEnabled() && autoCommitState.get().shouldAutoCommit()) {
- OffsetCommitRequestState requestState = createOffsetCommitRequest(
- subscriptions.allConsumed(),
- Long.MAX_VALUE);
- CompletableFuture<Map<TopicPartition, OffsetAndMetadata>> result = requestAutoCommit(requestState);
- // Reset timer to the interval (even if no request was generated), but ensure that if
- // the request completes with a retriable error, the timer is reset to send the next
- // auto-commit after the backoff expires.
- resetAutoCommitTimer();
- maybeResetTimerWithBackoff(result);
+ doAutoCommitAsync();
+ }
+ }
+
+ private void doAutoCommitAsync() {
+ OffsetCommitRequestState requestState = createOffsetCommitRequest(
+ subscriptions.allConsumed(),
+ Long.MAX_VALUE);
+ CompletableFuture<Map<TopicPartition, OffsetAndMetadata>> result = requestAutoCommit(requestState);
+ // Reset timer to the interval (even if no request was generated), but ensure that if
+ // the request completes with a retriable error, the timer is reset to send the next
+ // auto-commit after the backoff expires.
+ resetAutoCommitTimer();
+ maybeResetTimerWithBackoff(result);
+ }
+
+ /**
+ * Trigger a best-effort async auto-commit when assign() is called with new partitions.
+ * Fires once without blocking; the caller does not wait for the result.
+ */
+ public void maybeAutoCommitOnAssignment() {
+ if (autoCommitEnabled()) {
Review Comment:
Your right, I should respect the flag, I've changed the flag to the counter to represent multiple inflight auto commits.
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ConsumerCoordinator.java:
##########
@@ -1182,7 +1182,7 @@ public boolean commitOffsetsSync(Map<TopicPartition, OffsetAndMetadata> offsets,
return false;
}
- private void maybeAutoCommitOffsetsSync(Timer timer) {
+ public void maybeAutoCommitOffsetsSync(Timer timer) {
Review Comment:
fixed.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org