prestona commented on code in PR #15910: URL: https://github.com/apache/kafka/pull/15910#discussion_r1603914389
########## connect/mirror/src/main/java/org/apache/kafka/connect/mirror/CheckpointsStore.java: ########## @@ -0,0 +1,173 @@ +/* + * 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.connect.mirror; + +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.errors.AuthorizationException; +import org.apache.kafka.common.protocol.types.SchemaException; +import org.apache.kafka.common.utils.Time; +import org.apache.kafka.common.utils.Utils; +import org.apache.kafka.connect.util.Callback; +import org.apache.kafka.connect.util.KafkaBasedLog; +import org.apache.kafka.connect.util.TopicAdmin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.apache.kafka.connect.mirror.MirrorCheckpointConfig.CHECKPOINTS_TARGET_CONSUMER_ROLE; + +/** + * Reads once the Kafka log for checkpoints and populates a map of + * checkpoints per consumer group + */ +public class CheckpointsStore implements AutoCloseable { + + private static final Logger log = LoggerFactory.getLogger(CheckpointsStore.class); + + private final MirrorCheckpointTaskConfig config; + private final Set<String> consumerGroups; + + private TopicAdmin cpAdmin = null; + private KafkaBasedLog<byte[], byte[]> backingStore = null; + private Map<String, Map<TopicPartition, Checkpoint>> checkpointsPerConsumerGroup; + + private volatile boolean loadSuccess = false; + private volatile boolean isInitialized = false; + + public CheckpointsStore(MirrorCheckpointTaskConfig config, Set<String> consumerGroups) { + this.config = config; + this.consumerGroups = new HashSet<>(consumerGroups); + } + + // for testing + CheckpointsStore(Map<String, Map<TopicPartition, Checkpoint>> checkpointsPerConsumerGroup) { + this.config = null; + this.consumerGroups = null; + this.checkpointsPerConsumerGroup = checkpointsPerConsumerGroup; + isInitialized = true; + loadSuccess = true; + } + + // potentially long running + public void start() { + checkpointsPerConsumerGroup = readCheckpoints(); + isInitialized = true; + log.trace("Checkpoints store content : {}", checkpointsPerConsumerGroup); + } + + public boolean loadSuccess() { + return loadSuccess; + } + + public boolean isInitialized() { + return isInitialized; + } + + + // return a mutable map - it is expected to be mutated by the Task + public Map<String, Map<TopicPartition, Checkpoint>> contents() { Review Comment: Appreciate the feedback. We oscillated forward and backwards on whether to break encapsulation or risk `CheckpointStore` increasingly implementing all the methods of `Map`. -- 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]
