RivenSun2 commented on a change in pull request #11340: URL: https://github.com/apache/kafka/pull/11340#discussion_r713524099
########## File path: clients/src/main/java/org/apache/kafka/clients/consumer/internals/ConsumerCoordinator.java ########## @@ -1069,6 +1065,37 @@ private void maybeAutoCommitOffsetsSync(Timer timer) { } } + private void cleanUpConsumedOffsets(Map<TopicPartition, OffsetAndMetadata> willCommitOffsets) { + + if (willCommitOffsets.isEmpty()) + return; + + Set<String> validTopics = metadata.fetch().topics(); + Set<TopicPartition> toGiveUpTopicPartitions = new HashSet<>(); + + Iterator<Map.Entry<TopicPartition, OffsetAndMetadata>> iterator = willCommitOffsets.entrySet().iterator(); + + while (iterator.hasNext()) { + + Map.Entry<TopicPartition, OffsetAndMetadata> entry = iterator.next(); + + if (!validTopics.contains(entry.getKey().topic())) { + + toGiveUpTopicPartitions.add(entry.getKey()); + iterator.remove(); + } + + } + + if (toGiveUpTopicPartitions.size() > 0) { + + //Because toGiveUpTopicPartitions may receive `UnknownTopicOrPartitionException` when submitting their offsets. + //We are prepared to abandon them. The worst effect is that these partitions may repeatedly consume some messages + log.warn("Synchronous auto-commit of offsets {} will be abandoned", toGiveUpTopicPartitions); Review comment: Thank you for your reply. Can you simulate the case of jira and debug test it locally? In fact, what is filtered here are all topicPartitions that are ready to commitOffsets but may trigger `UnknownTopicOrPartitionException` -- 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