nizhikov commented on a change in pull request #8946: URL: https://github.com/apache/ignite/pull/8946#discussion_r604660592
########## File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/PdsFolderResolver.java ########## @@ -0,0 +1,524 @@ +/* + * 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.ignite.internal.processors.cache.persistence.filename; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.io.Serializable; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.UUID; +import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.processors.cache.persistence.FileLockHolder; +import org.apache.ignite.internal.util.typedef.internal.A; +import org.apache.ignite.internal.util.typedef.internal.CU; +import org.apache.ignite.internal.util.typedef.internal.SB; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static org.apache.ignite.IgniteSystemProperties.IGNITE_DATA_STORAGE_FOLDER_BY_CONSISTENT_ID; +import static org.apache.ignite.IgniteSystemProperties.getBoolean; + +public class PdsFolderResolver<FLH extends FileLockHolder> { + /** Database subfolders constant prefix. */ + private static final String DB_FOLDER_PREFIX = "node"; + + /** Node index and uid separator in subfolders name. */ + private static final String NODEIDX_UID_SEPARATOR = "-"; + + /** Constant node subfolder prefix and node index pattern (nodeII, where II - node index as decimal integer) */ + private static final String NODE_PATTERN = DB_FOLDER_PREFIX + "[0-9]*" + NODEIDX_UID_SEPARATOR; + + /** Uuid as string pattern. */ + private static final String UUID_STR_PATTERN = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"; + + /** + * Subdir (nodeII-UID, where II - node index as decimal integer, UID - string representation of consistent ID) + * pattern. + */ + private static final String SUBDIR_PATTERN = NODE_PATTERN + UUID_STR_PATTERN; + + /** Database subfolders for new style filter. */ + public static final FileFilter DB_SUBFOLDERS_NEW_STYLE_FILTER = new FileFilter() { + @Override public boolean accept(File pathname) { + return pathname.isDirectory() && pathname.getName().matches(SUBDIR_PATTERN); + } + }; + + /** Database subfolders for old style filter. */ + private static final FileFilter DB_SUBFOLDERS_OLD_STYLE_FILTER = new FileFilter() { + @Override public boolean accept(File pathname) { + String path = pathname.toString(); + return pathname.isDirectory() + && !"wal".equals(pathname.getName()) + && !path.contains(DataStorageConfiguration.DFLT_BINARY_METADATA_PATH) + && !path.contains(DataStorageConfiguration.DFLT_MARSHALLER_PATH) + && !pathname.getName().matches(SUBDIR_PATTERN); + } + }; + + /** Database default folder. */ + public static final String DB_DEFAULT_FOLDER = "db"; + + /** */ + private final IgniteConfiguration cfg; + + /** */ + private final IgniteLogger log; + + /** */ + private final @Nullable Serializable consistentId; + + /** */ + private final Function<File, FLH> tryLock; + + /** + * @param cfg Ignite configuration. + * @param log Logger. + * @param consistentId Constent id. + * @param tryLock Lock function. + */ + public PdsFolderResolver( + IgniteConfiguration cfg, + IgniteLogger log, + @Nullable Serializable consistentId, + Function<File, FLH> tryLock + ) { + this.cfg = cfg; + this.log = log; + this.consistentId = consistentId; + this.tryLock = tryLock; + } + + /** + * Prepares compatible PDS folder settings. No locking is performed, consistent ID is not overridden. + * + * @param pstStoreBasePath DB storage base path or null if persistence is not enabled. + * @param consistentId compatibility consistent ID + * @return PDS folder settings compatible with previous versions. + */ + private PdsFolderSettings<FLH> compatibleResolve( + @Nullable final File pstStoreBasePath, + @Nullable final Serializable consistentId) { + + if (cfg.getConsistentId() != null) { + // compatible mode from configuration is used fot this case, no locking, no consitent id change + return new PdsFolderSettings<>(pstStoreBasePath, cfg.getConsistentId()); + } + + if (consistentId == null) + return new PdsFolderSettings<>(pstStoreBasePath, consistentId); + + return null; + } + + /** + * Creates new settings when we don't have cached one. Review comment: Fixed. Thanks. -- 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. For queries about this service, please contact Infrastructure at: [email protected]
