muralibasani commented on code in PR #24193:
URL: https://github.com/apache/kafka/pull/24193#discussion_r4620079867


##########
tools/src/main/java/org/apache/kafka/tools/streams/StreamsGroupCommand.java:
##########
@@ -470,31 +473,66 @@ Map<TopicPartition, OffsetsInfo> 
getOffsets(StreamsGroupDescription description)
                 earliest.put(tp, OffsetSpec.earliest());
                 latest.put(tp, OffsetSpec.latest());
             }
-            Map<TopicPartition, ListOffsetsResult.ListOffsetsResultInfo> 
earliestResult = adminClient.listOffsets(
+            Map<TopicPartition, ListOffsetsResult.ListOffsetsResultInfo> 
earliestResult = offsetsOfExistingTopics(adminClient.listOffsets(
                 earliest,
                 withTimeoutMs(new ListOffsetsOptions())
-            ).all().get();
-            Map<TopicPartition, ListOffsetsResult.ListOffsetsResultInfo> 
latestResult = adminClient.listOffsets(
+            ), allTp);
+            Map<TopicPartition, ListOffsetsResult.ListOffsetsResultInfo> 
latestResult = offsetsOfExistingTopics(adminClient.listOffsets(
                 latest,
                 withTimeoutMs(new ListOffsetsOptions())
-            ).all().get();
+            ), allTp);
             Map<TopicPartition, OffsetAndMetadata> committedOffsets = 
getCommittedOffsets(description.groupId());
 
             Map<TopicPartition, OffsetsInfo> output = new HashMap<>();
             for (Map.Entry<TopicPartition, 
ListOffsetsResult.ListOffsetsResultInfo> tp : earliestResult.entrySet()) {
+                if (!latestResult.containsKey(tp.getKey())) {
+                    continue;
+                }
                 final Optional<Long> currentOffset = 
committedOffsets.containsKey(tp.getKey()) ? 
Optional.of(committedOffsets.get(tp.getKey()).offset()) : Optional.empty();
                 final Optional<Integer> leaderEpoch = 
committedOffsets.containsKey(tp.getKey()) ? 
committedOffsets.get(tp.getKey()).leaderEpoch() : Optional.empty();
                 final long lag = currentOffset.map(current -> 
latestResult.get(tp.getKey()).offset() - current).orElseGet(() -> 
latestResult.get(tp.getKey()).offset() - 
earliestResult.get(tp.getKey()).offset());
                 output.put(tp.getKey(),
                     new OffsetsInfo(
                         currentOffset,
                         leaderEpoch,
-                        latestResult.get(tp.getKey()).offset(),
-                        lag));
+                        Optional.of(latestResult.get(tp.getKey()).offset()),
+                        Optional.of(lag)));
+            }
+            // Partitions of a deleted topic have no log-end offset or lag, 
but still show their committed offset.
+            for (TopicPartition tp : allTp) {
+                if (!output.containsKey(tp)) {
+                    final Optional<OffsetAndMetadata> committed = 
Optional.ofNullable(committedOffsets.get(tp));
+                    output.put(tp, new 
OffsetsInfo(committed.map(OffsetAndMetadata::offset), 
committed.flatMap(OffsetAndMetadata::leaderEpoch), Optional.empty(), 
Optional.empty()));
+                }
             }
             return output;
         }
 
+        /**
+         * Like {@code result.all().get()}, but leaves out partitions whose 
topic no longer exists instead of failing.
+         *
+         * <p>A member that stopped without leaving the group (e.g. it 
crashed) keeps its assignment until its
+         * session times out, so the assignment can still reference a topic 
that has since been deleted. The admin
+         * client fails only that topic's partitions with {@link 
UnknownTopicOrPartitionException}, so one deleted
+         * topic must not fail the describe of the whole group (and of the 
remaining groups with {@code --all-groups}).
+         */
+        private static Map<TopicPartition, 
ListOffsetsResult.ListOffsetsResultInfo> offsetsOfExistingTopics(
+            ListOffsetsResult result,
+            Set<TopicPartition> partitions
+        ) throws ExecutionException, InterruptedException {
+            Map<TopicPartition, ListOffsetsResult.ListOffsetsResultInfo> 
offsets = new HashMap<>();
+            for (TopicPartition tp : partitions) {
+                try {
+                    offsets.put(tp, result.partitionResult(tp).get());

Review Comment:
   Yes, I saw it twice per describe before. With the describeTopics check, 
deleted partitions don't reach listOffsets and the ERROR lines are gone in my 
local run.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to