squah-confluent commented on code in PR #20055: URL: https://github.com/apache/kafka/pull/20055#discussion_r2174928086
########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/consumer/CurrentAssignmentBuilder.java: ########## @@ -215,6 +278,64 @@ private boolean ownsRevokedPartitions( return false; } + /** + * Updates the current assignment, removing any partitions that are not part of the subscribed topics. + * This method is a lot faster than running the full reconciliation logic in computeNextAssignment. + * + * @param memberAssignedPartitions The assigned partitions of the member to use. + * @return A new ConsumerGroupMember. + */ + private ConsumerGroupMember updateCurrentAssignment( + Map<Uuid, Set<Integer>> memberAssignedPartitions + ) { + Set<Uuid> subscribedTopicIds = subscribedTopicIds(); + + // Reuse the original map if no topics need to be removed. + Map<Uuid, Set<Integer>> newAssignedPartitions = memberAssignedPartitions; + Map<Uuid, Set<Integer>> newPartitionsPendingRevocation = new HashMap<>(member.partitionsPendingRevocation()); + for (Map.Entry<Uuid, Set<Integer>> entry : memberAssignedPartitions.entrySet()) { + if (!subscribedTopicIds.contains(entry.getKey())) { + if (newAssignedPartitions == memberAssignedPartitions) { + newAssignedPartitions = new HashMap<>(memberAssignedPartitions); + newPartitionsPendingRevocation = new HashMap<>(member.partitionsPendingRevocation()); + } + newAssignedPartitions.remove(entry.getKey()); + newPartitionsPendingRevocation.merge( + entry.getKey(), + entry.getValue(), + (existing, additional) -> { + existing = new HashSet<>(existing); + existing.addAll(additional); + return existing; + } + ); + } + } + + if (newAssignedPartitions == memberAssignedPartitions) { + // If no partitions were removed, we can return the member as is. + return member; + } + + if (ownsRevokedPartitions(newPartitionsPendingRevocation)) { Review Comment: If we don't check this, then we run into the `UNREVOKED_PARTITIONS` -> `UNRELEASED_PARTITIONS` bug in the regex tests and have to heartbeat an extra time. It just makes the tests worse is all. Instead of transitioning ``` STABLE --subscription update--> STABLE --regex and assignor update--> STABLE ``` it goes ``` STABLE --subscription update--> UNREVOKED_PARTITIONS --regex and assignor update--> UNRELEASED_PARTITIONS --> STABLE ``` -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org