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


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java:
##########
@@ -4149,19 +4173,98 @@ private UpdateTargetAssignmentResult<Assignment> 
maybeUpdateTargetAssignment(
                     group.groupId(), groupEpoch, preferredServerAssignor, 
assignorTimeMs);
             }
 
-            records.addAll(assignmentResult.records());
+            return assignmentResult;
+        };
+
+        if (offloadAssignor) {
+            assignmentResultBuilder.freezeInputs();
+            Map<String, String> previousStaticMembers = 
Map.copyOf(updatedMembersAndTargetAssignment.staticMembers());
+            // The view is backed by the group's timeline data structures, 
which may have been
+            // modified by the time the executor task runs.
+            updatedMembersAndTargetAssignment.close();
+
+            executor.schedule(
+                targetAssignmentUpdateKey,
+                buildTargetAssignment::get,
+                (result, exception) -> {
+                    if (exception != null) {
+                        log.error("[GroupId {}] Failed to compute a new target 
assignment for epoch {}: {}.", group.groupId(), groupEpoch, 
exception.getMessage(), exception);
+                        return new CoordinatorResult<>(List.of());
+                    }
+
+                    try {
+                        ConsumerGroup consumerGroup = 
consumerGroup(group.groupId());
+                        if (consumerGroup.assignmentEpoch() >= groupEpoch) {
+                            // The assignment epoch is already caught up.
+                            // Writing this record would backslide it.
+                            log.debug("[GroupId {}] Discarding stale offloaded 
target assignment for epoch {} (current assignment epoch is {}).",
+                                group.groupId(), groupEpoch, 
consumerGroup.assignmentEpoch());
+                            return new CoordinatorResult<>(List.of());
+                        }
+
+                        log.debug("[GroupId {}] Received updated target 
assignment for epoch {}: {}.",
+                            group.groupId(), groupEpoch, 
result.targetAssignment());
+
+                        TargetAssignmentRecordsBuilder<Assignment> 
assignmentRecordsBuilder =
+                            new 
TargetAssignmentRecordsBuilder.ConsumerTargetAssignmentRecordsBuilder(logContext,
 group.groupId())
+                                .withAssignmentEpoch(groupEpoch)
+                                
.withAssignmentTimestampMs(result.assignmentTimestampMs())
+                                .withCurrentMemberIds(group.members().keySet())
+                                
.withPreviousStaticMembers(previousStaticMembers)

Review Comment:
   Yes



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