chia7712 commented on code in PR #20319:
URL: https://github.com/apache/kafka/pull/20319#discussion_r2291766406


##########
tools/src/main/java/org/apache/kafka/tools/reassign/ReassignPartitionsCommand.java:
##########
@@ -1514,4 +1520,26 @@ static Set<TopicPartitionReplica> 
alterReplicaLogDirs(Admin adminClient,
         }
         return results;
     }
+
+    static Map<TopicPartitionReplica, String> getReplicaToLogDir(Admin 
adminClient, List<TopicPartitionReplica> replicas) throws InterruptedException, 
ExecutionException {
+        return adminClient.describeReplicaLogDirs(replicas).all().get()
+                .entrySet()
+                .stream()
+                .filter(entry -> entry.getValue() != null && 
entry.getValue().getCurrentReplicaLogDir() != null)

Review Comment:
   why to add `entry.getValue() != null` check?



##########
tools/src/main/java/org/apache/kafka/tools/reassign/ReassignPartitionsCommand.java:
##########
@@ -1514,4 +1520,26 @@ static Set<TopicPartitionReplica> 
alterReplicaLogDirs(Admin adminClient,
         }
         return results;
     }
+
+    static Map<TopicPartitionReplica, String> getReplicaToLogDir(Admin 
adminClient, List<TopicPartitionReplica> replicas) throws InterruptedException, 
ExecutionException {
+        return adminClient.describeReplicaLogDirs(replicas).all().get()
+                .entrySet()
+                .stream()
+                .filter(entry -> entry.getValue() != null && 
entry.getValue().getCurrentReplicaLogDir() != null)
+                .collect(Collectors.toMap(
+                    Entry::getKey,
+                    entry -> entry.getValue().getCurrentReplicaLogDir()
+                ));
+    }
+
+    private static List<TopicPartitionReplica> 
getTopicPartitionReplicas(Map<TopicPartition, List<Integer>> 
topicPartitionToReplicas) {

Review Comment:
   It seems `getTopicPartitionReplicas` and `getReplicaToLogDir` can be merged 
into a single helper.
   ```java
       static Map<TopicPartitionReplica, String> getReplicaToLogDir(Admin 
adminClient,
                                                                    
Map<TopicPartition, List<Integer>> topicPartitionToReplicas) throws 
InterruptedException, ExecutionException {
           var tprs = topicPartitionToReplicas.entrySet().stream()
                   .flatMap(entry -> entry.getValue().stream()
                           .map(id -> new 
TopicPartitionReplica(entry.getKey().topic(), entry.getKey().partition(), id)))
                   .collect(Collectors.toUnmodifiableSet());
   
           return adminClient.describeReplicaLogDirs(tprs).all().get()
                   .entrySet()
                   .stream()
                   .filter(entry -> entry.getValue().getCurrentReplicaLogDir() 
!= null)
                   .collect(Collectors.toMap(
                           Entry::getKey,
                           entry -> entry.getValue().getCurrentReplicaLogDir()
                   ));
       }
   
   ```



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