tkhurana commented on code in PR #2278: URL: https://github.com/apache/phoenix/pull/2278#discussion_r2449875125
########## phoenix-core-server/src/main/java/org/apache/phoenix/replication/ReplicationLogTracker.java: ########## @@ -0,0 +1,518 @@ +/* + * 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.phoenix.replication; + +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.phoenix.replication.metrics.MetricsReplicationLogTracker; +import org.apache.phoenix.util.EnvironmentEdgeManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is responsible to track and managing replication log files across different states. + * Handles file lifecycle management including new files, in-progress files, and completed files. + */ +public class ReplicationLogTracker { + + private static final Logger LOG = LoggerFactory.getLogger(ReplicationLogTracker.class); + + /** + * Configuration key for number of retries when deleting files + */ + private static final String FILE_DELETE_RETRIES_KEY = "phoenix.replication.file.delete.retries"; + + /** + * Default number of retries for file deletion operations + */ + private static final int DEFAULT_FILE_DELETE_RETRIES = 3; + + /** + * Configuration key for delay between file deletion retry attempts + */ + private static final String FILE_DELETE_RETRY_DELAY_MS_KEY = + "phoenix.replication.file.delete.retry.delay.ms"; + + /** + * Default delay in milliseconds between file deletion retry attempts + */ + private static final long DEFAULT_FILE_DELETE_RETRY_DELAY_MS = 1000L; + + private final URI rootURI; + private final DirectoryType directoryType; + private final FileSystem fileSystem; + private Path inProgressDirPath; + private ReplicationShardDirectoryManager replicationShardDirectoryManager; + protected final Configuration conf; + protected final String haGroupName; + protected MetricsReplicationLogTracker metrics; + + public ReplicationLogTracker(final Configuration conf, final String haGroupName, + final FileSystem fileSystem, final URI rootURI, final DirectoryType directoryType, + final MetricsReplicationLogTracker metrics) { + this.conf = conf; + this.fileSystem = fileSystem; + this.haGroupName = haGroupName; + this.rootURI = rootURI; + this.directoryType = directoryType; + this.metrics = metrics; + } + + protected String getNewLogSubDirectoryName() { + return this.directoryType.getName(); + } + + protected MetricsReplicationLogTracker getMetricsSource() { + return this.metrics; + } + + protected String getInProgressLogSubDirectoryName() { + return getNewLogSubDirectoryName() + "_progress"; + } + + /** + * Initializes the file tracker by setting up new files directory and in-progress directory. + * Creates the in-progress directory (rootURI/<group-name>/[in/out]_progress) if it doesn't Review Comment: I would suggest that ReplicationLogTracker should take this path as input `rootURI/groupName/in` or `rootURI/groupName/out` as input. You don't need that enum DirectoryType. The ReplicationLogTracker doesn't need to know about it. It should take a path as input and just work with it. -- 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]
