tkalkirill commented on code in PR #800: URL: https://github.com/apache/ignite-3/pull/800#discussion_r870183771
########## modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/CheckpointMarkersStorage.java: ########## @@ -0,0 +1,210 @@ +/* + * 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.pagememory.persistence.checkpoint; + +import static java.nio.file.Files.createDirectories; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.exists; +import static java.nio.file.Files.isDirectory; +import static java.nio.file.Files.list; +import static java.util.stream.Collectors.groupingBy; +import static java.util.stream.Collectors.partitioningBy; +import static java.util.stream.Collectors.toCollection; +import static java.util.stream.Collectors.toList; +import static org.apache.ignite.lang.IgniteSystemProperties.getInteger; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.ignite.lang.IgniteInternalCheckedException; +import org.jetbrains.annotations.Nullable; + +/** + * Abstraction responsible for managing checkpoint markers storage. + */ +// TODO: IGNITE-15818 At the moment, a simple implementation has been made, it may need to be redone, you need to check it +public class CheckpointMarkersStorage { + /** Earliest checkpoint map changes threshold system properties. */ + public static final String IGNITE_CHECKPOINT_MAP_SNAPSHOT_THRESHOLD = "IGNITE_CHECKPOINT_MAP_SNAPSHOT_THRESHOLD"; + + /** Checkpoint start marker. */ + private static final String CHECKPOINT_START_MARKER = "START"; + + /** Checkpoint end marker. */ + private static final String CHECKPOINT_END_MARKER = "END"; + + /** Checkpoint marker file name pattern. */ + private static final Pattern CHECKPOINT_MARKER_FILE_NAME_PATTERN = Pattern.compile("(.*)-(START|END)\\.bin"); + + /** Checkpoint metadata directory ("cp"), contains files with checkpoint start and end markers. */ + private final Path checkpointDir; + + /** Checkpoint IDs. */ + private final Set<UUID> checkpointIds; + + /** Earliest checkpoint map changes threshold. */ + // TODO: IGNITE-16935 Move to config + private final int earliestCheckpointChangesThreshold = getInteger(IGNITE_CHECKPOINT_MAP_SNAPSHOT_THRESHOLD, 5); + + /** + * Constructor. + * + * @param storagePath Storage path. + * @throws IgniteInternalCheckedException If failed. + */ + public CheckpointMarkersStorage( + Path storagePath + ) throws IgniteInternalCheckedException { + checkpointDir = storagePath.resolve("cp"); + + try { + createDirectories(checkpointDir); + } catch (IOException e) { + throw new IgniteInternalCheckedException("Could not create directory for checkpoint metadata: " + checkpointDir, e); + } + + checkCheckpointDir(checkpointDir); + + try { + checkpointIds = list(checkpointDir) + .map(CheckpointMarkersStorage::parseCheckpointIdFromMarkerFile) + .collect(toCollection(ConcurrentHashMap::newKeySet)); Review Comment: They are not sorted, and while this is not necessary, the heading to the class indicates what will need to be redone, this is a temporary version. -- 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]
