squah-confluent commented on code in PR #23688:
URL: https://github.com/apache/kafka/pull/23688#discussion_r4508072394


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java:
##########
@@ -4421,11 +4527,81 @@ private UpdateTargetAssignmentResult<Assignment> 
maybeUpdateTargetAssignment(
             } else {
                 return new UpdateTargetAssignmentResult<>(groupEpoch, 
Assignment.EMPTY);
             }
-        } catch (PartitionAssignorException ex) {
-            String msg = String.format("Failed to compute a new target 
assignment for epoch %d: %s",
-                groupEpoch, ex.getMessage());
-            log.error("[GroupId {}] {}.", group.groupId(), msg, ex);
-            throw new UnknownServerException(msg, ex);
+        }
+    }
+
+    /**
+     * Handle the result of the asynchronous task that computes a consumer 
group's
+     * target assignment when assignor offloading is enabled.
+     *
+     * @param groupId                The group id.
+     * @param targetAssignmentEpoch  The assignment epoch.
+     * @param previousStaticMembers  The static members at schedule time, 
keyed by instance id.
+     * @param result                 The computed target assignment.
+     * @param exception              The exception if the computation failed.
+     * @return A CoordinatorResult containing the records to mutate the group 
state.
+     */
+    private CoordinatorResult<Void, CoordinatorRecord> 
handleOffloadedConsumerTargetAssignmentResult(
+        String groupId,
+        int targetAssignmentEpoch,
+        Map<String, String> previousStaticMembers,
+        TargetAssignmentBuilder.TargetAssignmentResult result,
+        Throwable exception
+    ) {
+        Integer expectedTargetAssignmentEpoch = 
inflightOffloadedAssignorEpochs.remove(groupId);
+        if (expectedTargetAssignmentEpoch == null || targetAssignmentEpoch != 
expectedTargetAssignmentEpoch) {
+            // The assignment epoch doesn't match the expected in-flight 
assignment epoch.
+            // This should never happen since we only allow a single in-flight 
assignor run per
+            // group and cancel assignor tasks before removing their epoch 
from the in-flight map.
+            log.error("[GroupId {}] Discarding unexpected offloaded target 
assignment for epoch {} (expected in-flight epoch was {}).",
+                groupId, targetAssignmentEpoch, expectedTargetAssignmentEpoch);
+            return new CoordinatorResult<>(List.of());
+        }
+
+        if (exception != null) {
+            log.error("[GroupId {}] Failed to compute a new target assignment 
for epoch {}: {}.",
+                groupId, targetAssignmentEpoch, exception.getMessage(), 
exception);
+            return new CoordinatorResult<>(List.of());
+        }
+
+        try {
+            ConsumerGroup consumerGroup = consumerGroup(groupId);
+            if (consumerGroup.groupEpoch() < targetAssignmentEpoch) {
+                // The assignment epoch is greater than the group epoch. This 
means that the
+                // assignment was built off a group state that was not 
successfully written to the
+                // log and was reverted. Discard the assignment.
+                log.debug("[GroupId {}] Discarding stale offloaded target 
assignment for epoch {} (current group epoch is {}).",
+                    groupId, targetAssignmentEpoch, 
consumerGroup.groupEpoch());
+                return new CoordinatorResult<>(List.of());
+            }
+
+            if (consumerGroup.assignmentEpoch() >= targetAssignmentEpoch) {

Review Comment:
   It's an accident that this check catches that case. Originally the check was 
defensive, for the case where the last member leaves a group and the epoch 
bumped on leave and the assignor cancelled.
   
   Added an unconditional cancellation when upgrading a classic group in 
71f772ab1a7fe8c1dbd53a9a490aafb67724fe05 and removed the dead check.



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