dajac commented on code in PR #14467: URL: https://github.com/apache/kafka/pull/14467#discussion_r1349653948
########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/OffsetMetadataManager.java: ########## @@ -544,6 +579,100 @@ public OffsetFetchResponseData.OffsetFetchResponseGroup fetchAllOffsets( .setTopics(topicResponses); } + /** + * Remove expired offsets for group. + * + * @param groupId The group id. + * @param records The list of records to populate with offset commit tombstone records. + * + * @return True if no offsets exist or if all offsets expired, false otherwise. + */ + public boolean cleanupExpiredOffsets(String groupId, List<Record> records) { + TimelineHashMap<String, TimelineHashMap<Integer, OffsetAndMetadata>> offsetsByTopic = offsetsByGroup.get(groupId); + if (offsetsByTopic == null) { + return true; + } + + // We expect the group to exist. + Group group = groupMetadataManager.group(groupId); + Set<TopicPartition> expiredPartitions = new HashSet<>(); + long currentTimestamp = time.milliseconds(); + Optional<OffsetExpirationCondition> offsetExpirationCondition = group.offsetExpirationCondition(); + + if (!offsetExpirationCondition.isPresent()) { + return false; + } + + AtomicBoolean hasAllOffsetsExpired = new AtomicBoolean(true); + OffsetExpirationCondition condition = offsetExpirationCondition.get(); + + offsetsByTopic.forEach((topic, partitions) -> { + if (!group.isSubscribedToTopic(topic, false)) { + partitions.forEach((partition, offsetAndMetadata) -> { + if (condition.isOffsetExpired(offsetAndMetadata, currentTimestamp, config.offsetsRetentionMs)) { + expiredPartitions.add(appendOffsetCommitTombstone(groupId, topic, partition, records)); + } else { + hasAllOffsetsExpired.set(false); + } + }); + } else { + hasAllOffsetsExpired.set(false); + } + }); + + log.debug("[GroupId {}] Expiring offsets: {}", groupId, expiredPartitions); Review Comment: I meant that we need to format the list to a comma separated string. Could we also log the boolean indicating whether all the offsets get expired or not. Should we also say `Expiring offsets of partitions: `? -- 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