You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ni...@apache.org on 2025/02/20 08:27:26 UTC
(ignite) branch master updated: IGNITE-24481 IgniteSnapshotManager migration to SnapshotFileTree (#11880)
This is an automated email from the ASF dual-hosted git repository.
nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 9a1823ccc1d IGNITE-24481 IgniteSnapshotManager migration to SnapshotFileTree (#11880)
9a1823ccc1d is described below
commit 9a1823ccc1d67fdfe49af824c77463cf13286687
Author: Nikolay <ni...@apache.org>
AuthorDate: Thu Feb 20 11:27:18 2025 +0300
IGNITE-24481 IgniteSnapshotManager migration to SnapshotFileTree (#11880)
---
.../persistence/file/FilePageStoreManager.java | 39 ------
.../persistence/filename/SnapshotFileTree.java | 46 ++++++-
.../snapshot/IgniteSnapshotManager.java | 153 ++++++---------------
.../IncrementalSnapshotVerificationTask.java | 2 +-
.../persistence/snapshot/SnapshotFutureTask.java | 31 ++---
.../snapshot/SnapshotHandlerContext.java | 16 +--
.../snapshot/SnapshotHandlerRestoreTask.java | 2 +-
.../snapshot/SnapshotMetadataVerificationTask.java | 4 +-
.../snapshot/SnapshotPartitionsVerifyHandler.java | 46 +++----
.../snapshot/SnapshotPartitionsVerifyTask.java | 2 +-
.../snapshot/SnapshotResponseRemoteFutureTask.java | 49 +++----
.../snapshot/SnapshotRestoreProcess.java | 14 +-
.../snapshot/IgniteClusterSnapshotHandlerTest.java | 6 +-
.../snapshot/IgniteSnapshotManagerSelfTest.java | 6 +-
14 files changed, 170 insertions(+), 246 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
index cd40750d266..8c08fde21d9 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java
@@ -86,7 +86,6 @@ import static java.util.Objects.requireNonNull;
import static org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION;
import static org.apache.ignite.internal.pagemem.PageIdAllocator.MAX_PARTITION_ID;
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.CACHE_DATA_TMP_FILENAME;
-import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.CACHE_DIR_WITH_META_FILTER;
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.FILE_SUFFIX;
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.INDEX_FILE_NAME;
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.TMP_SUFFIX;
@@ -753,44 +752,6 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen
return store.pages();
}
- /**
- * @param dir Directory to check.
- * @param names Cache group names to filter.
- * @return Files that match cache or cache group pattern.
- */
- public static List<File> cacheDirectories(File dir, Predicate<String> names) {
- File[] files = dir.listFiles();
-
- if (files == null)
- return Collections.emptyList();
-
- return Arrays.stream(files)
- .sorted()
- .filter(File::isDirectory)
- .filter(CACHE_DIR_WITH_META_FILTER)
- .filter(f -> names.test(NodeFileTree.cacheName(f)))
- .collect(Collectors.toList());
- }
-
- /**
- * @param dir Directory to check.
- * @param grpId Cache group id
- * @return Files that match cache or cache group pattern.
- */
- public static File cacheDirectory(File dir, int grpId) {
- File[] files = dir.listFiles();
-
- if (files == null)
- return null;
-
- return Arrays.stream(files)
- .filter(File::isDirectory)
- .filter(CACHE_DIR_WITH_META_FILTER)
- .filter(f -> CU.cacheId(NodeFileTree.cacheName(f)) == grpId)
- .findAny()
- .orElse(null);
- }
-
/**
* @param cacheDir Cache directory to check.
* @return List of cache partitions in given directory.
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/SnapshotFileTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/SnapshotFileTree.java
index 0c9bc67a068..23d9465c336 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/SnapshotFileTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/SnapshotFileTree.java
@@ -18,8 +18,14 @@
package org.apache.ignite.internal.processors.cache.persistence.filename;
import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
import org.apache.ignite.internal.GridKernalContext;
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.U;
import org.jetbrains.annotations.Nullable;
@@ -51,7 +57,7 @@ public class SnapshotFileTree extends NodeFileTree {
public static final String DUMP_LOCK = "dump.lock";
/** Incremental snapshots directory name. */
- private static final String INC_SNP_DIR = "increments";
+ public static final String INC_SNP_DIR = "increments";
/** Dump files name. */
private static final String DUMP_FILE_EXT = ".dump";
@@ -92,7 +98,7 @@ public class SnapshotFileTree extends NodeFileTree {
this.name = name;
this.path = path;
this.consId = consId;
- this.tmpFt = new NodeFileTree(new File(snapshotTempRoot(), name), folderName());
+ this.tmpFt = new NodeFileTree(new File(ctx.pdsFolderResolver().fileTree().snapshotTempRoot(), name), folderName());
}
/** @return Snapshot name. */
@@ -174,6 +180,42 @@ public class SnapshotFileTree extends NodeFileTree {
return consId;
}
+ /**
+ * @param names Cache group names to filter.
+ * @return Files that match cache or cache group pattern.
+ */
+ public List<File> cacheDirectories(Predicate<String> names) {
+ File[] files = nodeStorage().listFiles();
+
+ if (files == null)
+ return Collections.emptyList();
+
+ return Arrays.stream(files)
+ .sorted()
+ .filter(File::isDirectory)
+ .filter(CACHE_DIR_WITH_META_FILTER)
+ .filter(f -> names.test(cacheName(f)))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * @param grpId Cache group id.
+ * @return Files that match cache or cache group pattern.
+ */
+ public File cacheDirectory(int grpId) {
+ File[] files = nodeStorage().listFiles();
+
+ if (files == null)
+ return null;
+
+ return Arrays.stream(files)
+ .filter(File::isDirectory)
+ .filter(CACHE_DIR_WITH_META_FILTER)
+ .filter(f -> CU.cacheId(cacheName(f)) == grpId)
+ .findAny()
+ .orElse(null);
+ }
+
/**
* @param partId Partition id.
* @return File name of delta partition pages.
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
index 40219b3b003..f3529b559aa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
@@ -212,15 +212,12 @@ import static org.apache.ignite.internal.pagemem.PageIdUtils.pageIndex;
import static org.apache.ignite.internal.pagemem.PageIdUtils.toDetailString;
import static org.apache.ignite.internal.processors.cache.GridCacheUtils.baselineNode;
import static org.apache.ignite.internal.processors.cache.GridCacheUtils.isPersistenceEnabled;
-import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheDirectories;
-import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.TMP_SUFFIX;
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.cacheName;
-import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.partitionFile;
import static org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver.DB_DEFAULT_FOLDER;
import static org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree.DELTA_IDX_SUFFIX;
import static org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree.DUMP_LOCK;
+import static org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree.INC_SNP_DIR;
import static org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree.SNAPSHOT_METAFILE_EXT;
-import static org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree.partDeltaFileName;
import static org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_ID;
import static org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_NAME;
import static org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId.getTypeByPartId;
@@ -294,10 +291,6 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
/** Default value of check flag. */
public static final boolean DFLT_CHECK_ON_RESTORE = false;
- /** @deprecated Use #SNP_RUNNING_DIR_KEY instead. */
- @Deprecated
- private static final String SNP_RUNNING_KEY = "snapshot-running";
-
/** Snapshot operation start log message. */
private static final String SNAPSHOT_STARTED_MSG = "Cluster-wide snapshot operation started: ";
@@ -328,9 +321,6 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
/** Total snapshot files count which receiver should expect to receive. */
private static final String SNP_PARTITIONS_CNT = "partsCnt";
- /** Incremental snapshots directory name. */
- public static final String INC_SNP_DIR = "increments";
-
/** Pattern for incremental snapshot directory names. */
public static final Pattern INC_SNP_NAME_PATTERN = U.fixedLengthNumberNamePattern(null);
@@ -458,15 +448,6 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
snpRmtMgr = new SequentialRemoteSnapshotManager();
}
- /**
- * @param snapshotCacheDir Snapshot directory to store files.
- * @param partId Cache partition identifier.
- * @return A file representation.
- */
- public static File partDeltaFile(File snapshotCacheDir, int partId) {
- return new File(snapshotCacheDir, partDeltaFileName(partId));
- }
-
/**
* Partition delta index file. Represents a sequence of page indexes that written to a delta.
*
@@ -632,8 +613,14 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
() -> F.flatCollections(F.transform(localSnapshotNames(null), name -> {
List<SnapshotView> views = new ArrayList<>();
- for (SnapshotMetadata m: readSnapshotMetadatas(name, null)) {
- List<File> dirs = snapshotCacheDirectories(m.snapshotName(), null, m.folderName(), grpName -> true);
+ for (SnapshotMetadata m: readSnapshotMetadatas(new SnapshotFileTree(ctx, name, null))) {
+ List<File> dirs = snapshotCacheDirectories(
+ m.snapshotName(),
+ null,
+ m.folderName(),
+ m.consistentId(),
+ grpName -> true
+ );
Collection<String> cacheGrps = F.viewReadOnly(dirs, NodeFileTree::cacheName);
@@ -772,18 +759,6 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
});
}
- /**
- * @param snpName Snapshot name.
- * @param snpPath Snapshot directory path.
- * @return Local snapshot directory where snapshot files are located.
- */
- public File snapshotLocalDir(String snpName, @Nullable String snpPath) {
- assert ft != null;
- assert U.alphanumericUnderscore(snpName) : snpName;
-
- return snpPath == null ? new File(ft.snapshotsRoot(), snpName) : new File(snpPath, snpName);
- }
-
/**
* @param req Request on snapshot creation.
* @return Future which will be completed when a snapshot has been started.
@@ -1085,7 +1060,7 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
encKey == null ? null : encSpi.encryptKey(encKey)
);
- SnapshotHandlerContext ctx = new SnapshotHandlerContext(meta, req.groups(), cctx.localNode(), req.snapshotFileTree().root(),
+ SnapshotHandlerContext ctx = new SnapshotHandlerContext(meta, req.groups(), cctx.localNode(), req.snapshotFileTree(),
req.streamerWarning(), true);
req.meta(meta);
@@ -1330,10 +1305,8 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
if (!oldestBaseline)
return;
- File snpDir = snapshotLocalDir(snpReq.snapshotName(), snpReq.snapshotPath());
- File tempSmf = new File(snpDir, snapshotMetaFileName(cctx.localNode().consistentId().toString()) +
- TMP_SUFFIX);
- File smf = new File(snpDir, snapshotMetaFileName(cctx.localNode().consistentId().toString()));
+ File tempSmf = snpReq.snapshotFileTree().tmpMeta();
+ File smf = snpReq.snapshotFileTree().meta();
try {
storeSnapshotMeta(snpReq.meta(), tempSmf);
@@ -1820,22 +1793,19 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
* @param names Cache group names to filter.
* @return The list of cache or cache group names in given snapshot on local node.
*/
- public List<File> snapshotCacheDirectories(String snpName, @Nullable String snpPath, String folderName, Predicate<String> names) {
- File snpDir = snapshotLocalDir(snpName, snpPath);
+ public List<File> snapshotCacheDirectories(
+ String snpName,
+ @Nullable String snpPath,
+ String folderName,
+ String consId,
+ Predicate<String> names
+ ) {
+ SnapshotFileTree sft = new SnapshotFileTree(cctx.kernalContext(), snpName, snpPath, folderName, consId);
- if (!snpDir.exists())
+ if (!sft.root().exists())
return Collections.emptyList();
- return cacheDirectories(new File(snpDir, databaseRelativePath(folderName)), names);
- }
-
- /**
- * @param snpDir The full path to the snapshot files.
- * @param consId Node consistent id to read metadata for.
- * @return Snapshot metadata instance.
- */
- public SnapshotMetadata readSnapshotMetadata(File snpDir, String consId) throws IgniteCheckedException, IOException {
- return readSnapshotMetadata(new File(snpDir, snapshotMetaFileName(consId)));
+ return sft.cacheDirectories(names);
}
/**
@@ -1871,24 +1841,22 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
}
/**
- * @param snpName Snapshot name.
- * @param snpPath Snapshot directory path.
+ * Note, there can be snapshots from other nodes.
+ * This method will read all metadata.
+ * Some instances can return {@link SnapshotMetadata#folderName()} and {@link SnapshotMetadata#consistentId()} that differs from local.
+ *
+ * @param sft Snapshot file tree.
* @return List of snapshot metadata for the given snapshot name on local node.
* If snapshot has been taken from local node the snapshot metadata for given
* local node will be placed on the first place.
*/
- public List<SnapshotMetadata> readSnapshotMetadatas(String snpName, @Nullable String snpPath) {
- A.notNullOrEmpty(snpName, "Snapshot name cannot be null or empty.");
- A.ensure(U.alphanumericUnderscore(snpName), "Snapshot name must satisfy the following name pattern: a-zA-Z0-9_");
-
- File snpDir = snapshotLocalDir(snpName, snpPath);
-
- if (!(snpDir.exists() && snpDir.isDirectory()))
+ public List<SnapshotMetadata> readSnapshotMetadatas(SnapshotFileTree sft) {
+ if (!(sft.root().exists() && sft.root().isDirectory()))
return Collections.emptyList();
List<File> smfs = new ArrayList<>();
- try (DirectoryStream<Path> ds = Files.newDirectoryStream(snpDir.toPath())) {
+ try (DirectoryStream<Path> ds = Files.newDirectoryStream(sft.root().toPath())) {
for (Path d : ds) {
File f = d.toFile();
@@ -2286,18 +2254,13 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
restoreCacheGrpProc.cleanup();
// Snapshot which has not been completed due to the local node crashed must be deleted.
- String snpName = (String)metaStorage.read(SNP_RUNNING_KEY);
- String snpDirName = snpName == null ? (String)metaStorage.read(SNP_RUNNING_DIR_KEY) : null;
+ String snpDirName = (String)metaStorage.read(SNP_RUNNING_DIR_KEY);
- File snpDir = snpName != null
- ? snapshotLocalDir(snpName, null)
- : snpDirName != null
- ? new File(snpDirName)
- : null;
-
- if (snpDir == null)
+ if (snpDirName == null)
return;
+ File snpDir = new File(snpDirName);
+
recovered = true;
for (File tmp : ft.snapshotTempRoot().listFiles())
@@ -2414,14 +2377,6 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
}
}
- /**
- * @param consId Consistent node id.
- * @return Snapshot metadata file name.
- */
- public static String snapshotMetaFileName(String consId) {
- return U.maskForFileName(consId) + SNAPSHOT_METAFILE_EXT;
- }
-
/**
* @param snpDir The full path to the snapshot files.
* @param folderName The node folder name, usually it's the same as the U.maskForFileName(consistentId).
@@ -2461,45 +2416,28 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
/**
* @param snpName Snapshot name.
- * @param grpName Cache group name.
+ * @param ccfg Cache configuration.
* @param partId Partition id.
* @param encrKeyProvider Encryption keys provider to create encrypted IO. If {@code null}, no encrypted IO is used.
* @return Iterator over partition.
* @throws IgniteCheckedException If and error occurs.
*/
public GridCloseableIterator<CacheDataRow> partitionRowIterator(String snpName,
- String grpName,
+ CacheConfiguration<?, ?> ccfg,
int partId,
@Nullable EncryptionCacheKeyProvider encrKeyProvider
) throws IgniteCheckedException {
- File snpDir = snapshotLocalDir(snpName, null);
-
- if (!snpDir.exists())
- throw new IgniteCheckedException("Snapshot directory doesn't exists: " + snpDir.getAbsolutePath());
-
- File nodePath = new File(snpDir, databaseRelativePath(ft.folderName()));
+ SnapshotFileTree sft = new SnapshotFileTree(cctx.kernalContext(), snpName, null);
- if (!nodePath.exists())
- throw new IgniteCheckedException("Consistent id directory doesn't exists: " + nodePath.getAbsolutePath());
+ if (!sft.root().exists())
+ throw new IgniteCheckedException("Snapshot directory doesn't exists: " + sft.root().getAbsolutePath());
- List<File> grps = cacheDirectories(nodePath, name -> name.equals(grpName));
-
- if (F.isEmpty(grps)) {
- throw new IgniteCheckedException(
- "The snapshot cache group not found [dir=" + snpDir.getAbsolutePath() + ", grpName=" + grpName + ']'
- );
- }
-
- if (grps.size() > 1) {
- throw new IgniteCheckedException(
- "The snapshot cache group directory cannot be uniquely identified [dir=" + snpDir.getAbsolutePath() +
- ", grpName=" + grpName + ']'
- );
- }
+ if (!sft.nodeStorage().exists())
+ throw new IgniteCheckedException("Consistent id directory doesn't exists: " + sft.nodeStorage().getAbsolutePath());
- File snpPart = partitionFile(new File(snapshotLocalDir(snpName, null), databaseRelativePath(ft.folderName())),
- grps.get(0).getName(), partId);
+ File snpPart = sft.partitionFile(ccfg, partId);
+ String grpName = CU.cacheOrGroupName(ccfg);
int grpId = CU.cacheId(grpName);
FilePageStore pageStore = (FilePageStore)storeMgr.getPageStoreFactory(grpId,
@@ -2699,7 +2637,6 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
try {
metaStorage.remove(SNP_RUNNING_DIR_KEY);
- metaStorage.remove(SNP_RUNNING_KEY);
}
finally {
cctx.database().checkpointReadUnlock();
@@ -3636,7 +3573,6 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
if (msg instanceof SnapshotFilesRequestMessage) {
SnapshotFilesRequestMessage reqMsg0 = (SnapshotFilesRequestMessage)msg;
String rqId = reqMsg0.id();
- String snpName = reqMsg0.snapshotName();
try {
synchronized (this) {
@@ -3655,8 +3591,7 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
new SnapshotResponseRemoteFutureTask(cctx,
nodeId,
reqMsg0.requestId(),
- snpName,
- reqMsg0.snapshotPath(),
+ new SnapshotFileTree(cctx.kernalContext(), reqMsg0.snapshotName(), reqMsg0.snapshotPath()),
rmtSndrFactory.apply(rqId, nodeId),
reqMsg0.parts()));
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotVerificationTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotVerificationTask.java
index 70568bc7482..1905824d0c0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotVerificationTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotVerificationTask.java
@@ -342,7 +342,7 @@ public class IncrementalSnapshotVerificationTask extends AbstractSnapshotVerific
}
/** @return Collection of snapshotted transactional caches, key is a cache ID. */
- private Map<Integer, StoredCacheData> readTxCachesData() throws IgniteCheckedException, IOException {
+ private Map<Integer, StoredCacheData> readTxCachesData() {
return GridLocalConfigManager.readCachesData(
sft.nodeStorage(),
ignite.context().marshallerContext().jdkMarshaller(),
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotFutureTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotFutureTask.java
index 81ff8ee077b..289d91735f5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotFutureTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotFutureTask.java
@@ -74,11 +74,8 @@ import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.jetbrains.annotations.Nullable;
-import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.cacheStorage;
import static org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_DIR_NAME;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.copy;
-import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.databaseRelativePath;
-import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.partDeltaFile;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.partDeltaIndexFile;
/**
@@ -96,9 +93,6 @@ class SnapshotFutureTask extends AbstractCreateSnapshotFutureTask implements Che
/** Local buffer to perform copy-on-write operations for {@link PageStoreSerialWriter}. */
private final ThreadLocal<ByteBuffer> locBuff;
- /** Snapshot working directory on file system. */
- private final File tmpSnpWorkDir;
-
/** Node file tree. */
private final NodeFileTree ft;
@@ -135,9 +129,6 @@ class SnapshotFutureTask extends AbstractCreateSnapshotFutureTask implements Che
/** Future to wait until checkpoint mark phase will be finished and snapshot tasks scheduled. */
private final GridFutureAdapter<Void> startedFut = new GridFutureAdapter<>();
- /** Absolute path to save intermediate results of cache partitions of this node. */
- private volatile File tmpConsIdDir;
-
/** Pointer to {@link ClusterSnapshotRecord}. */
private volatile @Nullable WALPointer snpPtr;
@@ -185,7 +176,6 @@ class SnapshotFutureTask extends AbstractCreateSnapshotFutureTask implements Che
assert cctx.pageStore() instanceof FilePageStoreManager : "Snapshot task can work only with physical files.";
assert !parts.containsKey(MetaStorage.METASTORAGE_CACHE_ID) : "The withMetaStorage must be used instead.";
- this.tmpSnpWorkDir = new File(ft.snapshotTempRoot(), snpName);
this.ft = ft;
this.ioFactory = ioFactory;
this.withMetaStorage = withMetaStorage;
@@ -215,16 +205,15 @@ class SnapshotFutureTask extends AbstractCreateSnapshotFutureTask implements Che
snpSndr.close(err);
- if (tmpConsIdDir != null)
- U.delete(tmpConsIdDir);
+ U.delete(sft.tempFileTree().nodeStorage());
// Delete snapshot directory if no other files exists.
try {
- if (U.fileCount(tmpSnpWorkDir.toPath()) == 0 || err != null)
- U.delete(tmpSnpWorkDir.toPath());
+ if (U.fileCount(sft.tempFileTree().root().toPath()) == 0 || err != null)
+ U.delete(sft.tempFileTree().root().toPath());
}
catch (IOException e) {
- log.error("Snapshot directory doesn't exist [snpName=" + snpName + ", dir=" + tmpSnpWorkDir + ']');
+ log.error("Snapshot directory doesn't exist [snpName=" + snpName + ", dir=" + sft.tempFileTree().root() + ']');
}
if (err != null)
@@ -253,9 +242,7 @@ class SnapshotFutureTask extends AbstractCreateSnapshotFutureTask implements Che
if (!started.compareAndSet(false, true))
return false;
- tmpConsIdDir = U.resolveWorkDirectory(tmpSnpWorkDir.getAbsolutePath(),
- databaseRelativePath(cctx.kernalContext().pdsFolderResolver().resolveFolders().folderName()),
- false);
+ U.mkdirs(sft.tempFileTree().nodeStorage());
for (Integer grpId : parts.keySet()) {
CacheGroupContext gctx = cctx.cache().cacheGroup(grpId);
@@ -267,13 +254,13 @@ class SnapshotFutureTask extends AbstractCreateSnapshotFutureTask implements Che
throw new IgniteCheckedException("In-memory cache groups are not allowed to be snapshot: " + grpId);
// Create cache group snapshot directory on start in a single thread.
- U.ensureDirectory(cacheStorage(tmpConsIdDir, ft.cacheDirName(gctx.config())),
+ U.ensureDirectory(sft.tempFileTree().cacheStorage(gctx.config()),
"directory for snapshotting cache group",
log);
}
if (withMetaStorage) {
- U.ensureDirectory(cacheStorage(tmpConsIdDir, METASTORAGE_DIR_NAME),
+ U.ensureDirectory(sft.tempFileTree().cacheStorage(METASTORAGE_DIR_NAME),
"directory for snapshotting metastorage",
log);
}
@@ -481,7 +468,7 @@ class SnapshotFutureTask extends AbstractCreateSnapshotFutureTask implements Che
GroupPartitionId pair = new GroupPartitionId(grpId, partId);
PageStore store = pageStore.getStore(grpId, partId);
- File delta = partDeltaFile(cacheStorage(tmpConsIdDir, dirName), partId);
+ File delta = sft.partDeltaFile(dirName, partId);
partDeltaWriters.put(pair, deltaWriterFactory.apply(store, delta, encGrpId));
@@ -642,7 +629,7 @@ class SnapshotFutureTask extends AbstractCreateSnapshotFutureTask implements Che
if (sent || fromTemp)
return;
- File cacheWorkDir = cacheStorage(tmpSnpWorkDir, cacheDirName);
+ File cacheWorkDir = sft.tempFileTree().cacheStorage(cacheDirName);
if (!U.mkdirs(cacheWorkDir))
throw new IOException("Unable to create temp directory to copy original configuration file: " + cacheWorkDir);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotHandlerContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotHandlerContext.java
index 07b9946dfcc..6f84c968184 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotHandlerContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotHandlerContext.java
@@ -17,9 +17,9 @@
package org.apache.ignite.internal.processors.cache.persistence.snapshot;
-import java.io.File;
import java.util.Collection;
import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree;
import org.jetbrains.annotations.Nullable;
/**
@@ -30,7 +30,7 @@ public class SnapshotHandlerContext {
private final SnapshotMetadata metadata;
/** The full path to the snapshot files. */
- private final File snpDir;
+ private final SnapshotFileTree sft;
/** The names of the cache groups on which the operation is performed. */
private final Collection<String> grps;
@@ -49,7 +49,7 @@ public class SnapshotHandlerContext {
* @param grps The names of the cache groups on which the operation is performed.
* {@code False} otherwise. Always {@code false} for snapshot restoration.
* @param locNode Local node.
- * @param snpDir The full path to the snapshot files.
+ * @param sft Snapshot file tree.
* @param streamerWrn {@code True} if concurrent streaming updates occurred during snapshot operation.
* @param check If {@code true}, calculates and compares partition hashes. Otherwise, only basic snapshot validation is launched.
*/
@@ -57,14 +57,14 @@ public class SnapshotHandlerContext {
SnapshotMetadata metadata,
@Nullable Collection<String> grps,
ClusterNode locNode,
- File snpDir,
+ SnapshotFileTree sft,
boolean streamerWrn,
boolean check
) {
this.metadata = metadata;
this.grps = grps;
this.locNode = locNode;
- this.snpDir = snpDir;
+ this.sft = sft;
this.streamerWrn = streamerWrn;
this.check = check;
}
@@ -77,10 +77,10 @@ public class SnapshotHandlerContext {
}
/**
- * @return The full path to the snapshot files.
+ * @return Snapshot file tree.
*/
- public File snapshotDirectory() {
- return snpDir;
+ public SnapshotFileTree snapshotFileTree() {
+ return sft;
}
/**
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotHandlerRestoreTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotHandlerRestoreTask.java
index 462840f0a67..773f0de14c5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotHandlerRestoreTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotHandlerRestoreTask.java
@@ -117,7 +117,7 @@ public class SnapshotHandlerRestoreTask extends AbstractSnapshotVerificationTask
SnapshotMetadata meta = snpMgr.readSnapshotMetadata(sft.meta());
return snpMgr.handlers().invokeAll(SnapshotHandlerType.RESTORE,
- new SnapshotHandlerContext(meta, rqGrps, ignite.localNode(), sft.root(), false, check));
+ new SnapshotHandlerContext(meta, rqGrps, ignite.localNode(), sft, false, check));
}
catch (IgniteCheckedException | IOException e) {
throw new IgniteException(e);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotMetadataVerificationTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotMetadataVerificationTask.java
index a021b66588b..45810ee8c09 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotMetadataVerificationTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotMetadataVerificationTask.java
@@ -109,14 +109,14 @@ public class SnapshotMetadataVerificationTask
SnapshotFileTree sft = new SnapshotFileTree(ignite.context(), arg.snapshotName(), arg.snapshotPath());
- List<SnapshotMetadata> snpMeta = snpMgr.readSnapshotMetadatas(sft.name(), sft.path());
+ List<SnapshotMetadata> snpMeta = snpMgr.readSnapshotMetadatas(sft);
for (SnapshotMetadata meta : snpMeta)
checkMeta(meta);
if (arg.incrementIndex() > 0) {
List<SnapshotMetadata> metas = snpMeta.stream()
- .filter(m -> m.consistentId().equals(valueOf(ignite.localNode().consistentId())))
+ .filter(m -> m.consistentId().equals(sft.consistentId()))
.collect(Collectors.toList());
if (metas.size() != 1) {
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyHandler.java
index 380b6842258..6b6fabb9b0c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyHandler.java
@@ -74,12 +74,10 @@ import static org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX;
import static org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION;
import static org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING;
import static org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.fromOrdinal;
-import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheDirectories;
import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cachePartitionFiles;
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.cacheName;
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.partId;
import static org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId.getTypeByPartId;
-import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.databaseRelativePath;
import static org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext.closeAllComponents;
import static org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext.startAllComponents;
import static org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.calculatePartitionHash;
@@ -109,8 +107,8 @@ public class SnapshotPartitionsVerifyHandler implements SnapshotHandler<Map<Part
/** {@inheritDoc} */
@Override public Map<PartitionKey, PartitionHashRecord> invoke(SnapshotHandlerContext opCtx) throws IgniteCheckedException {
- if (!opCtx.snapshotDirectory().exists())
- throw new IgniteCheckedException("Snapshot directory doesn't exists: " + opCtx.snapshotDirectory());
+ if (!opCtx.snapshotFileTree().root().exists())
+ throw new IgniteCheckedException("Snapshot directory doesn't exists: " + opCtx.snapshotFileTree().root());
SnapshotMetadata meta = opCtx.metadata();
@@ -131,7 +129,7 @@ public class SnapshotPartitionsVerifyHandler implements SnapshotHandler<Map<Part
Map<Integer, File> grpDirs = new HashMap<>();
- for (File dir : cacheDirectories(new File(opCtx.snapshotDirectory(), databaseRelativePath(meta.folderName())), name -> true)) {
+ for (File dir : opCtx.snapshotFileTree().cacheDirectories(name -> true)) {
int grpId = CU.cacheId(cacheName(dir));
if (!grps.remove(grpId))
@@ -191,7 +189,7 @@ public class SnapshotPartitionsVerifyHandler implements SnapshotHandler<Map<Part
IgniteSnapshotManager snpMgr = cctx.snapshotMgr();
GridKernalContext snpCtx = snpMgr.createStandaloneKernalContext(cctx.kernalContext().compress(),
- opCtx.snapshotDirectory(), meta.folderName());
+ opCtx.snapshotFileTree().root(), meta.folderName());
FilePageStoreManager storeMgr = (FilePageStoreManager)cctx.pageStore();
@@ -357,28 +355,21 @@ public class SnapshotPartitionsVerifyHandler implements SnapshotHandler<Map<Part
SnapshotHandlerContext opCtx,
Set<File> partFiles
) {
- try {
- String consistentId = cctx.kernalContext().pdsFolderResolver().resolveFolders().consistentId().toString();
-
- EncryptionSpi encSpi = opCtx.metadata().encryptionKey() != null ? cctx.gridConfig().getEncryptionSpi() : null;
-
- try (Dump dump = new Dump(opCtx.snapshotDirectory(), consistentId, true, true, encSpi, log)) {
- Collection<PartitionHashRecord> partitionHashRecords = U.doInParallel(
- cctx.snapshotMgr().snapshotExecutorService(),
- partFiles,
- part -> calculateDumpedPartitionHash(dump, cacheName(part.getParentFile()), partId(part))
- );
+ EncryptionSpi encSpi = opCtx.metadata().encryptionKey() != null ? cctx.gridConfig().getEncryptionSpi() : null;
- return partitionHashRecords.stream().collect(Collectors.toMap(PartitionHashRecord::partitionKey, r -> r));
- }
- catch (Throwable t) {
- log.error("Error executing handler: ", t);
+ try (Dump dump = new Dump(opCtx.snapshotFileTree().root(), opCtx.snapshotFileTree().consistentId(), true, true, encSpi, log)) {
+ Collection<PartitionHashRecord> partitionHashRecords = U.doInParallel(
+ cctx.snapshotMgr().snapshotExecutorService(),
+ partFiles,
+ part -> calculateDumpedPartitionHash(dump, cacheName(part.getParentFile()), partId(part))
+ );
- throw new IgniteException(t);
- }
+ return partitionHashRecords.stream().collect(Collectors.toMap(PartitionHashRecord::partitionKey, r -> r));
}
- catch (IgniteCheckedException e) {
- throw new IgniteException(e);
+ catch (Throwable t) {
+ log.error("Error executing handler: ", t);
+
+ throw new IgniteException(t);
}
}
@@ -469,16 +460,15 @@ public class SnapshotPartitionsVerifyHandler implements SnapshotHandler<Map<Part
/** */
protected boolean isPunchHoleEnabled(SnapshotHandlerContext opCtx, Set<Integer> grpIds) {
SnapshotMetadata meta = opCtx.metadata();
- Path snapshotDir = opCtx.snapshotDirectory().toPath();
if (meta.hasCompressedGroups() && grpIds.stream().anyMatch(meta::isGroupWithCompression)) {
try {
- cctx.kernalContext().compress().checkPageCompressionSupported(snapshotDir, meta.pageSize());
+ cctx.kernalContext().compress().checkPageCompressionSupported(opCtx.snapshotFileTree().root().toPath(), meta.pageSize());
return true;
}
catch (Exception e) {
- log.info("File system doesn't support page compression on snapshot directory: " + snapshotDir
+ log.info("File system doesn't support page compression on snapshot directory: " + opCtx.snapshotFileTree().root()
+ ", snapshot may have larger size than expected.");
}
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyTask.java
index e2f7f86762e..3aae970b0e7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyTask.java
@@ -96,7 +96,7 @@ public class SnapshotPartitionsVerifyTask extends AbstractSnapshotVerificationTa
SnapshotMetadata meta = cctx.snapshotMgr().readSnapshotMetadata(sft.meta());
return new SnapshotPartitionsVerifyHandler(cctx)
- .invoke(new SnapshotHandlerContext(meta, rqGrps, ignite.localNode(), sft.root(), false, check));
+ .invoke(new SnapshotHandlerContext(meta, rqGrps, ignite.localNode(), sft, false, check));
}
catch (IgniteCheckedException | IOException e) {
throw new IgniteException(e);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotResponseRemoteFutureTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotResponseRemoteFutureTask.java
index 8e4ff56e6ba..1c9b9c49c0a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotResponseRemoteFutureTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotResponseRemoteFutureTask.java
@@ -26,27 +26,25 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
+import java.util.stream.Collectors;
import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
+import org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree;
import org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId;
import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteBiTuple;
import org.jetbrains.annotations.Nullable;
-import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheDirectory;
-import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.partitionFile;
-import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.databaseRelativePath;
-
/** */
public class SnapshotResponseRemoteFutureTask extends AbstractSnapshotFutureTask<Void> {
- /** Snapshot directory path. */
- private final String snpPath;
+ /** Snapshot file tree. */
+ private final SnapshotFileTree sft;
/**
* @param cctx Shared context.
* @param srcNodeId Node id which cause snapshot task creation.
* @param reqId Snapshot operation request ID.
- * @param snpName Unique identifier of snapshot process.
- * @param snpPath Snapshot directory path.
+ * @param sft Snapshot file tree.
* @param snpSndr Factory which produces snapshot receiver instance.
* @param parts Partition to be processed.
*/
@@ -54,14 +52,13 @@ public class SnapshotResponseRemoteFutureTask extends AbstractSnapshotFutureTask
GridCacheSharedContext<?, ?> cctx,
UUID srcNodeId,
UUID reqId,
- String snpName,
- String snpPath,
+ SnapshotFileTree sft,
SnapshotSender snpSndr,
Map<Integer, Set<Integer>> parts
) {
- super(cctx, srcNodeId, reqId, snpName, snpSndr, parts);
+ super(cctx, srcNodeId, reqId, sft.name(), snpSndr, parts);
- this.snpPath = snpPath;
+ this.sft = sft;
}
/** {@inheritDoc} */
@@ -70,11 +67,16 @@ public class SnapshotResponseRemoteFutureTask extends AbstractSnapshotFutureTask
return false;
try {
- List<SnapshotMetadata> metas = cctx.snapshotMgr().readSnapshotMetadatas(snpName, snpPath);
+ List<IgniteBiTuple<SnapshotMetadata, SnapshotFileTree>> metasAndTrees = cctx.snapshotMgr().readSnapshotMetadatas(sft)
+ .stream().map(meta -> F.t(
+ meta,
+ // Separate file tree for the case when snapshot moved from other node.
+ new SnapshotFileTree(cctx.kernalContext(), sft.name(), sft.path(), meta.folderName(), meta.consistentId()))
+ ).collect(Collectors.toList());
- Function<GroupPartitionId, SnapshotMetadata> findMeta = pair -> {
- for (SnapshotMetadata meta : metas) {
- Map<Integer, Set<Integer>> parts0 = meta.partitions();
+ Function<GroupPartitionId, IgniteBiTuple<SnapshotMetadata, SnapshotFileTree>> findMeta = pair -> {
+ for (IgniteBiTuple<SnapshotMetadata, SnapshotFileTree> metaAndTree : metasAndTrees) {
+ Map<Integer, Set<Integer>> parts0 = metaAndTree.get1().partitions();
if (F.isEmpty(parts0))
continue;
@@ -82,13 +84,13 @@ public class SnapshotResponseRemoteFutureTask extends AbstractSnapshotFutureTask
Set<Integer> locParts = parts0.get(pair.getGroupId());
if (locParts != null && locParts.contains(pair.getPartitionId()))
- return meta;
+ return metaAndTree;
}
return null;
};
- Map<GroupPartitionId, SnapshotMetadata> partsToSend = new HashMap<>();
+ Map<GroupPartitionId, IgniteBiTuple<SnapshotMetadata, SnapshotFileTree>> partsToSend = new HashMap<>();
parts.forEach((grpId, parts) -> parts.forEach(
part -> partsToSend.computeIfAbsent(new GroupPartitionId(grpId, part), findMeta)));
@@ -103,21 +105,20 @@ public class SnapshotResponseRemoteFutureTask extends AbstractSnapshotFutureTask
snpSndr.init(partsToSend.size());
- File snpDir = cctx.snapshotMgr().snapshotLocalDir(snpName, snpPath);
+ CompletableFuture.runAsync(() -> partsToSend.forEach((gp, metaAndTree) -> {
+ SnapshotFileTree sft0 = metaAndTree.get2();
- CompletableFuture.runAsync(() -> partsToSend.forEach((gp, meta) -> {
if (err.get() != null)
return;
- File cacheDir = cacheDirectory(new File(snpDir, databaseRelativePath(meta.folderName())),
- gp.getGroupId());
+ File cacheDir = sft0.cacheDirectory(gp.getGroupId());
if (cacheDir == null) {
- throw new IgniteException("Cache directory not found [snpName=" + snpName + ", meta=" + meta +
+ throw new IgniteException("Cache directory not found [snpName=" + snpName + ", meta=" + metaAndTree.get1() +
", pair=" + gp + ']');
}
- File snpPart = partitionFile(cacheDir.getParentFile(), cacheDir.getName(), gp.getPartitionId());
+ File snpPart = sft0.partitionFile(cacheDir.getName(), gp.getPartitionId());
if (!snpPart.exists()) {
throw new IgniteException("Snapshot partition file not found [cacheDir=" + cacheDir +
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java
index c5098106e0e..9a41c7cde5f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotRestoreProcess.java
@@ -677,7 +677,8 @@ public class SnapshotRestoreProcess {
}
}
- List<SnapshotMetadata> locMetas = snpMgr.readSnapshotMetadatas(req.snapshotName(), req.snapshotPath());
+ List<SnapshotMetadata> locMetas =
+ snpMgr.readSnapshotMetadatas(new SnapshotFileTree(ctx, req.snapshotName(), req.snapshotPath()));
enrichContext(opCtx0, req, locMetas);
@@ -745,8 +746,15 @@ public class SnapshotRestoreProcess {
// Collect the cache configurations and prepare a temporary directory for copying files.
// Metastorage can be restored only manually by directly copying files.
for (SnapshotMetadata meta : metas) {
- for (File snpCacheDir : cctx.snapshotMgr().snapshotCacheDirectories(req.snapshotName(), req.snapshotPath(), meta.folderName(),
- name -> !METASTORAGE_CACHE_NAME.equals(name))) {
+ List<File> cacheDirs = cctx.snapshotMgr().snapshotCacheDirectories(
+ req.snapshotName(),
+ req.snapshotPath(),
+ meta.folderName(),
+ meta.consistentId(),
+ name -> !METASTORAGE_CACHE_NAME.equals(name)
+ );
+
+ for (File snpCacheDir : cacheDirs) {
String grpName = cacheName(snpCacheDir);
if (!F.isEmpty(req.groups()) && !req.groups().contains(grpName))
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotHandlerTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotHandlerTest.java
index dc07f842002..243a86e784b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotHandlerTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotHandlerTest.java
@@ -366,8 +366,8 @@ public class IgniteClusterSnapshotHandlerTest extends IgniteClusterSnapshotResto
}
@Override public Void invoke(SnapshotHandlerContext ctx) {
- if (!expFullPath.equals(ctx.snapshotDirectory().getAbsolutePath()))
- throw new IllegalStateException("Expected " + expFullPath + ", actual " + ctx.snapshotDirectory());
+ if (!expFullPath.equals(ctx.snapshotFileTree().root().getAbsolutePath()))
+ throw new IllegalStateException("Expected " + expFullPath + ", actual " + ctx.snapshotFileTree().root());
return null;
}
@@ -419,7 +419,7 @@ public class IgniteClusterSnapshotHandlerTest extends IgniteClusterSnapshotResto
@Override public Void invoke(SnapshotHandlerContext ctx) {
// Someone removes snapshot files during creation.
// In this case snapshot must fail.
- U.delete(ctx.snapshotDirectory());
+ U.delete(ctx.snapshotFileTree().root());
return null;
}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManagerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManagerSelfTest.java
index cba652e86ec..edd4958192b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManagerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManagerSelfTest.java
@@ -400,7 +400,7 @@ public class IgniteSnapshotManagerSelfTest extends AbstractSnapshotSelfTest {
Map<Integer, Value> iterated = new HashMap<>();
try (GridCloseableIterator<CacheDataRow> iter = snp(ignite).partitionRowIterator(SNAPSHOT_NAME,
- ccfg.getName(),
+ ccfg,
0,
ignite.context().encryption())
) {
@@ -445,7 +445,7 @@ public class IgniteSnapshotManagerSelfTest extends AbstractSnapshotSelfTest {
int rows = 0;
try (GridCloseableIterator<CacheDataRow> iter = snp(ignite).partitionRowIterator(SNAPSHOT_NAME,
- dfltCacheCfg.getName(),
+ dfltCacheCfg,
0,
ignite.context().encryption())
) {
@@ -491,7 +491,7 @@ public class IgniteSnapshotManagerSelfTest extends AbstractSnapshotSelfTest {
int rows = 0;
try (GridCloseableIterator<CacheDataRow> iter = snp(ignite).partitionRowIterator(SNAPSHOT_NAME,
- dfltCacheCfg.getName(),
+ dfltCacheCfg,
part,
ignite.context().encryption())
) {