chickenchickenlove commented on code in PR #24250:
URL: https://github.com/apache/kafka/pull/24250#discussion_r4667352689
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/StreamsMembershipManager.java:
##########
@@ -1286,36 +1364,77 @@ private CompletableFuture<Void> assignTasks(final
SortedSet<StreamsRebalanceData
.collect(Collectors.joining(", "))
);
- final SortedSet<TopicPartition> partitionsToAssign =
topicPartitionsForActiveTasks(activeTasksToAssign);
- final SortedSet<TopicPartition> partitionsToAssignNotPreviouslyOwned =
- partitionsToAssignNotPreviouslyOwned(partitionsToAssign,
topicPartitionsForActiveTasks(ownedActiveTasks));
+ final Cluster metadataSnapshot = metadata.fetch();
+ final int metadataVersion = metadata.updateVersion();
+
+ // Include all resolvable active tasks in the target assignment,
including those already applied.
+ // During partial reconciliation, passing only newly resolved tasks
would cause TaskManager
+ // to treat previously assigned tasks omitted from the callback as
removed.
+ final SortedSet<StreamsRebalanceData.TaskId>
resolvedActiveTasksToAssign =
filterTasksResolvableFromLocalMetadata(activeTasksToAssign, metadataSnapshot);
+ final SortedSet<TopicPartition> resolvedPartitionsToAssign =
topicPartitionsForActiveTasks(resolvedActiveTasksToAssign, metadataSnapshot);
+
+ // Request a metadata update if any task has an unknown input topic
partition count
+ // or no valid input partition according to the locally known counts.
+ if (resolvedActiveTasksToAssign.size() < activeTasksToAssign.size()) {
+ metadata.requestUpdate(true);
+ }
+ final SortedSet<TopicPartition> ownedAssignedPartitions =
previousAssignedAssignment.assignedPartitions;
+ final SortedSet<TopicPartition> partitionsToAssignNotPreviouslyOwned =
partitionsToAssignNotPreviouslyOwned(
+ resolvedPartitionsToAssign,
+ ownedAssignedPartitions
+ );
+ final Map<String, SortedSet<Integer>> resolvedActiveTasks =
toTasksAssignment(resolvedActiveTasksToAssign);
+
+ // Capture the resolved portion of the target assignment.
+ // It becomes currentAssignment only after reconciliation completes
successfully.
+ final LocalAssignment resolvedLocalAssignment = new LocalAssignment(
+ assignmentToReconcile.localEpoch,
+ resolvedActiveTasks,
+ assignmentToReconcile.standbyTasks,
+ assignmentToReconcile.warmupTasks,
+ assignmentToReconcile.isGroupReady,
+ resolvedPartitionsToAssign
+ );
+
+ // Skip applying the assignment and invoking the callback if the
resolved tasks
+ // and partitions match the previously reconciled assignment at the
same local epoch.
+ if
(resolvedPartitionsToAssign.equals(previousAssignedAssignment.assignedPartitions)
&&
+
resolvedLocalAssignment.reconcilingCompleted(previousAssignedAssignment)
+ ) {
+ return CompletableFuture.completedFuture(new
AssignTasksResult(null, metadataVersion));
+ }
// Enqueue event to app thread to apply assignment within poll() and
invoke callback.
- // The app thread will trigger ApplyAssignmentEvent to update
subscription state on background thread.
+ // The app thread will trigger Apply to update subscription state on
background thread.
CompletableFuture<Void> partitionsAssignedAndCallbackExecuted =
enqueueStreamsPartitionsAssignedEvent(
- partitionsToAssign,
+ resolvedPartitionsToAssign,
partitionsToAssignNotPreviouslyOwned,
new StreamsRebalanceData.Assignment(
- activeTasksToAssign,
+ resolvedActiveTasksToAssign,
standbyTasksToAssign,
warmupTasksToAssign,
+ resolvedLocalAssignment.assignedPartitions,
+ resolvedLocalAssignment.localEpoch,
isGroupReady
)
);
- partitionsAssignedAndCallbackExecuted.whenComplete((__, callbackError)
-> {
+
+ // Retain cached partition counts only for input topics of the tasks
in the new assignment.
+ final Set<String> assignedInputTopics =
assignedInputTopics(resolvedLocalAssignment);
Review Comment:
Good point. I'll address it in a new commit.
--
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]