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


##########
tools/src/main/java/org/apache/kafka/tools/consumer/group/ConsumerGroupCommand.java:
##########
@@ -631,7 +635,34 @@ else if (logEndOffsetResult.getValue() instanceof 
OffsetsUtils.Ignore)
                     return null;
 
                 throw new IllegalStateException("Unknown LogOffset subclass: " 
+ logEndOffsetResult.getValue());
-            }).collect(Collectors.toList());
+            }).toList();
+
+            // prepare data for partitions without leaders
+            List<PartitionAssignmentState> noneLeaderAssignments = 
topicPartitionsWithoutLeader.stream()
+                    .map(tp -> getDescribePartitionResult.apply(tp, 
Optional.empty())).toList();
+
+            // concat the data and then sort them
+            return Stream.concat(existLeaderAssignments.stream(), 
noneLeaderAssignments.stream())
+                    .sorted(Comparator.<PartitionAssignmentState, 
String>comparing(
+                            state -> state.topic.orElse(""), String::compareTo)
+                            .thenComparingInt(state -> 
state.partition.orElse(-1)))

Review Comment:
   the sort policy should include topic name, right?



##########
tools/src/main/java/org/apache/kafka/tools/consumer/group/ConsumerGroupCommand.java:
##########
@@ -631,7 +635,34 @@ else if (logEndOffsetResult.getValue() instanceof 
OffsetsUtils.Ignore)
                     return null;
 
                 throw new IllegalStateException("Unknown LogOffset subclass: " 
+ logEndOffsetResult.getValue());
-            }).collect(Collectors.toList());
+            }).toList();
+
+            // prepare data for partitions without leaders
+            List<PartitionAssignmentState> noneLeaderAssignments = 
topicPartitionsWithoutLeader.stream()
+                    .map(tp -> getDescribePartitionResult.apply(tp, 
Optional.empty())).toList();
+
+            // concat the data and then sort them
+            return Stream.concat(existLeaderAssignments.stream(), 
noneLeaderAssignments.stream())
+                    .sorted(Comparator.<PartitionAssignmentState, 
String>comparing(
+                            state -> state.topic.orElse(""), String::compareTo)
+                            .thenComparingInt(state -> 
state.partition.orElse(-1)))
+                    .collect(Collectors.toList());
+        }
+
+        private List<TopicPartition> 
filterNoneLeaderPartitions(Collection<TopicPartition> topicPartitions) {
+            // collect all topics
+            Set<String> topics = 
topicPartitions.stream().map(TopicPartition::topic).collect(Collectors.toSet());
+
+            try {
+                return 
adminClient.describeTopics(topics).allTopicNames().get().entrySet()
+                        .stream()
+                        .flatMap(entry -> 
entry.getValue().partitions().stream()
+                                .filter(partitionInfo -> 
partitionInfo.leader() == null)
+                                .map(partitionInfo -> new 
TopicPartition(entry.getKey(), partitionInfo.partition())))
+                        .collect(Collectors.toList());

Review Comment:
   `.toList();`



##########
tools/src/main/java/org/apache/kafka/tools/consumer/group/ConsumerGroupCommand.java:
##########
@@ -619,7 +618,12 @@ private Collection<PartitionAssignmentState> 
describePartitions(
                     consumerIdOpt, hostOpt, clientIdOpt, logEndOffsetOpt, 
leaderEpoch);
             };
 
-            return 
offsetsUtils.getLogEndOffsets(topicPartitions).entrySet().stream().map(logEndOffsetResult
 -> {
+            List<TopicPartition> topicPartitionsWithLeader = new 
ArrayList<>(topicPartitions);

Review Comment:
   ```java
               List<TopicPartition> topicPartitionsWithoutLeader = 
filterNoneLeaderPartitions(topicPartitions);
               List<TopicPartition> topicPartitionsWithLeader = 
topicPartitions.stream().filter(tp -> 
!topicPartitionsWithoutLeader.contains(tp)).toList();
   ```



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