1.4 KiB
UNDF: UNDF-2026-000000436
kafka-0004: AbstractStickyAssignor — consumerSubscription.topics().contains() in prepopulateCurrentAssignments
Defect ID
kafka-0004
File:Line
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractStickyAssignor.java:1052
Description
In prepopulateCurrentAssignments(), an outer loop iterates over all consumers
(C) and their current assignment. An inner loop iterates over partitions (P per
consumer). At line 1052:
} else if (!consumerSubscription.topics().contains(partition.topic()) || ...)
consumerSubscription.topics() returns List<String>, so .contains() is O(T).
The loop is O(C × P × T) total. Note: kafka-0001/0002 fixed consumer2AllPotentialTopics
and currentAssignment.get(consumer) in a separate code path — this is a distinct
occurrence in prepopulateCurrentAssignments().
With C=200 consumers, P=500 partitions/consumer, T=50 topics → 5M O(T) calls = 250M ops.
Complexity
- Slow: O(C × P × T) — List.contains() = O(T)
- Fast: O(C × P) — HashSet.contains() = O(1)
Severity
HIGH
Speedup Estimate
~T× improvement = 50x at T=50 topics.
Fix
Convert consumerSubscription.topics() to a HashSet<String> before the inner
partition loop, or use the pre-built consumer2AllPotentialTopics (which kafka-0002
already converts to Set<String>) as the subscription check.