frankgh commented on code in PR #212: URL: https://github.com/apache/cassandra-sidecar/pull/212#discussion_r2114657721
########## server/src/main/java/org/apache/cassandra/sidecar/livemigration/LiveMigrationInstanceMetadataUtil.java: ########## @@ -0,0 +1,193 @@ +/* + * 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.cassandra.sidecar.livemigration; + +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata; +import org.jetbrains.annotations.NotNull; + +import static org.apache.cassandra.sidecar.common.ApiEndpointsV1.LIVE_MIGRATION_CDC_RAW_DIR_PATH; +import static org.apache.cassandra.sidecar.common.ApiEndpointsV1.LIVE_MIGRATION_COMMITLOG_DIR_PATH; +import static org.apache.cassandra.sidecar.common.ApiEndpointsV1.LIVE_MIGRATION_DATA_FILE_DIR_PATH; +import static org.apache.cassandra.sidecar.common.ApiEndpointsV1.LIVE_MIGRATION_HINTS_DIR_PATH; +import static org.apache.cassandra.sidecar.common.ApiEndpointsV1.LIVE_MIGRATION_LOCAL_SYSTEM_DATA_FILE_DIR_PATH; +import static org.apache.cassandra.sidecar.common.ApiEndpointsV1.LIVE_MIGRATION_SAVED_CACHES_DIR_PATH; +import static org.apache.cassandra.sidecar.livemigration.LiveMigrationPlaceholderUtil.CDC_RAW_DIR_PLACEHOLDER; +import static org.apache.cassandra.sidecar.livemigration.LiveMigrationPlaceholderUtil.COMMITLOG_DIR_PLACEHOLDER; +import static org.apache.cassandra.sidecar.livemigration.LiveMigrationPlaceholderUtil.DATA_FILE_DIR_PLACEHOLDER; +import static org.apache.cassandra.sidecar.livemigration.LiveMigrationPlaceholderUtil.HINTS_DIR_PLACEHOLDER; +import static org.apache.cassandra.sidecar.livemigration.LiveMigrationPlaceholderUtil.LOCAL_SYSTEM_DATA_FILE_DIR_PLACEHOLDER; +import static org.apache.cassandra.sidecar.livemigration.LiveMigrationPlaceholderUtil.SAVED_CACHES_DIR_PLACEHOLDER; + +/** + * Utility class for having all {@link InstanceMetadata} related helper functions related to + * Live Migration in one place. + */ +@SuppressWarnings("ConstantValue") +public class LiveMigrationInstanceMetadataUtil +{ + + /** + * List of directories Live Migration considers to transfer between source and destination. + */ + public static List<String> dirsToCopy(InstanceMetadata instanceMetadata) + { + List<String> dirsToCopy = new ArrayList<>(); + dirsToCopy.add(instanceMetadata.hintsDir()); + dirsToCopy.add(instanceMetadata.commitlogDir()); + if (instanceMetadata.savedCachesDir() != null) + { + dirsToCopy.add(instanceMetadata.savedCachesDir()); + } + if (instanceMetadata.cdcDir() != null) + { + dirsToCopy.add(instanceMetadata.cdcDir()); + } + if (instanceMetadata.localSystemDataFileDir() != null) + { + dirsToCopy.add(instanceMetadata.localSystemDataFileDir()); + } + dirsToCopy.addAll(instanceMetadata.dataDirs()); + return dirsToCopy; + } + + /** + * Returns map of directory that can be copied and the index to use while constructing + * url for file transfer. + */ + public static Map<String, String> dirPathPrefixMap(InstanceMetadata instanceMetadata) + { + Map<String, String> dirIndexMap = new Hashtable<>(); Review Comment: in general use of Hashtable is discouraged. It's an old class and it is synchronized, the recommendation is the usage of HashMap. I don't see any null keys/values used in the scope of this method. Are you thinking the map will be updated outside of this method? And maybe if we don't expect changes to the map returned in this method we can return an unmodifiable map here? ``` return Collections.unmodifiableMap(dirIndexMap); ``` -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org