Skip to content

KAFKA-20106 [2/2]: Ensure reconciled assignment updated within poll KS#21813

Open
lianetm wants to merge 7 commits intoapache:trunkfrom
lianetm:lm-assignment-fix-ks
Open

KAFKA-20106 [2/2]: Ensure reconciled assignment updated within poll KS#21813
lianetm wants to merge 7 commits intoapache:trunkfrom
lianetm:lm-assignment-fix-ks

Conversation

@lianetm
Copy link
Member

@lianetm lianetm commented Mar 18, 2026

Apply same fix from #21495 to the
Streams manager.

This ensures that assignment updates happen within a call to
consumer.poll (even when reconciliations may complete async in the
background). Done by piggybacking the assignment update the in the
existing hop that was made to the app thread when a reconciliation
completed (previously used to trigger callback only, now used to update
assignment and run callback)

Copy link
Collaborator

@DL1231 DL1231 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this patch

event.assignedPartitions(), event.addedPartitions());
} else if (requestManagers.streamsMembershipManager.isPresent()) {
requestManagers.streamsMembershipManager.get().applyAssignment(
(SortedSet<TopicPartition>) event.assignedPartitions(), event.addedPartitions());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApplyAssignmentEvent wraps assignedPartitions with Collections.unmodifiableSet() in its constructor, which does not preserve the SortedSet interface (unlike Collections.unmodifiableSortedSet()). So the cast (SortedSet<TopicPartition>) event.assignedPartitions() will throw ClassCastException at runtime.

The unit test masks this because completeAssignment() calls membershipManager.applyAssignment() directly, bypassing the ApplyAssignmentEvent round-trip.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call (the gap didn't exits in this PR though, but it is indeed clashing now with the recent fix wrapping into unmodifiable). Will fix it here to align. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by removing the casting and updating the applyAssignment params (we don't really need a SortedSet at that point)

PARTITIONS_ASSIGNED,
PARTITIONS_REMOVED,
STREAMS_ON_TASKS_ASSIGNED_CALLBACK_NEEDED,
STREAMS_PARTITIONS_ASSIGNED,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the class is StreamsTasksAssignedEvent but the enum is STREAMS_PARTITIONS_ASSIGNED. Consider STREAMS_TASKS_ASSIGNED to keep them aligned.

@lucasbru lucasbru self-assigned this Mar 20, 2026
*/
public void applyAssignment(SortedSet<TopicPartition> assignedPartitions, SortedSet<TopicPartition> addedPartitions) {
subscriptionState.assignFromSubscribedAwaitingCallback(assignedPartitions, addedPartitions);
notifyAssignmentChange(assignedPartitions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be package-private? It's only called from ApplicationEventProcessor and tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't. AppEventProcessor is in a diff package than the managers.

assignment
);
backgroundEventHandler.add(event);
log.debug("Enqueued StreamsPartitionsAssignedEvent to apply assignment and trigger onTasksAssigned callback");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: log says StreamsPartitionsAssignedEvent but the class is StreamsTasksAssignedEvent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants