chia7712 commented on code in PR #19611: URL: https://github.com/apache/kafka/pull/19611#discussion_r2095148638
########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/SubscribedTopicDescriberImpl.java: ########## @@ -79,49 +81,65 @@ public int numPartitions(Uuid topicId) { */ @Override public Set<String> racksForPartition(Uuid topicId, int partition) { + TopicImage topic = metadataImage.topics().getTopic(topicId); + if (topic != null) { + PartitionRegistration partitionRegistration = topic.partitions().get(partition); + if (partitionRegistration != null) { + Set<String> racks = new HashSet<>(); + for (int replica : partitionRegistration.replicas) { + // Only add the rack if it is available for the broker/replica. + metadataImage.cluster().broker(replica).rack().ifPresent(racks::add); Review Comment: Should we check the offline replica? ########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/SubscribedTopicDescriberImpl.java: ########## @@ -79,49 +81,65 @@ public int numPartitions(Uuid topicId) { */ @Override public Set<String> racksForPartition(Uuid topicId, int partition) { + TopicImage topic = metadataImage.topics().getTopic(topicId); + if (topic != null) { + PartitionRegistration partitionRegistration = topic.partitions().get(partition); + if (partitionRegistration != null) { + Set<String> racks = new HashSet<>(); + for (int replica : partitionRegistration.replicas) { + // Only add the rack if it is available for the broker/replica. + metadataImage.cluster().broker(replica).rack().ifPresent(racks::add); + } + return racks; Review Comment: Should we return immutable set? ########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/SubscribedTopicDescriberImpl.java: ########## @@ -19,41 +19,42 @@ import org.apache.kafka.common.Uuid; import org.apache.kafka.coordinator.group.api.assignor.PartitionAssignor; import org.apache.kafka.coordinator.group.api.assignor.SubscribedTopicDescriber; +import org.apache.kafka.image.MetadataImage; +import org.apache.kafka.image.TopicImage; +import org.apache.kafka.metadata.PartitionRegistration; +import java.util.HashSet; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.IntStream; /** * The subscribed topic metadata class is used by the {@link PartitionAssignor} to obtain * topic and partition metadata for the topics that the modern group is subscribed to. */ public class SubscribedTopicDescriberImpl implements SubscribedTopicDescriber { /** - * The topic Ids mapped to their corresponding {@link TopicMetadata} - * object, which contains topic and partition metadata. + * The map of topic Ids to the set of allowed partitions for each topic. + * If this is empty, all partitions are allowed. */ - private final Map<Uuid, TopicMetadata> topicMetadata; - private final Map<Uuid, Set<Integer>> topicPartitionAllowedMap; + private final Optional<Map<Uuid, Set<Integer>>> topicPartitionAllowedMap; Review Comment: #19739 uses null, in contrast, this PR uses `Optional`. @AndrewJSchofield WDYT? -- 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