lianetm commented on code in PR #24181:
URL: https://github.com/apache/kafka/pull/24181#discussion_r4540899027
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/OffsetsRequestManager.java:
##########
@@ -473,14 +490,32 @@ private void refreshOffsets(final Map<TopicPartition,
OffsetAndMetadata> offsets
refreshCommittedOffsets(offsetsToApply, metadata,
subscriptionState);
- result.complete(null);
-
+ result.complete(true);
+
+ } else if (isMemberNotInGroupError(error)) {
+ // The member stopped being part of the group while the
OffsetFetch request was in flight (ex. fenced,
+ // left or failed). The partitions may be reassigned after the
member rejoins, so do not fall back to
+ // resetting positions, and do not fail the update. Positions will
be refreshed with the committed
+ // offsets on a following call to updateFetchPositions, if the
partitions are still assigned.
+ log.info("Skipping position initialization because the OffsetFetch
failed with {} (member no longer " +
+ "in the group). Positions will be initialized on a following
poll if the partitions are still " +
+ "assigned.", Errors.forException(error));
+ result.complete(false);
} else {
log.error("Error fetching committed offsets to update positions",
error);
result.completeExceptionally(error);
}
}
+ /**
+ * Check if the given error, received in response to an OffsetFetch
request, indicates that the member
+ * is no longer a valid member of the group (ex. it was fenced, left the
group or failed).
+ */
+ private static boolean isMemberNotInGroupError(Throwable error) {
Review Comment:
if the error is stale epoch is not accurate to say "isMemberNotInGroupError"
really. What about memberNeedsRejoin? or memberFencedOrLeft?
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/OffsetsRequestManager.java:
##########
@@ -413,16 +421,20 @@ private CompletableFuture<Void>
initWithPartitionOffsetsIfNeeded(Set<TopicPartit
* when resetting positions for partitions
that may not have committed offsets).
* @param deadlineMs Deadline of the application event that
triggered this operation. Used to
* determine how much time to allow for the
reused offset fetch to complete.
+ * @return Future that completes with true if the partitions that still
have no position should be reset
+ * using the configured offset reset strategy, or false if the fetch
failed because the member is no longer
Review Comment:
feels weird to have this `initWithCommittedOffsets` return something about
"shouldReset" which is not related to this func...would it be a better
separation of concerns (and easier to reason about) if we leave this func just
bubbling up the errors as it did, and then have the caller (the one that
decides to reset or not) decide if it should skip the reset based on the error?
Handle it at a higher level would also let us handle the "if
(memberLostAssignment" in a single place? (vs in 2 paths now, for a new request
and when reused)
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/OffsetsRequestManager.java:
##########
@@ -473,14 +490,32 @@ private void refreshOffsets(final Map<TopicPartition,
OffsetAndMetadata> offsets
refreshCommittedOffsets(offsetsToApply, metadata,
subscriptionState);
- result.complete(null);
-
+ result.complete(true);
+
+ } else if (isMemberNotInGroupError(error)) {
+ // The member stopped being part of the group while the
OffsetFetch request was in flight (ex. fenced,
+ // left or failed). The partitions may be reassigned after the
member rejoins, so do not fall back to
+ // resetting positions, and do not fail the update. Positions will
be refreshed with the committed
+ // offsets on a following call to updateFetchPositions, if the
partitions are still assigned.
+ log.info("Skipping position initialization because the OffsetFetch
failed with {} (member no longer " +
Review Comment:
I would remove the "skipping position initializtion because"...we did try
to, but couldn't.
The rest of your message is good already imo : OffsetFetch
failed...Positions will be initialized on a following poll...
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/OffsetsRequestManager.java:
##########
@@ -339,10 +344,13 @@ private CompletableFuture<Void>
updatePositionsWithOffsets(long deadlineMs) {
CompletableFuture<Void> updatePositions;
final Set<TopicPartition> initializingPartitions =
subscriptionState.initializingPartitions();
if (commitRequestManager != null) {
- CompletableFuture<Void> refreshWithCommittedOffsets =
initWithCommittedOffsetsIfNeeded(initializingPartitions, deadlineMs);
+ CompletableFuture<Boolean> refreshWithCommittedOffsets =
initWithCommittedOffsetsIfNeeded(initializingPartitions, deadlineMs);
- // Reset positions for all partitions that may still require it
(or that are awaiting reset)
- updatePositions = refreshWithCommittedOffsets.thenCompose(__ ->
initWithPartitionOffsetsIfNeeded(initializingPartitions));
+ // Reset positions for all partitions that may still require it
(or that are awaiting reset), unless
+ // the committed offsets could not be retrieved because the member
is no longer in the group
+ updatePositions =
refreshWithCommittedOffsets.thenCompose(shouldResetPositions ->
shouldResetPositions ?
+ initWithPartitionOffsetsIfNeeded(initializingPartitions) :
+ CompletableFuture.completedFuture(null));
Review Comment:
claude suggested this to address my [comment
above](https://github.com/apache/kafka/pull/24181/changes#r4541072001), wdyt?
```suggestion
updatePositions = refreshWithCommittedOffsets
.handle((__, error) -> {
if (error == null) {
// Reset positions for partitions still missing one (or awaiting
reset)
return initWithPartitionOffsetsIfNeeded(initializingPartitions);
}
if (memberLostAssignment(error)) {
// Leave partitions without positions (no reset); they're
fetched again if reassigned after rejoining
log.info("Skipping position initialization ...", ...);
return CompletableFuture.<Void>completedFuture(null);
}
return CompletableFuture.<Void>failedFuture(error);
})
.thenCompose(Function.identity());
```
--
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]