apourchet commented on code in PR #15972:
URL: https://github.com/apache/kafka/pull/15972#discussion_r1606913055


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/assignment/RackUtils.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.streams.processor.internals.assignment;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.kafka.common.Cluster;
+import org.apache.kafka.common.Node;
+import org.apache.kafka.common.PartitionInfo;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.TopicPartitionInfo;
+import org.apache.kafka.streams.processor.internals.InternalTopicManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RackUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(RackUtils.class);
+
+    public static Map<TopicPartition, Set<String>> 
getRacksForTopicPartition(final Cluster cluster,
+                                                                             
final InternalTopicManager internalTopicManager,
+                                                                             
final Set<TopicPartition> topicPartitions,
+                                                                             
final boolean isChangelog) {
+        final Set<String> topicsToDescribe = new HashSet<>();
+        if (isChangelog) {
+            
topicsToDescribe.addAll(topicPartitions.stream().map(TopicPartition::topic).collect(
+                Collectors.toSet()));
+        } else {
+            topicsToDescribe.addAll(topicsWithStaleMetadata(cluster, 
topicPartitions));
+        }
+
+        final Set<TopicPartition> topicsWithUpToDateMetadata = 
topicPartitions.stream()
+            .filter(partition -> !topicsToDescribe.contains(partition.topic()))
+            .collect(Collectors.toSet());
+        final Map<TopicPartition, Set<String>> racksForTopicPartition = 
knownRacksForPartition(
+            cluster, topicsWithUpToDateMetadata);
+
+        final Map<String, List<TopicPartitionInfo>> freshTopicPartitionInfo =
+            describeTopics(internalTopicManager, topicsToDescribe);

Review Comment:
   I agree, I wrote it this way to mimic the exact pattern of use that the 
RackAwareAssigner uses. Once this is all wired and tested though we can make 
optimizations and changes like this one (and the lazy rack info one).



-- 
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

Reply via email to