rreddy-22 commented on code in PR #14467: URL: https://github.com/apache/kafka/pull/14467#discussion_r1353053689
########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/OffsetExpirationConditionImpl.java: ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.coordinator.group; + +import java.util.function.Function; + +public class OffsetExpirationConditionImpl implements OffsetExpirationCondition { + + /** + * Given an offset and metadata, obtain the base timestamp that should be used + * as the start of the offsets retention period. + */ + private final Function<OffsetAndMetadata, Long> baseTimestamp; + + public OffsetExpirationConditionImpl(Function<OffsetAndMetadata, Long> baseTimestamp) { + this.baseTimestamp = baseTimestamp; + } + + /** + * Determine whether an offset is expired. Older versions have an expire timestamp per partition. If this + * exists, compare against the current timestamp. Otherwise, use the base timestamp (either commit timestamp + * or current state timestamp if group is empty for generic groups) and check whether the offset has + * exceeded the offset retention. + * + * @param offset The offset and metadata. + * @param currentTimestampMs The current timestamp. + * @param offsetsRetentionMs The offsets retention in milliseconds. + * + * @return Whether the given offset is expired or not. + */ + @Override + public boolean isOffsetExpired(OffsetAndMetadata offset, long currentTimestampMs, long offsetsRetentionMs) { + if (offset.expireTimestampMs.isPresent()) { + // Older versions with explicit expire_timestamp field => old expiration semantics is used + return currentTimestampMs >= offset.expireTimestampMs.getAsLong(); + } else { + // Current version with no per partition retention Review Comment: nit: missing period -- 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