nizhikov commented on code in PR #10263:
URL: https://github.com/apache/ignite/pull/10263#discussion_r989937959


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java:
##########
@@ -2178,6 +2404,118 @@ private IgniteFuture<Boolean> 
executeRestoreManagementTask(
         return new 
IgniteFutureImpl<>(cctx.kernalContext().task().execute(taskCls, snpName));
     }
 
+    /**
+     * Checks that incremental snapshot can be created for given full snapshot 
and current cluster state.
+     *
+     * @param name Full snapshot name.
+     * @param snpPath Snapshot path.
+     */
+    private void checkIncrementalCanBeCreated(String name, @Nullable String 
snpPath) throws IgniteCheckedException {
+        File snpDir = snapshotLocalDir(name, snpPath);
+
+        SnapshotMetadata meta = readSnapshotMetadata(new File(
+            snpDir,
+            snapshotMetaFileName(cctx.localNode().consistentId().toString())
+        ));
+
+        Set<String> aliveNodesConsIds = cctx.discovery().aliveServerNodes()
+            .stream()
+            .map(node -> node.consistentId().toString())
+            .collect(Collectors.toSet());
+
+        for (String consId : meta.baselineNodes()) {
+            if (!aliveNodesConsIds.contains(consId)) {
+                throw new IgniteCheckedException("Create incremental snapshot 
request has been rejected. " +
+                    "Node from full snapshot offline [consistentId=" + consId 
+ ']');
+            }
+        }
+
+        File rootSnpCachesDir = new File(snpDir, 
databaseRelativePath(meta.folderName()));
+
+        for (int grpId : meta.cacheGroupIds()) {
+            if (grpId == METASTORAGE_CACHE_ID)
+                continue;
+
+            CacheGroupContext gctx = 
cctx.kernalContext().cache().cacheGroup(grpId);
+
+            if (gctx == null) {
+                throw new IgniteCheckedException("Create incremental snapshot 
request has been rejected. " +
+                    "Cache group destroyed [groupId=" + grpId + ']');
+            }
+
+            List<File> snpCacheDir =
+                cacheDirectories(rootSnpCachesDir, grpName -> 
gctx.cacheOrGroupName().equals(grpName));
+
+            if (snpCacheDir.isEmpty()) {
+                throw new IgniteCheckedException("Create incremental snapshot 
request has been rejected. " +
+                    "Cache group directory not found [groupId=" + grpId + ']');
+            }
+
+            assert snpCacheDir.size() == 1 : "Single snapshot cache directory 
must be found";
+
+            JdkMarshaller marsh = 
MarshallerUtils.jdkMarshaller(cctx.kernalContext().igniteInstanceName());
+
+            for (File snpDataFile : 
FilePageStoreManager.cacheDataFiles(snpCacheDir.get(0))) {
+                StoredCacheData snpCacheData = 
GridLocalConfigManager.readCacheData(
+                    snpDataFile,
+                    marsh,
+                    cctx.kernalContext().config()
+                );
+
+                File nodeDataFile = new 
File(snpDataFile.getAbsolutePath().replace(
+                    rootSnpCachesDir.getAbsolutePath(),
+                    pdsSettings.persistentStoreNodePath().getAbsolutePath()
+                ));
+
+                if (!nodeDataFile.exists()) {
+                    throw new IgniteCheckedException("Create incremental 
snapshot request has been rejected. " +
+                        "Cache destroyed [cacheId=" + snpCacheData.cacheId() +
+                        ", cacheName=" + snpCacheData.config().getName() + 
']');
+                }
+
+                StoredCacheData nodeCacheData = 
GridLocalConfigManager.readCacheData(
+                    nodeDataFile,
+                    marsh,
+                    cctx.gridConfig()
+                );
+
+                addEncryptionInfoIfEnabled(nodeCacheData);

Review Comment:
   OK. added this check to `checkIncrementalCanBeCreated`.



-- 
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]

Reply via email to