dongnuo123 commented on code in PR #20055: URL: https://github.com/apache/kafka/pull/20055#discussion_r2180342268
########## 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: I understand this can avoid unnecessary state transition and involving extra heartbeat but don't follow why there is a `UNREVOKED_PARTITIONS` -> `UNRELEASED_PARTITIONS`. Is it possible for the second case to be ``` STABLE --subscription update--> UNREVOKED_PARTITIONS --regex and assignor update--> 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