timoninmaxim commented on code in PR #11391:
URL: https://github.com/apache/ignite/pull/11391#discussion_r1668210102


##########
modules/core/src/main/java/org/apache/ignite/internal/management/cache/VerifyBackupPartitionsTaskV2.java:
##########
@@ -110,7 +111,7 @@ public class VerifyBackupPartitionsTaskV2 extends 
ComputeTaskAdapter<CacheIdleVe
 
     /** {@inheritDoc} */
     @Nullable @Override public IdleVerifyResultV2 
reduce(List<ComputeJobResult> results) throws IgniteException {
-        return reduce0(results);

Review Comment:
   Let's revert name to `reduce0`. Now this renaming just increased changes in 
the patch, e.g. this change affects SnapshotPartitionsVerifyTask file.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotFullCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.management.cache.VerifyBackupPartitionsTaskV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot full checking (with the partition hashes). 
*/
+public class SnapshotFullCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotFullCheckOperationRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotFullCheckOperationRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotFullCheckOperationRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotFullCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);

Review Comment:
   IgniteSnapshotManager handles this event and trigger onNodeLeft for 
SnapshotRestoreProcess. Let's do the same



##########
modules/core/src/main/java/org/apache/ignite/internal/management/cache/VerifyBackupPartitionsTaskV2.java:
##########
@@ -138,34 +139,43 @@ public class VerifyBackupPartitionsTaskV2 extends 
ComputeTaskAdapter<CacheIdleVe
         }
     }
 
-    /**
-     * @param results Received results of broadcast remote requests.
-     * @return Idle verify job result constructed from results of remote 
executions.
-     */
-    public static IdleVerifyResultV2 reduce0(List<ComputeJobResult> results) {
-        Map<PartitionKeyV2, List<PartitionHashRecordV2>> clusterHashes = new 
HashMap<>();
-        Map<ClusterNode, Exception> ex = new HashMap<>();
+    /** */
+    public static IdleVerifyResultV2 reduceJobResults(List<ComputeJobResult> 
jobResults) throws IgniteException {
+        Map<ClusterNode, Map<PartitionKeyV2, PartitionHashRecordV2>> results = 
new HashMap<>();
+        Map<ClusterNode, Exception> errors = new HashMap<>();
 
-        for (ComputeJobResult res : results) {
-            if (res.getException() != null) {
-                ex.put(res.getNode(), res.getException());
+        jobResults.forEach(jr -> {
+            if (jr.getData() != null)
+                results.put(jr.getNode(), jr.getData());
 
-                continue;
-            }
+            if (jr.getException() != null)
+                errors.put(jr.getNode(), jr.getException());
+        });
 
-            Map<PartitionKeyV2, PartitionHashRecordV2> nodeHashes = 
res.getData();
+        return reduceHashesAndErrors(results, errors);
+    }
+
+    /** */
+    public static IdleVerifyResultV2 reduceHashesAndErrors(
+        Map<ClusterNode, Map<PartitionKeyV2, PartitionHashRecordV2>> results,
+        Map<ClusterNode, Exception> errors
+    ) {
+        Map<PartitionKeyV2, List<PartitionHashRecordV2>> clusterHashes = new 
HashMap<>();
+
+        results.forEach((node, nodeHashes) -> {
+            assert errors.get(node) == null;
 
             for (Map.Entry<PartitionKeyV2, PartitionHashRecordV2> e : 
nodeHashes.entrySet()) {
                 List<PartitionHashRecordV2> records = 
clusterHashes.computeIfAbsent(e.getKey(), k -> new ArrayList<>());
 
                 records.add(e.getValue());
             }
-        }
+        });
 
-        if (results.size() != ex.size())
-            return new IdleVerifyResultV2(clusterHashes, ex);
+        if (results.size() != errors.size())
+            return new IdleVerifyResultV2(clusterHashes, errors);
         else
-            return new IdleVerifyResultV2(ex);
+            return new IdleVerifyResultV2(errors);

Review Comment:
   Let's revert `ex -> errors` naming



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotFullCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.management.cache.VerifyBackupPartitionsTaskV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot full checking (with the partition hashes). 
*/
+public class SnapshotFullCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();

Review Comment:
   There is only one object of `SnapshotFullCheckDistributedProcess` in 
runtime. Then this field no need to be static. Also checking snapshot might be 
never called, and it's useless to hold the object in the memory.



##########
modules/core/src/main/java/org/apache/ignite/internal/management/cache/VerifyBackupPartitionsTaskV2.java:
##########
@@ -143,29 +145,20 @@ public class VerifyBackupPartitionsTaskV2 extends 
ComputeTaskAdapter<CacheIdleVe
      * @return Idle verify job result constructed from results of remote 
executions.
      */
     public static IdleVerifyResultV2 reduce0(List<ComputeJobResult> results) {
-        Map<PartitionKeyV2, List<PartitionHashRecordV2>> clusterHashes = new 
HashMap<>();
-        Map<ClusterNode, Exception> ex = new HashMap<>();
+        Map<ClusterNode, Exception> errors = new HashMap<>();

Review Comment:
   Let's revert renaming `ex -> errors`



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.
+     *
+     * @param th The interrupt reason.
+     * @param rqFilter If not {@code null}, used to filter which 
requests/process to stop. If {@code null}, stops all the validations.
+     */
+    public void interrupt(Throwable th, @Nullable 
Function<SnapshotCheckProcessRequest, Boolean> rqFilter) {
+        if (requests.isEmpty())
+            return;
+
+        requests.values().forEach(rq -> {
+            if (rqFilter == null || rqFilter.apply(rq)) {
+                rq.error(th);
+
+                clean(rq.requestId(), th, null, null);
+            }
+        });
+    }
+
+    /** Stops the related validation if the node is a mandatory one. */
+    private void nodeLeft(ClusterNode node) {
+        if (node.isClient() || requests.isEmpty())
+            return;
+
+        interrupt(
+            new ClusterTopologyCheckedException("Snapshot checking stopped. A 
node left the cluster: " + node + '.'),
+            rq -> rq.nodes().contains(node.id())
+        );
+    }
+
+    /** Phase 2 and process finish. */
+    private IgniteInternalFuture<?> reduceValidatePartsAndFinish(
+        UUID procId,
+        Map<UUID, HashMap<PartitionKeyV2, PartitionHashRecordV2>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        clean(procId, null, results, errors);
+
+        return FINISHED_FUT;
+    }
+
+    /** Phase 2 beginning.  */
+    private IgniteInternalFuture<HashMap<PartitionKeyV2, 
PartitionHashRecordV2>> validateParts(
+        SnapshotCheckProcessRequest incReq) {
+        SnapshotCheckProcessRequest locReq;
+
+        if (stopAndCleanOnError(incReq, null) || (locReq = 
requests.get(incReq.snapshotName())) == null)
+            return FINISHED_FUT;
+
+        assert locReq.equals(incReq);
+
+        // Store metas to collect cluster operation result laster.
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
clusterOpFuts.get(incReq.requestId());
+
+        if (clusterOpFut != null)
+            locReq.metas = incReq.metas;
+
+        // Local meta might be null if current node started after the snapshot 
creation or placement.
+        if (!incReq.nodes.contains(kctx.localNodeId()) || locReq.meta() == 
null)
+            return FINISHED_FUT;
+
+        GridFutureAdapter<HashMap<PartitionKeyV2, PartitionHashRecordV2>> 
locPartsChkFut = new GridFutureAdapter<>();
+
+        locReq.fut(locPartsChkFut);
+
+        ExecutorService executor = 
kctx.cache().context().snapshotMgr().snapshotExecutorService();
+
+        executor.submit(() -> stopFutureOnAnyFailure(locPartsChkFut, () -> {
+            // An error can occure when the local future is still null.
+            if (locReq.error() != null)
+                locPartsChkFut.onDone(locReq.error());
+
+            if (locPartsChkFut.isDone())
+                return;
+
+            File snpDir = 
kctx.cache().context().snapshotMgr().snapshotLocalDir(locReq.snapshotName(), 
locReq.snapshotPath());
+
+            try {
+                Map<PartitionKeyV2, PartitionHashRecordV2> res = 
kctx.cache().context().snapshotMgr().checker()
+                    .checkPartitions(locReq.meta(), snpDir, locReq.groups(), 
false, true, false);
+
+                locPartsChkFut.onDone(res instanceof HashMap ? 
(HashMap<PartitionKeyV2, PartitionHashRecordV2>)res
+                    : new HashMap<>(res));
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException("Failed to calculate snapshot 
partition hashes, req: " + incReq, e);
+            }
+
+            // No need to wait to the cealup if current node is just a worker.
+            if (!kctx.localNodeId().equals(locReq.opCoordId) && clusterOpFut 
== null)
+                clean(locReq.reqId, null, null, null);
+        }));
+
+        return locPartsChkFut;
+    }
+
+    /**
+     * If required, stops and clean related validation if errors occured
+     *
+     * @return {@code True} if the validation stopped and cleaned. {@code 
False} otherwise.
+     */
+    private boolean stopAndCleanOnError(SnapshotCheckProcessRequest req,
+        @Nullable Map<UUID, Throwable> occuredErrors) {
+        assert req != null;
+
+        if (!F.isEmpty(occuredErrors)) {
+            occuredErrors = occuredErrors.entrySet().stream()
+                .filter(e -> 
req.nodes.contains(e.getKey())).collect(Collectors.toMap(Map.Entry::getKey, 
Map.Entry::getValue));
+        }
+
+        if (F.isEmpty(occuredErrors) && req.error() == null)
+            return false;
+
+        clean(req.requestId(), req.error(), null, occuredErrors);
+
+        return true;
+    }
+
+    /** Cleans certain snapshot validation. */
+    private void clean(
+        UUID rqId,
+        @Nullable Throwable opErr,
+        @Nullable Map<UUID, ? extends Map<PartitionKeyV2, 
PartitionHashRecordV2>> results,
+        @Nullable Map<UUID, Throwable> errors
+    ) {
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
clusterOpFuts.remove(rqId);
+
+        stopFutureOnAnyFailure(clusterOpFut, () -> {
+            SnapshotCheckProcessRequest locRq = curRequest(null, rqId);
+
+            Throwable err = opErr;
+
+            if (locRq != null)
+                err = stopAndCleanLocRequest(locRq, err);
+
+            if (clusterOpFut == null || clusterOpFut.isDone())
+                return;
+
+            boolean finished;
+
+            // Nodes' results and errors reducing is available on a required 
node where the process request must be registered.
+            assert (F.isEmpty(errors) && F.isEmpty(results)) || locRq != null;
+
+            Map<ClusterNode, Exception> errors0 = locRq == null || 
F.isEmpty(errors)
+                ? Collections.emptyMap()
+                : collectErrors(errors, locRq.nodes());
+
+            if (err == null && !F.isEmpty(results)) {
+                Map<ClusterNode, Map<PartitionKeyV2, PartitionHashRecordV2>> 
results0 = collecPartsHashes(results, locRq.nodes());
+
+                IdleVerifyResultV2 chkRes = 
SnapshotChecker.reduceHashesResults(results0, errors0);
+
+                finished = clusterOpFut.onDone(new 
SnapshotPartitionsVerifyTaskResult(locRq.metas, chkRes));
+            }
+            else
+                finished = finishClusterFutureWithErr(clusterOpFut, err, 
errors0);
+
+            if (finished && log.isInfoEnabled())
+                log.info("Snapshot validation process finished, req: " + locRq 
+ '.');
+        });
+    }
+
+    /** */
+    private Throwable stopAndCleanLocRequest(SnapshotCheckProcessRequest 
locRq, @Nullable Throwable err) {
+        if (err == null && locRq.error() != null)
+            err = locRq.error();
+
+        GridFutureAdapter<?> locWorkingFut = locRq.fut();
+
+        boolean finished = false;
+
+        // Try to stop local working future ASAP.
+        if (locWorkingFut != null)
+            finished = err == null ? locWorkingFut.onDone() : 
locWorkingFut.onDone(err);
+
+        requests.remove(locRq.snapshotName());
+
+        if (finished && log.isInfoEnabled())
+            log.info("Finished snapshot local validation, req: " + locRq + 
'.');
+
+        return err;
+    }
+
+    /** */
+    private Map<ClusterNode, Exception> collectErrors(Map<UUID, Throwable> 
errors, Set<UUID> requiredNodes) {
+        if (errors.isEmpty())
+            return Collections.emptyMap();
+
+        return errors.entrySet().stream().filter(e -> 
requiredNodes.contains(e.getKey()) && e.getValue() != null)
+            .collect(Collectors.toMap(e -> 
kctx.cluster().get().node(e.getKey()), e -> asException(e.getValue())));
+    }
+
+    /** */
+    private Map<ClusterNode, Map<PartitionKeyV2, PartitionHashRecordV2>> 
collecPartsHashes(
+        @Nullable Map<UUID, ? extends Map<PartitionKeyV2, 
PartitionHashRecordV2>> results,
+        Collection<UUID> requiredNodes
+    ) {
+        if (results == null)
+            return Collections.emptyMap();
+
+        return results.entrySet().stream()
+            .filter(e -> requiredNodes.contains(e.getKey()) && e.getValue() != 
null)
+            .collect(Collectors.toMap(e -> 
kctx.cluster().get().node(e.getKey()), Map.Entry::getValue));
+    }
+
+    /**
+     * @param snpName Snapshot name of the validation process. If {@coe null}, 
ignored.
+     * @param procId  If {@code snpName} is {@code null}, is used to find the 
operation request.
+     * @return Current snapshot checking request by {@code snpName} or {@code 
procId}.
+     */
+    private @Nullable SnapshotCheckProcessRequest curRequest(@Nullable String 
snpName, UUID procId) {

Review Comment:
   AFAIK, we don't use abbreviations in method names. `currentRequest`



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.
+     *
+     * @param th The interrupt reason.
+     * @param rqFilter If not {@code null}, used to filter which 
requests/process to stop. If {@code null}, stops all the validations.
+     */
+    public void interrupt(Throwable th, @Nullable 
Function<SnapshotCheckProcessRequest, Boolean> rqFilter) {
+        if (requests.isEmpty())

Review Comment:
   useless check



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {

Review Comment:
   Let's name it `SnapshotCheckProcess` similar to `SnapshotRestoreProcess`



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.
+     *
+     * @param th The interrupt reason.
+     * @param rqFilter If not {@code null}, used to filter which 
requests/process to stop. If {@code null}, stops all the validations.
+     */
+    public void interrupt(Throwable th, @Nullable 
Function<SnapshotCheckProcessRequest, Boolean> rqFilter) {
+        if (requests.isEmpty())
+            return;
+
+        requests.values().forEach(rq -> {
+            if (rqFilter == null || rqFilter.apply(rq)) {
+                rq.error(th);
+
+                clean(rq.requestId(), th, null, null);
+            }
+        });
+    }
+
+    /** Stops the related validation if the node is a mandatory one. */
+    private void nodeLeft(ClusterNode node) {
+        if (node.isClient() || requests.isEmpty())
+            return;
+
+        interrupt(
+            new ClusterTopologyCheckedException("Snapshot checking stopped. A 
node left the cluster: " + node + '.'),
+            rq -> rq.nodes().contains(node.id())
+        );
+    }
+
+    /** Phase 2 and process finish. */
+    private IgniteInternalFuture<?> reduceValidatePartsAndFinish(
+        UUID procId,
+        Map<UUID, HashMap<PartitionKeyV2, PartitionHashRecordV2>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        clean(procId, null, results, errors);
+
+        return FINISHED_FUT;
+    }
+
+    /** Phase 2 beginning.  */
+    private IgniteInternalFuture<HashMap<PartitionKeyV2, 
PartitionHashRecordV2>> validateParts(

Review Comment:
   Why does it actually `HashMap` and not just a `Map`?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.
+     *
+     * @param th The interrupt reason.
+     * @param rqFilter If not {@code null}, used to filter which 
requests/process to stop. If {@code null}, stops all the validations.
+     */
+    public void interrupt(Throwable th, @Nullable 
Function<SnapshotCheckProcessRequest, Boolean> rqFilter) {
+        if (requests.isEmpty())
+            return;
+
+        requests.values().forEach(rq -> {
+            if (rqFilter == null || rqFilter.apply(rq)) {
+                rq.error(th);
+
+                clean(rq.requestId(), th, null, null);
+            }
+        });
+    }
+
+    /** Stops the related validation if the node is a mandatory one. */
+    private void nodeLeft(ClusterNode node) {
+        if (node.isClient() || requests.isEmpty())
+            return;
+
+        interrupt(
+            new ClusterTopologyCheckedException("Snapshot checking stopped. A 
node left the cluster: " + node + '.'),
+            rq -> rq.nodes().contains(node.id())
+        );
+    }
+
+    /** Phase 2 and process finish. */
+    private IgniteInternalFuture<?> reduceValidatePartsAndFinish(
+        UUID procId,
+        Map<UUID, HashMap<PartitionKeyV2, PartitionHashRecordV2>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        clean(procId, null, results, errors);
+
+        return FINISHED_FUT;
+    }
+
+    /** Phase 2 beginning.  */
+    private IgniteInternalFuture<HashMap<PartitionKeyV2, 
PartitionHashRecordV2>> validateParts(
+        SnapshotCheckProcessRequest incReq) {
+        SnapshotCheckProcessRequest locReq;
+
+        if (stopAndCleanOnError(incReq, null) || (locReq = 
requests.get(incReq.snapshotName())) == null)
+            return FINISHED_FUT;
+
+        assert locReq.equals(incReq);
+
+        // Store metas to collect cluster operation result laster.

Review Comment:
   laster?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.
+     *
+     * @param th The interrupt reason.
+     * @param rqFilter If not {@code null}, used to filter which 
requests/process to stop. If {@code null}, stops all the validations.
+     */
+    public void interrupt(Throwable th, @Nullable 
Function<SnapshotCheckProcessRequest, Boolean> rqFilter) {
+        if (requests.isEmpty())
+            return;
+
+        requests.values().forEach(rq -> {
+            if (rqFilter == null || rqFilter.apply(rq)) {
+                rq.error(th);
+
+                clean(rq.requestId(), th, null, null);
+            }
+        });
+    }
+
+    /** Stops the related validation if the node is a mandatory one. */
+    private void nodeLeft(ClusterNode node) {
+        if (node.isClient() || requests.isEmpty())
+            return;
+
+        interrupt(
+            new ClusterTopologyCheckedException("Snapshot checking stopped. A 
node left the cluster: " + node + '.'),
+            rq -> rq.nodes().contains(node.id())
+        );
+    }
+
+    /** Phase 2 and process finish. */
+    private IgniteInternalFuture<?> reduceValidatePartsAndFinish(
+        UUID procId,
+        Map<UUID, HashMap<PartitionKeyV2, PartitionHashRecordV2>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        clean(procId, null, results, errors);
+
+        return FINISHED_FUT;
+    }
+
+    /** Phase 2 beginning.  */
+    private IgniteInternalFuture<HashMap<PartitionKeyV2, 
PartitionHashRecordV2>> validateParts(
+        SnapshotCheckProcessRequest incReq) {
+        SnapshotCheckProcessRequest locReq;
+
+        if (stopAndCleanOnError(incReq, null) || (locReq = 
requests.get(incReq.snapshotName())) == null)
+            return FINISHED_FUT;
+
+        assert locReq.equals(incReq);
+
+        // Store metas to collect cluster operation result laster.
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
clusterOpFuts.get(incReq.requestId());
+
+        if (clusterOpFut != null)
+            locReq.metas = incReq.metas;
+
+        // Local meta might be null if current node started after the snapshot 
creation or placement.
+        if (!incReq.nodes.contains(kctx.localNodeId()) || locReq.meta() == 
null)
+            return FINISHED_FUT;
+
+        GridFutureAdapter<HashMap<PartitionKeyV2, PartitionHashRecordV2>> 
locPartsChkFut = new GridFutureAdapter<>();
+
+        locReq.fut(locPartsChkFut);
+
+        ExecutorService executor = 
kctx.cache().context().snapshotMgr().snapshotExecutorService();
+
+        executor.submit(() -> stopFutureOnAnyFailure(locPartsChkFut, () -> {
+            // An error can occure when the local future is still null.
+            if (locReq.error() != null)
+                locPartsChkFut.onDone(locReq.error());
+
+            if (locPartsChkFut.isDone())
+                return;
+
+            File snpDir = 
kctx.cache().context().snapshotMgr().snapshotLocalDir(locReq.snapshotName(), 
locReq.snapshotPath());
+
+            try {
+                Map<PartitionKeyV2, PartitionHashRecordV2> res = 
kctx.cache().context().snapshotMgr().checker()
+                    .checkPartitions(locReq.meta(), snpDir, locReq.groups(), 
false, true, false);
+
+                locPartsChkFut.onDone(res instanceof HashMap ? 
(HashMap<PartitionKeyV2, PartitionHashRecordV2>)res
+                    : new HashMap<>(res));
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException("Failed to calculate snapshot 
partition hashes, req: " + incReq, e);
+            }
+
+            // No need to wait to the cealup if current node is just a worker.

Review Comment:
   cealup?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.
+     *
+     * @param th The interrupt reason.
+     * @param rqFilter If not {@code null}, used to filter which 
requests/process to stop. If {@code null}, stops all the validations.
+     */
+    public void interrupt(Throwable th, @Nullable 
Function<SnapshotCheckProcessRequest, Boolean> rqFilter) {
+        if (requests.isEmpty())
+            return;
+
+        requests.values().forEach(rq -> {
+            if (rqFilter == null || rqFilter.apply(rq)) {
+                rq.error(th);
+
+                clean(rq.requestId(), th, null, null);
+            }
+        });
+    }
+
+    /** Stops the related validation if the node is a mandatory one. */
+    private void nodeLeft(ClusterNode node) {
+        if (node.isClient() || requests.isEmpty())
+            return;
+
+        interrupt(
+            new ClusterTopologyCheckedException("Snapshot checking stopped. A 
node left the cluster: " + node + '.'),
+            rq -> rq.nodes().contains(node.id())
+        );
+    }
+
+    /** Phase 2 and process finish. */
+    private IgniteInternalFuture<?> reduceValidatePartsAndFinish(
+        UUID procId,
+        Map<UUID, HashMap<PartitionKeyV2, PartitionHashRecordV2>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        clean(procId, null, results, errors);
+
+        return FINISHED_FUT;
+    }
+
+    /** Phase 2 beginning.  */
+    private IgniteInternalFuture<HashMap<PartitionKeyV2, 
PartitionHashRecordV2>> validateParts(
+        SnapshotCheckProcessRequest incReq) {
+        SnapshotCheckProcessRequest locReq;
+
+        if (stopAndCleanOnError(incReq, null) || (locReq = 
requests.get(incReq.snapshotName())) == null)
+            return FINISHED_FUT;
+
+        assert locReq.equals(incReq);
+
+        // Store metas to collect cluster operation result laster.
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
clusterOpFuts.get(incReq.requestId());
+
+        if (clusterOpFut != null)
+            locReq.metas = incReq.metas;
+
+        // Local meta might be null if current node started after the snapshot 
creation or placement.
+        if (!incReq.nodes.contains(kctx.localNodeId()) || locReq.meta() == 
null)
+            return FINISHED_FUT;
+
+        GridFutureAdapter<HashMap<PartitionKeyV2, PartitionHashRecordV2>> 
locPartsChkFut = new GridFutureAdapter<>();
+
+        locReq.fut(locPartsChkFut);
+
+        ExecutorService executor = 
kctx.cache().context().snapshotMgr().snapshotExecutorService();
+
+        executor.submit(() -> stopFutureOnAnyFailure(locPartsChkFut, () -> {
+            // An error can occure when the local future is still null.
+            if (locReq.error() != null)
+                locPartsChkFut.onDone(locReq.error());
+
+            if (locPartsChkFut.isDone())
+                return;
+
+            File snpDir = 
kctx.cache().context().snapshotMgr().snapshotLocalDir(locReq.snapshotName(), 
locReq.snapshotPath());
+
+            try {
+                Map<PartitionKeyV2, PartitionHashRecordV2> res = 
kctx.cache().context().snapshotMgr().checker()
+                    .checkPartitions(locReq.meta(), snpDir, locReq.groups(), 
false, true, false);
+
+                locPartsChkFut.onDone(res instanceof HashMap ? 
(HashMap<PartitionKeyV2, PartitionHashRecordV2>)res
+                    : new HashMap<>(res));
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException("Failed to calculate snapshot 
partition hashes, req: " + incReq, e);
+            }
+
+            // No need to wait to the cealup if current node is just a worker.
+            if (!kctx.localNodeId().equals(locReq.opCoordId) && clusterOpFut 
== null)
+                clean(locReq.reqId, null, null, null);
+        }));
+
+        return locPartsChkFut;
+    }
+
+    /**
+     * If required, stops and clean related validation if errors occured
+     *
+     * @return {@code True} if the validation stopped and cleaned. {@code 
False} otherwise.
+     */
+    private boolean stopAndCleanOnError(SnapshotCheckProcessRequest req,
+        @Nullable Map<UUID, Throwable> occuredErrors) {
+        assert req != null;
+
+        if (!F.isEmpty(occuredErrors)) {
+            occuredErrors = occuredErrors.entrySet().stream()
+                .filter(e -> 
req.nodes.contains(e.getKey())).collect(Collectors.toMap(Map.Entry::getKey, 
Map.Entry::getValue));
+        }
+
+        if (F.isEmpty(occuredErrors) && req.error() == null)
+            return false;
+
+        clean(req.requestId(), req.error(), null, occuredErrors);
+
+        return true;
+    }
+
+    /** Cleans certain snapshot validation. */
+    private void clean(
+        UUID rqId,
+        @Nullable Throwable opErr,
+        @Nullable Map<UUID, ? extends Map<PartitionKeyV2, 
PartitionHashRecordV2>> results,
+        @Nullable Map<UUID, Throwable> errors
+    ) {
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
clusterOpFuts.remove(rqId);
+
+        stopFutureOnAnyFailure(clusterOpFut, () -> {
+            SnapshotCheckProcessRequest locRq = curRequest(null, rqId);
+
+            Throwable err = opErr;
+
+            if (locRq != null)
+                err = stopAndCleanLocRequest(locRq, err);
+
+            if (clusterOpFut == null || clusterOpFut.isDone())
+                return;
+
+            boolean finished;
+
+            // Nodes' results and errors reducing is available on a required 
node where the process request must be registered.
+            assert (F.isEmpty(errors) && F.isEmpty(results)) || locRq != null;
+
+            Map<ClusterNode, Exception> errors0 = locRq == null || 
F.isEmpty(errors)
+                ? Collections.emptyMap()
+                : collectErrors(errors, locRq.nodes());
+
+            if (err == null && !F.isEmpty(results)) {
+                Map<ClusterNode, Map<PartitionKeyV2, PartitionHashRecordV2>> 
results0 = collecPartsHashes(results, locRq.nodes());
+
+                IdleVerifyResultV2 chkRes = 
SnapshotChecker.reduceHashesResults(results0, errors0);
+
+                finished = clusterOpFut.onDone(new 
SnapshotPartitionsVerifyTaskResult(locRq.metas, chkRes));
+            }
+            else
+                finished = finishClusterFutureWithErr(clusterOpFut, err, 
errors0);
+
+            if (finished && log.isInfoEnabled())
+                log.info("Snapshot validation process finished, req: " + locRq 
+ '.');
+        });
+    }
+
+    /** */
+    private Throwable stopAndCleanLocRequest(SnapshotCheckProcessRequest 
locRq, @Nullable Throwable err) {
+        if (err == null && locRq.error() != null)
+            err = locRq.error();
+
+        GridFutureAdapter<?> locWorkingFut = locRq.fut();
+
+        boolean finished = false;
+
+        // Try to stop local working future ASAP.
+        if (locWorkingFut != null)
+            finished = err == null ? locWorkingFut.onDone() : 
locWorkingFut.onDone(err);
+
+        requests.remove(locRq.snapshotName());
+
+        if (finished && log.isInfoEnabled())
+            log.info("Finished snapshot local validation, req: " + locRq + 
'.');
+
+        return err;
+    }
+
+    /** */
+    private Map<ClusterNode, Exception> collectErrors(Map<UUID, Throwable> 
errors, Set<UUID> requiredNodes) {
+        if (errors.isEmpty())
+            return Collections.emptyMap();
+
+        return errors.entrySet().stream().filter(e -> 
requiredNodes.contains(e.getKey()) && e.getValue() != null)
+            .collect(Collectors.toMap(e -> 
kctx.cluster().get().node(e.getKey()), e -> asException(e.getValue())));
+    }
+
+    /** */
+    private Map<ClusterNode, Map<PartitionKeyV2, PartitionHashRecordV2>> 
collecPartsHashes(
+        @Nullable Map<UUID, ? extends Map<PartitionKeyV2, 
PartitionHashRecordV2>> results,
+        Collection<UUID> requiredNodes
+    ) {
+        if (results == null)
+            return Collections.emptyMap();
+
+        return results.entrySet().stream()
+            .filter(e -> requiredNodes.contains(e.getKey()) && e.getValue() != 
null)
+            .collect(Collectors.toMap(e -> 
kctx.cluster().get().node(e.getKey()), Map.Entry::getValue));
+    }
+
+    /**
+     * @param snpName Snapshot name of the validation process. If {@coe null}, 
ignored.
+     * @param procId  If {@code snpName} is {@code null}, is used to find the 
operation request.
+     * @return Current snapshot checking request by {@code snpName} or {@code 
procId}.
+     */
+    private @Nullable SnapshotCheckProcessRequest curRequest(@Nullable String 
snpName, UUID procId) {
+        return snpName == null
+            ? requests.values().stream().filter(rq -> 
rq.requestId().equals(procId)).findFirst().orElse(null)
+            : requests.get(snpName);
+    }
+
+    /** Phase 1 beginning: prepare, collect and check local metas. */
+    private IgniteInternalFuture<ArrayList<SnapshotMetadata>> 
prepareAndCheckMetas(SnapshotCheckProcessRequest extReq) {
+        SnapshotCheckProcessRequest locReq = 
requests.computeIfAbsent(extReq.snapshotName(), snpName -> extReq);
+
+        if (!locReq.equals(extReq)) {
+            Throwable err = new IllegalStateException("Validation of snapshot 
'" + extReq.snapshotName()
+                + "' has already started. Request=" + locReq + '.');
+
+            clean(extReq.requestId(), err, null, null);
+
+            return new GridFinishedFuture<>(err);
+        }
+
+        if (!extReq.nodes.contains(kctx.localNodeId())) {
+            if (log.isDebugEnabled()) {
+                log.debug("Skipping snapshot local metadatas collecting for 
snapshot validation, request=" + extReq
+                    + ". Current node is not required.");
+            }
+
+            return FINISHED_FUT;
+        }
+
+        GridFutureAdapter<ArrayList<SnapshotMetadata>> locMetasChkFut = new 
GridFutureAdapter<>();
+
+        assert locReq.fut() == null;
+
+        locReq.fut(locMetasChkFut);
+
+        IgniteSnapshotManager snpMgr = kctx.cache().context().snapshotMgr();
+
+        snpMgr.snapshotExecutorService().submit(() -> 
stopFutureOnAnyFailure(locMetasChkFut, () -> {
+            if (log.isDebugEnabled())
+                log.debug("Checking local snapshot metadatas. Request=" + 
locReq + '.');
+
+            Collection<Integer> grpIds = F.isEmpty(locReq.groups()) ? null : 
F.viewReadOnly(locReq.groups(), CU::cacheId);
+
+            // An error can occure when the local future is still null.
+            if (locReq.error() != null)
+                locMetasChkFut.onDone(locReq.error());
+
+            if (locMetasChkFut.isDone())
+                return;
+
+            List<SnapshotMetadata> locMetas = snpMgr.checker().checkLocalMetas(
+                snpMgr.snapshotLocalDir(locReq.snapshotName(), 
locReq.snapshotPath()),
+                grpIds,
+                kctx.cluster().get().localNode().consistentId()
+            );
+
+            if (!F.isEmpty(locMetas))
+                locReq.meta(locMetas.get(0));
+
+            if (!(locMetas instanceof ArrayList))
+                locMetas = new ArrayList<>(locMetas);
+
+            // A node might have already gone before this. No need to proceed.
+            Throwable locRqErr = locReq.error();
+
+            if (locRqErr != null)
+                locMetasChkFut.onDone(locRqErr);
+            else
+                locMetasChkFut.onDone((ArrayList<SnapshotMetadata>)locMetas);
+        }));
+
+        return locMetasChkFut;
+    }
+
+    /** Phase 1 end. */
+    private void reducePreparationAndMetasCheck(
+        UUID procId,
+        Map<UUID, ? extends List<SnapshotMetadata>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        SnapshotCheckProcessRequest locReq = curRequest(snpName(results), 
procId);
+
+        assert locReq == null || locReq.opCoordId != null;
+
+        if (locReq == null || stopAndCleanOnError(locReq, errors) || 
!kctx.localNodeId().equals(locReq.opCoordId))
+            return;
+
+        Throwable stopClusterProcErr = null;
+
+        try {
+            assert !F.isEmpty(results) || !F.isEmpty(errors) || locReq.error() 
!= null;
+
+            if (locReq.error() != null)
+                throw locReq.error();
+
+            locReq.metas = new HashMap<>();
+
+            Map<ClusterNode, Exception> errs = new HashMap<>();
+
+            results.forEach((nodeId, metas) -> {
+                // A node might be non-baseline (not required).
+                if (locReq.nodes.contains(nodeId)) {
+                    assert kctx.cluster().get().node(nodeId) != null;
+
+                    locReq.metas.put(kctx.cluster().get().node(nodeId), metas);
+                }
+            });
+
+            errors.forEach((nodeId, nodeErr) -> {
+                // A node might be non-baseline (not required).
+                if (locReq.nodes.contains(nodeId)) {
+                    assert kctx.cluster().get().node(nodeId) != null;
+                    assert nodeErr != null;
+
+                    errs.put(kctx.cluster().get().node(nodeId), 
asException(nodeErr));
+                }
+            });
+
+            SnapshotMetadataVerificationTaskResult metasRes = new 
SnapshotMetadataVerificationTaskResult(
+                locReq.metas,
+                SnapshotChecker.reduceMetasResults(locReq.snapshotName(), 
locReq.snapshotPath(), locReq.metas, errs,
+                    kctx.cluster().get().localNode().consistentId())
+            );
+
+            if (!F.isEmpty(metasRes.exceptions()))
+                stopClusterProcErr = new 
IgniteSnapshotVerifyException(metasRes.exceptions());
+        }
+        catch (Throwable th) {
+            stopClusterProcErr = th;
+        }
+
+        if (stopClusterProcErr != null)
+            locReq.error(stopClusterProcErr);
+
+        phase2PartsHashes.start(procId, locReq);
+
+        if (log.isDebugEnabled())
+            log.debug("Started partitions validation as part of the snapshot 
checking. Request=" + locReq + '.');
+    }
+
+    /** Finds current snapshot name from the metas. */
+    private @Nullable String snpName(@Nullable Map<UUID, ? extends 
List<SnapshotMetadata>> metas) {
+        if (F.isEmpty(metas))
+            return null;
+
+        // Ensure the same snapshot name or empty.
+        assert 
F.flatCollections(metas.values().stream().filter(Objects::nonNull).collect(Collectors.toList()))
+            
.stream().map(SnapshotMetadata::snapshotName).collect(Collectors.toSet()).size()
 < 2
+            : "Empty or not unique snapshot names in the snapshot metadatas.";
+
+        for (List<SnapshotMetadata> nodeMetas : metas.values()) {
+            if (F.isEmpty(nodeMetas))
+                continue;
+
+            assert nodeMetas.get(0) != null : "Empty snapshot metadata in the 
results";
+            assert !F.isEmpty(nodeMetas.get(0).snapshotName()) : "Empty 
snapshot name in a snapshot metadata.";
+
+            return nodeMetas.get(0).snapshotName();
+        }
+
+        return null;
+    }
+
+    /** Starts the snapshot full validation. */
+    public IgniteInternalFuture<SnapshotPartitionsVerifyTaskResult> start(
+        String snpName,
+        @Nullable String snpPath,
+        @Nullable Collection<String> grpNames,
+        boolean inclCstHndlrs
+    ) {
+        assert !F.isEmpty(snpName);
+
+        UUID rqId = UUID.randomUUID();
+
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
new GridFutureAdapter<>();
+
+        clusterOpFut.listen(fut -> clusterOpFuts.remove(rqId));
+
+        stopFutureOnAnyFailure(clusterOpFut, () -> {
+            List<UUID> requiredNodes = new 
ArrayList<>(F.viewReadOnly(kctx.discovery().discoCache().aliveBaselineNodes(), 
F.node2id()));
+
+            SnapshotCheckProcessRequest req = new SnapshotCheckProcessRequest(
+                rqId,
+                kctx.localNodeId(),
+                requiredNodes,
+                
requiredNodes.get(ThreadLocalRandom.current().nextInt(requiredNodes.size())),
+                snpName,
+                snpPath,
+                grpNames,
+                0,
+                inclCstHndlrs,
+                true
+            );
+
+            phase1CheckMetas.start(req.requestId(), req);
+
+            clusterOpFuts.put(rqId, clusterOpFut);
+        });
+
+        return clusterOpFut;
+    }
+
+    /**
+     * Ensures thta the future is stopped if any failure occures.
+     *
+     * @param fut Future to stop. If {@code null}, ignored.
+     * @param action Related action to launch and watch.
+     */
+    private static void stopFutureOnAnyFailure(@Nullable GridFutureAdapter<?> 
fut, Runnable action) {
+        if (fut == null) {
+            action.run();
+
+            return;
+        }
+
+        try {
+            action.run();

Review Comment:
   Code duplication.
   
   ```
   try {
       action.run();
   }
   catch (Throwable th) {
       if (fut != null)
           fut.onDone(th);
   }
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.
+     *
+     * @param th The interrupt reason.
+     * @param rqFilter If not {@code null}, used to filter which 
requests/process to stop. If {@code null}, stops all the validations.
+     */
+    public void interrupt(Throwable th, @Nullable 
Function<SnapshotCheckProcessRequest, Boolean> rqFilter) {
+        if (requests.isEmpty())
+            return;
+
+        requests.values().forEach(rq -> {
+            if (rqFilter == null || rqFilter.apply(rq)) {
+                rq.error(th);
+
+                clean(rq.requestId(), th, null, null);
+            }
+        });
+    }
+
+    /** Stops the related validation if the node is a mandatory one. */
+    private void nodeLeft(ClusterNode node) {
+        if (node.isClient() || requests.isEmpty())
+            return;
+
+        interrupt(
+            new ClusterTopologyCheckedException("Snapshot checking stopped. A 
node left the cluster: " + node + '.'),
+            rq -> rq.nodes().contains(node.id())
+        );
+    }
+
+    /** Phase 2 and process finish. */
+    private IgniteInternalFuture<?> reduceValidatePartsAndFinish(
+        UUID procId,
+        Map<UUID, HashMap<PartitionKeyV2, PartitionHashRecordV2>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        clean(procId, null, results, errors);
+
+        return FINISHED_FUT;
+    }
+
+    /** Phase 2 beginning.  */
+    private IgniteInternalFuture<HashMap<PartitionKeyV2, 
PartitionHashRecordV2>> validateParts(
+        SnapshotCheckProcessRequest incReq) {
+        SnapshotCheckProcessRequest locReq;
+
+        if (stopAndCleanOnError(incReq, null) || (locReq = 
requests.get(incReq.snapshotName())) == null)
+            return FINISHED_FUT;
+
+        assert locReq.equals(incReq);
+
+        // Store metas to collect cluster operation result laster.
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
clusterOpFuts.get(incReq.requestId());
+
+        if (clusterOpFut != null)
+            locReq.metas = incReq.metas;
+
+        // Local meta might be null if current node started after the snapshot 
creation or placement.
+        if (!incReq.nodes.contains(kctx.localNodeId()) || locReq.meta() == 
null)
+            return FINISHED_FUT;
+
+        GridFutureAdapter<HashMap<PartitionKeyV2, PartitionHashRecordV2>> 
locPartsChkFut = new GridFutureAdapter<>();
+
+        locReq.fut(locPartsChkFut);
+
+        ExecutorService executor = 
kctx.cache().context().snapshotMgr().snapshotExecutorService();
+
+        executor.submit(() -> stopFutureOnAnyFailure(locPartsChkFut, () -> {
+            // An error can occure when the local future is still null.
+            if (locReq.error() != null)
+                locPartsChkFut.onDone(locReq.error());
+
+            if (locPartsChkFut.isDone())
+                return;
+
+            File snpDir = 
kctx.cache().context().snapshotMgr().snapshotLocalDir(locReq.snapshotName(), 
locReq.snapshotPath());
+
+            try {
+                Map<PartitionKeyV2, PartitionHashRecordV2> res = 
kctx.cache().context().snapshotMgr().checker()
+                    .checkPartitions(locReq.meta(), snpDir, locReq.groups(), 
false, true, false);
+
+                locPartsChkFut.onDone(res instanceof HashMap ? 
(HashMap<PartitionKeyV2, PartitionHashRecordV2>)res
+                    : new HashMap<>(res));
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException("Failed to calculate snapshot 
partition hashes, req: " + incReq, e);
+            }
+
+            // No need to wait to the cealup if current node is just a worker.
+            if (!kctx.localNodeId().equals(locReq.opCoordId) && clusterOpFut 
== null)
+                clean(locReq.reqId, null, null, null);
+        }));
+
+        return locPartsChkFut;
+    }
+
+    /**
+     * If required, stops and clean related validation if errors occured
+     *
+     * @return {@code True} if the validation stopped and cleaned. {@code 
False} otherwise.
+     */
+    private boolean stopAndCleanOnError(SnapshotCheckProcessRequest req,
+        @Nullable Map<UUID, Throwable> occuredErrors) {
+        assert req != null;
+
+        if (!F.isEmpty(occuredErrors)) {
+            occuredErrors = occuredErrors.entrySet().stream()
+                .filter(e -> 
req.nodes.contains(e.getKey())).collect(Collectors.toMap(Map.Entry::getKey, 
Map.Entry::getValue));
+        }
+
+        if (F.isEmpty(occuredErrors) && req.error() == null)
+            return false;
+
+        clean(req.requestId(), req.error(), null, occuredErrors);
+
+        return true;
+    }
+
+    /** Cleans certain snapshot validation. */
+    private void clean(
+        UUID rqId,
+        @Nullable Throwable opErr,
+        @Nullable Map<UUID, ? extends Map<PartitionKeyV2, 
PartitionHashRecordV2>> results,
+        @Nullable Map<UUID, Throwable> errors
+    ) {
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
clusterOpFuts.remove(rqId);
+
+        stopFutureOnAnyFailure(clusterOpFut, () -> {
+            SnapshotCheckProcessRequest locRq = curRequest(null, rqId);
+
+            Throwable err = opErr;
+
+            if (locRq != null)
+                err = stopAndCleanLocRequest(locRq, err);
+
+            if (clusterOpFut == null || clusterOpFut.isDone())
+                return;
+
+            boolean finished;
+
+            // Nodes' results and errors reducing is available on a required 
node where the process request must be registered.
+            assert (F.isEmpty(errors) && F.isEmpty(results)) || locRq != null;
+
+            Map<ClusterNode, Exception> errors0 = locRq == null || 
F.isEmpty(errors)
+                ? Collections.emptyMap()
+                : collectErrors(errors, locRq.nodes());
+
+            if (err == null && !F.isEmpty(results)) {
+                Map<ClusterNode, Map<PartitionKeyV2, PartitionHashRecordV2>> 
results0 = collecPartsHashes(results, locRq.nodes());
+
+                IdleVerifyResultV2 chkRes = 
SnapshotChecker.reduceHashesResults(results0, errors0);
+
+                finished = clusterOpFut.onDone(new 
SnapshotPartitionsVerifyTaskResult(locRq.metas, chkRes));
+            }
+            else
+                finished = finishClusterFutureWithErr(clusterOpFut, err, 
errors0);
+
+            if (finished && log.isInfoEnabled())
+                log.info("Snapshot validation process finished, req: " + locRq 
+ '.');
+        });
+    }
+
+    /** */
+    private Throwable stopAndCleanLocRequest(SnapshotCheckProcessRequest 
locRq, @Nullable Throwable err) {
+        if (err == null && locRq.error() != null)
+            err = locRq.error();
+
+        GridFutureAdapter<?> locWorkingFut = locRq.fut();
+
+        boolean finished = false;
+
+        // Try to stop local working future ASAP.
+        if (locWorkingFut != null)
+            finished = err == null ? locWorkingFut.onDone() : 
locWorkingFut.onDone(err);
+
+        requests.remove(locRq.snapshotName());
+
+        if (finished && log.isInfoEnabled())
+            log.info("Finished snapshot local validation, req: " + locRq + 
'.');
+
+        return err;
+    }
+
+    /** */
+    private Map<ClusterNode, Exception> collectErrors(Map<UUID, Throwable> 
errors, Set<UUID> requiredNodes) {
+        if (errors.isEmpty())
+            return Collections.emptyMap();
+
+        return errors.entrySet().stream().filter(e -> 
requiredNodes.contains(e.getKey()) && e.getValue() != null)
+            .collect(Collectors.toMap(e -> 
kctx.cluster().get().node(e.getKey()), e -> asException(e.getValue())));
+    }
+
+    /** */
+    private Map<ClusterNode, Map<PartitionKeyV2, PartitionHashRecordV2>> 
collecPartsHashes(
+        @Nullable Map<UUID, ? extends Map<PartitionKeyV2, 
PartitionHashRecordV2>> results,
+        Collection<UUID> requiredNodes
+    ) {
+        if (results == null)
+            return Collections.emptyMap();
+
+        return results.entrySet().stream()
+            .filter(e -> requiredNodes.contains(e.getKey()) && e.getValue() != 
null)
+            .collect(Collectors.toMap(e -> 
kctx.cluster().get().node(e.getKey()), Map.Entry::getValue));
+    }
+
+    /**
+     * @param snpName Snapshot name of the validation process. If {@coe null}, 
ignored.
+     * @param procId  If {@code snpName} is {@code null}, is used to find the 
operation request.
+     * @return Current snapshot checking request by {@code snpName} or {@code 
procId}.
+     */
+    private @Nullable SnapshotCheckProcessRequest curRequest(@Nullable String 
snpName, UUID procId) {
+        return snpName == null
+            ? requests.values().stream().filter(rq -> 
rq.requestId().equals(procId)).findFirst().orElse(null)
+            : requests.get(snpName);
+    }
+
+    /** Phase 1 beginning: prepare, collect and check local metas. */
+    private IgniteInternalFuture<ArrayList<SnapshotMetadata>> 
prepareAndCheckMetas(SnapshotCheckProcessRequest extReq) {
+        SnapshotCheckProcessRequest locReq = 
requests.computeIfAbsent(extReq.snapshotName(), snpName -> extReq);
+
+        if (!locReq.equals(extReq)) {
+            Throwable err = new IllegalStateException("Validation of snapshot 
'" + extReq.snapshotName()
+                + "' has already started. Request=" + locReq + '.');
+
+            clean(extReq.requestId(), err, null, null);
+
+            return new GridFinishedFuture<>(err);
+        }
+
+        if (!extReq.nodes.contains(kctx.localNodeId())) {
+            if (log.isDebugEnabled()) {
+                log.debug("Skipping snapshot local metadatas collecting for 
snapshot validation, request=" + extReq
+                    + ". Current node is not required.");
+            }
+
+            return FINISHED_FUT;
+        }
+
+        GridFutureAdapter<ArrayList<SnapshotMetadata>> locMetasChkFut = new 
GridFutureAdapter<>();
+
+        assert locReq.fut() == null;
+
+        locReq.fut(locMetasChkFut);
+
+        IgniteSnapshotManager snpMgr = kctx.cache().context().snapshotMgr();
+
+        snpMgr.snapshotExecutorService().submit(() -> 
stopFutureOnAnyFailure(locMetasChkFut, () -> {
+            if (log.isDebugEnabled())
+                log.debug("Checking local snapshot metadatas. Request=" + 
locReq + '.');
+
+            Collection<Integer> grpIds = F.isEmpty(locReq.groups()) ? null : 
F.viewReadOnly(locReq.groups(), CU::cacheId);
+
+            // An error can occure when the local future is still null.
+            if (locReq.error() != null)
+                locMetasChkFut.onDone(locReq.error());
+
+            if (locMetasChkFut.isDone())
+                return;
+
+            List<SnapshotMetadata> locMetas = snpMgr.checker().checkLocalMetas(
+                snpMgr.snapshotLocalDir(locReq.snapshotName(), 
locReq.snapshotPath()),
+                grpIds,
+                kctx.cluster().get().localNode().consistentId()
+            );
+
+            if (!F.isEmpty(locMetas))
+                locReq.meta(locMetas.get(0));
+
+            if (!(locMetas instanceof ArrayList))
+                locMetas = new ArrayList<>(locMetas);
+
+            // A node might have already gone before this. No need to proceed.
+            Throwable locRqErr = locReq.error();
+
+            if (locRqErr != null)
+                locMetasChkFut.onDone(locRqErr);
+            else
+                locMetasChkFut.onDone((ArrayList<SnapshotMetadata>)locMetas);
+        }));
+
+        return locMetasChkFut;
+    }
+
+    /** Phase 1 end. */
+    private void reducePreparationAndMetasCheck(
+        UUID procId,
+        Map<UUID, ? extends List<SnapshotMetadata>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        SnapshotCheckProcessRequest locReq = curRequest(snpName(results), 
procId);
+
+        assert locReq == null || locReq.opCoordId != null;
+
+        if (locReq == null || stopAndCleanOnError(locReq, errors) || 
!kctx.localNodeId().equals(locReq.opCoordId))
+            return;
+
+        Throwable stopClusterProcErr = null;
+
+        try {
+            assert !F.isEmpty(results) || !F.isEmpty(errors) || locReq.error() 
!= null;
+
+            if (locReq.error() != null)
+                throw locReq.error();
+
+            locReq.metas = new HashMap<>();
+
+            Map<ClusterNode, Exception> errs = new HashMap<>();
+
+            results.forEach((nodeId, metas) -> {
+                // A node might be non-baseline (not required).
+                if (locReq.nodes.contains(nodeId)) {
+                    assert kctx.cluster().get().node(nodeId) != null;
+
+                    locReq.metas.put(kctx.cluster().get().node(nodeId), metas);
+                }
+            });
+
+            errors.forEach((nodeId, nodeErr) -> {
+                // A node might be non-baseline (not required).
+                if (locReq.nodes.contains(nodeId)) {
+                    assert kctx.cluster().get().node(nodeId) != null;
+                    assert nodeErr != null;
+
+                    errs.put(kctx.cluster().get().node(nodeId), 
asException(nodeErr));
+                }
+            });
+
+            SnapshotMetadataVerificationTaskResult metasRes = new 
SnapshotMetadataVerificationTaskResult(
+                locReq.metas,
+                SnapshotChecker.reduceMetasResults(locReq.snapshotName(), 
locReq.snapshotPath(), locReq.metas, errs,
+                    kctx.cluster().get().localNode().consistentId())
+            );
+
+            if (!F.isEmpty(metasRes.exceptions()))
+                stopClusterProcErr = new 
IgniteSnapshotVerifyException(metasRes.exceptions());
+        }
+        catch (Throwable th) {
+            stopClusterProcErr = th;
+        }
+
+        if (stopClusterProcErr != null)
+            locReq.error(stopClusterProcErr);
+
+        phase2PartsHashes.start(procId, locReq);
+
+        if (log.isDebugEnabled())
+            log.debug("Started partitions validation as part of the snapshot 
checking. Request=" + locReq + '.');
+    }
+
+    /** Finds current snapshot name from the metas. */
+    private @Nullable String snpName(@Nullable Map<UUID, ? extends 
List<SnapshotMetadata>> metas) {
+        if (F.isEmpty(metas))
+            return null;
+
+        // Ensure the same snapshot name or empty.
+        assert 
F.flatCollections(metas.values().stream().filter(Objects::nonNull).collect(Collectors.toList()))
+            
.stream().map(SnapshotMetadata::snapshotName).collect(Collectors.toSet()).size()
 < 2
+            : "Empty or not unique snapshot names in the snapshot metadatas.";
+
+        for (List<SnapshotMetadata> nodeMetas : metas.values()) {
+            if (F.isEmpty(nodeMetas))
+                continue;
+
+            assert nodeMetas.get(0) != null : "Empty snapshot metadata in the 
results";
+            assert !F.isEmpty(nodeMetas.get(0).snapshotName()) : "Empty 
snapshot name in a snapshot metadata.";
+
+            return nodeMetas.get(0).snapshotName();
+        }
+
+        return null;
+    }
+
+    /** Starts the snapshot full validation. */
+    public IgniteInternalFuture<SnapshotPartitionsVerifyTaskResult> start(
+        String snpName,
+        @Nullable String snpPath,
+        @Nullable Collection<String> grpNames,
+        boolean inclCstHndlrs
+    ) {
+        assert !F.isEmpty(snpName);
+
+        UUID rqId = UUID.randomUUID();
+
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
new GridFutureAdapter<>();
+
+        clusterOpFut.listen(fut -> clusterOpFuts.remove(rqId));
+
+        stopFutureOnAnyFailure(clusterOpFut, () -> {
+            List<UUID> requiredNodes = new 
ArrayList<>(F.viewReadOnly(kctx.discovery().discoCache().aliveBaselineNodes(), 
F.node2id()));
+
+            SnapshotCheckProcessRequest req = new SnapshotCheckProcessRequest(
+                rqId,
+                kctx.localNodeId(),
+                requiredNodes,
+                
requiredNodes.get(ThreadLocalRandom.current().nextInt(requiredNodes.size())),
+                snpName,
+                snpPath,
+                grpNames,
+                0,
+                inclCstHndlrs,
+                true
+            );
+
+            phase1CheckMetas.start(req.requestId(), req);
+
+            clusterOpFuts.put(rqId, clusterOpFut);
+        });
+
+        return clusterOpFut;
+    }
+
+    /**
+     * Ensures thta the future is stopped if any failure occures.
+     *
+     * @param fut Future to stop. If {@code null}, ignored.
+     * @param action Related action to launch and watch.
+     */
+    private static void stopFutureOnAnyFailure(@Nullable GridFutureAdapter<?> 
fut, Runnable action) {
+        if (fut == null) {
+            action.run();
+
+            return;
+        }
+
+        try {
+            action.run();

Review Comment:
   Also, it looks like that the `fut` is never `null`



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotFullCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.management.cache.VerifyBackupPartitionsTaskV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot full checking (with the partition hashes). 
*/
+public class SnapshotFullCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotFullCheckOperationRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotFullCheckOperationRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotFullCheckOperationRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotFullCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.

Review Comment:
   passed?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();

Review Comment:
   Let's make the field private and provide a method for getting all current 
requests.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.
+     *
+     * @param th The interrupt reason.
+     * @param rqFilter If not {@code null}, used to filter which 
requests/process to stop. If {@code null}, stops all the validations.
+     */
+    public void interrupt(Throwable th, @Nullable 
Function<SnapshotCheckProcessRequest, Boolean> rqFilter) {
+        if (requests.isEmpty())
+            return;
+
+        requests.values().forEach(rq -> {
+            if (rqFilter == null || rqFilter.apply(rq)) {
+                rq.error(th);
+
+                clean(rq.requestId(), th, null, null);
+            }
+        });
+    }
+
+    /** Stops the related validation if the node is a mandatory one. */
+    private void nodeLeft(ClusterNode node) {
+        if (node.isClient() || requests.isEmpty())
+            return;
+
+        interrupt(
+            new ClusterTopologyCheckedException("Snapshot checking stopped. A 
node left the cluster: " + node + '.'),
+            rq -> rq.nodes().contains(node.id())
+        );
+    }
+
+    /** Phase 2 and process finish. */
+    private IgniteInternalFuture<?> reduceValidatePartsAndFinish(
+        UUID procId,
+        Map<UUID, HashMap<PartitionKeyV2, PartitionHashRecordV2>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        clean(procId, null, results, errors);
+
+        return FINISHED_FUT;
+    }
+
+    /** Phase 2 beginning.  */
+    private IgniteInternalFuture<HashMap<PartitionKeyV2, 
PartitionHashRecordV2>> validateParts(
+        SnapshotCheckProcessRequest incReq) {

Review Comment:
   What does `incReq` mean?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.
+     *
+     * @param th The interrupt reason.
+     * @param rqFilter If not {@code null}, used to filter which 
requests/process to stop. If {@code null}, stops all the validations.
+     */
+    public void interrupt(Throwable th, @Nullable 
Function<SnapshotCheckProcessRequest, Boolean> rqFilter) {
+        if (requests.isEmpty())
+            return;
+
+        requests.values().forEach(rq -> {
+            if (rqFilter == null || rqFilter.apply(rq)) {
+                rq.error(th);
+
+                clean(rq.requestId(), th, null, null);
+            }
+        });
+    }
+
+    /** Stops the related validation if the node is a mandatory one. */
+    private void nodeLeft(ClusterNode node) {
+        if (node.isClient() || requests.isEmpty())
+            return;
+
+        interrupt(
+            new ClusterTopologyCheckedException("Snapshot checking stopped. A 
node left the cluster: " + node + '.'),
+            rq -> rq.nodes().contains(node.id())
+        );
+    }
+
+    /** Phase 2 and process finish. */
+    private IgniteInternalFuture<?> reduceValidatePartsAndFinish(
+        UUID procId,
+        Map<UUID, HashMap<PartitionKeyV2, PartitionHashRecordV2>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        clean(procId, null, results, errors);
+
+        return FINISHED_FUT;
+    }
+
+    /** Phase 2 beginning.  */
+    private IgniteInternalFuture<HashMap<PartitionKeyV2, 
PartitionHashRecordV2>> validateParts(
+        SnapshotCheckProcessRequest incReq) {
+        SnapshotCheckProcessRequest locReq;
+
+        if (stopAndCleanOnError(incReq, null) || (locReq = 
requests.get(incReq.snapshotName())) == null)
+            return FINISHED_FUT;
+
+        assert locReq.equals(incReq);
+
+        // Store metas to collect cluster operation result laster.
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
clusterOpFuts.get(incReq.requestId());
+
+        if (clusterOpFut != null)
+            locReq.metas = incReq.metas;
+
+        // Local meta might be null if current node started after the snapshot 
creation or placement.
+        if (!incReq.nodes.contains(kctx.localNodeId()) || locReq.meta() == 
null)
+            return FINISHED_FUT;
+
+        GridFutureAdapter<HashMap<PartitionKeyV2, PartitionHashRecordV2>> 
locPartsChkFut = new GridFutureAdapter<>();
+
+        locReq.fut(locPartsChkFut);
+
+        ExecutorService executor = 
kctx.cache().context().snapshotMgr().snapshotExecutorService();
+
+        executor.submit(() -> stopFutureOnAnyFailure(locPartsChkFut, () -> {
+            // An error can occure when the local future is still null.
+            if (locReq.error() != null)
+                locPartsChkFut.onDone(locReq.error());
+
+            if (locPartsChkFut.isDone())
+                return;
+
+            File snpDir = 
kctx.cache().context().snapshotMgr().snapshotLocalDir(locReq.snapshotName(), 
locReq.snapshotPath());
+
+            try {
+                Map<PartitionKeyV2, PartitionHashRecordV2> res = 
kctx.cache().context().snapshotMgr().checker()
+                    .checkPartitions(locReq.meta(), snpDir, locReq.groups(), 
false, true, false);
+
+                locPartsChkFut.onDone(res instanceof HashMap ? 
(HashMap<PartitionKeyV2, PartitionHashRecordV2>)res
+                    : new HashMap<>(res));
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException("Failed to calculate snapshot 
partition hashes, req: " + incReq, e);
+            }
+
+            // No need to wait to the cealup if current node is just a worker.
+            if (!kctx.localNodeId().equals(locReq.opCoordId) && clusterOpFut 
== null)
+                clean(locReq.reqId, null, null, null);
+        }));
+
+        return locPartsChkFut;
+    }
+
+    /**
+     * If required, stops and clean related validation if errors occured
+     *
+     * @return {@code True} if the validation stopped and cleaned. {@code 
False} otherwise.
+     */
+    private boolean stopAndCleanOnError(SnapshotCheckProcessRequest req,
+        @Nullable Map<UUID, Throwable> occuredErrors) {
+        assert req != null;
+
+        if (!F.isEmpty(occuredErrors)) {
+            occuredErrors = occuredErrors.entrySet().stream()
+                .filter(e -> 
req.nodes.contains(e.getKey())).collect(Collectors.toMap(Map.Entry::getKey, 
Map.Entry::getValue));
+        }
+
+        if (F.isEmpty(occuredErrors) && req.error() == null)
+            return false;
+
+        clean(req.requestId(), req.error(), null, occuredErrors);
+
+        return true;
+    }
+
+    /** Cleans certain snapshot validation. */
+    private void clean(
+        UUID rqId,
+        @Nullable Throwable opErr,
+        @Nullable Map<UUID, ? extends Map<PartitionKeyV2, 
PartitionHashRecordV2>> results,
+        @Nullable Map<UUID, Throwable> errors
+    ) {
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
clusterOpFuts.remove(rqId);
+
+        stopFutureOnAnyFailure(clusterOpFut, () -> {
+            SnapshotCheckProcessRequest locRq = curRequest(null, rqId);
+
+            Throwable err = opErr;
+
+            if (locRq != null)
+                err = stopAndCleanLocRequest(locRq, err);
+
+            if (clusterOpFut == null || clusterOpFut.isDone())
+                return;
+
+            boolean finished;
+
+            // Nodes' results and errors reducing is available on a required 
node where the process request must be registered.
+            assert (F.isEmpty(errors) && F.isEmpty(results)) || locRq != null;
+
+            Map<ClusterNode, Exception> errors0 = locRq == null || 
F.isEmpty(errors)
+                ? Collections.emptyMap()
+                : collectErrors(errors, locRq.nodes());
+
+            if (err == null && !F.isEmpty(results)) {
+                Map<ClusterNode, Map<PartitionKeyV2, PartitionHashRecordV2>> 
results0 = collecPartsHashes(results, locRq.nodes());
+
+                IdleVerifyResultV2 chkRes = 
SnapshotChecker.reduceHashesResults(results0, errors0);
+
+                finished = clusterOpFut.onDone(new 
SnapshotPartitionsVerifyTaskResult(locRq.metas, chkRes));
+            }
+            else
+                finished = finishClusterFutureWithErr(clusterOpFut, err, 
errors0);
+
+            if (finished && log.isInfoEnabled())
+                log.info("Snapshot validation process finished, req: " + locRq 
+ '.');
+        });
+    }
+
+    /** */
+    private Throwable stopAndCleanLocRequest(SnapshotCheckProcessRequest 
locRq, @Nullable Throwable err) {
+        if (err == null && locRq.error() != null)
+            err = locRq.error();
+
+        GridFutureAdapter<?> locWorkingFut = locRq.fut();
+
+        boolean finished = false;
+
+        // Try to stop local working future ASAP.
+        if (locWorkingFut != null)
+            finished = err == null ? locWorkingFut.onDone() : 
locWorkingFut.onDone(err);
+
+        requests.remove(locRq.snapshotName());
+
+        if (finished && log.isInfoEnabled())
+            log.info("Finished snapshot local validation, req: " + locRq + 
'.');
+
+        return err;
+    }
+
+    /** */
+    private Map<ClusterNode, Exception> collectErrors(Map<UUID, Throwable> 
errors, Set<UUID> requiredNodes) {
+        if (errors.isEmpty())
+            return Collections.emptyMap();
+
+        return errors.entrySet().stream().filter(e -> 
requiredNodes.contains(e.getKey()) && e.getValue() != null)
+            .collect(Collectors.toMap(e -> 
kctx.cluster().get().node(e.getKey()), e -> asException(e.getValue())));
+    }
+
+    /** */
+    private Map<ClusterNode, Map<PartitionKeyV2, PartitionHashRecordV2>> 
collecPartsHashes(

Review Comment:
   collec?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCheckDistributedProcess.java:
##########
@@ -0,0 +1,549 @@
+/*
+ * 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.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.management.cache.IdleVerifyResultV2;
+import org.apache.ignite.internal.management.cache.PartitionKeyV2;
+import 
org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2;
+import org.apache.ignite.internal.util.distributed.DistributedProcess;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
+import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_CHECK_METAS;
+import static 
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.SNAPSHOT_VALIDATE_PARTS;
+
+/** Distributed process of snapshot checking (with the partition hashes). */
+public class SnapshotCheckDistributedProcess {
+    /** */
+    private static final IgniteInternalFuture FINISHED_FUT = new 
GridFinishedFuture<>();
+
+    /** */
+    private final IgniteLogger log;
+
+    /** */
+    private final GridKernalContext kctx;
+
+    /** Snapshot check requests per snapshot on every node. */
+    final Map<String, SnapshotCheckProcessRequest> requests = new 
ConcurrentHashMap<>();
+
+    /** Cluster-wide operation futures per snapshot called from current node. 
*/
+    private final Map<UUID, 
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult>> clusterOpFuts = new 
ConcurrentHashMap<>();
+
+    /** Check metas first phase subprocess. */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
ArrayList<SnapshotMetadata>> phase1CheckMetas;
+
+    /** Partition hashes second phase subprocess.  */
+    private final DistributedProcess<SnapshotCheckProcessRequest, 
HashMap<PartitionKeyV2, PartitionHashRecordV2>> phase2PartsHashes;
+
+    /** */
+    public SnapshotCheckDistributedProcess(GridKernalContext kctx) {
+        this.kctx = kctx;
+
+        log = kctx.log(getClass());
+
+        phase1CheckMetas = new DistributedProcess<>(kctx, 
SNAPSHOT_CHECK_METAS, this::prepareAndCheckMetas,
+            this::reducePreparationAndMetasCheck);
+
+        phase2PartsHashes = new DistributedProcess<>(kctx, 
SNAPSHOT_VALIDATE_PARTS, this::validateParts,
+            this::reduceValidatePartsAndFinish);
+
+        kctx.event().addLocalEventListener((evt) -> 
nodeLeft(((DiscoveryEvent)evt).eventNode()), EVT_NODE_FAILED, EVT_NODE_LEFT);
+    }
+
+    /**
+     * Stops the process with the passes exception.
+     *
+     * @param th The interrupt reason.
+     * @param rqFilter If not {@code null}, used to filter which 
requests/process to stop. If {@code null}, stops all the validations.
+     */
+    public void interrupt(Throwable th, @Nullable 
Function<SnapshotCheckProcessRequest, Boolean> rqFilter) {
+        if (requests.isEmpty())
+            return;
+
+        requests.values().forEach(rq -> {
+            if (rqFilter == null || rqFilter.apply(rq)) {
+                rq.error(th);
+
+                clean(rq.requestId(), th, null, null);
+            }
+        });
+    }
+
+    /** Stops the related validation if the node is a mandatory one. */
+    private void nodeLeft(ClusterNode node) {
+        if (node.isClient() || requests.isEmpty())
+            return;
+
+        interrupt(
+            new ClusterTopologyCheckedException("Snapshot checking stopped. A 
node left the cluster: " + node + '.'),
+            rq -> rq.nodes().contains(node.id())
+        );
+    }
+
+    /** Phase 2 and process finish. */
+    private IgniteInternalFuture<?> reduceValidatePartsAndFinish(
+        UUID procId,
+        Map<UUID, HashMap<PartitionKeyV2, PartitionHashRecordV2>> results,
+        Map<UUID, Throwable> errors
+    ) {
+        clean(procId, null, results, errors);
+
+        return FINISHED_FUT;
+    }
+
+    /** Phase 2 beginning.  */
+    private IgniteInternalFuture<HashMap<PartitionKeyV2, 
PartitionHashRecordV2>> validateParts(
+        SnapshotCheckProcessRequest incReq) {
+        SnapshotCheckProcessRequest locReq;
+
+        if (stopAndCleanOnError(incReq, null) || (locReq = 
requests.get(incReq.snapshotName())) == null)
+            return FINISHED_FUT;
+
+        assert locReq.equals(incReq);
+
+        // Store metas to collect cluster operation result laster.
+        GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> clusterOpFut = 
clusterOpFuts.get(incReq.requestId());
+
+        if (clusterOpFut != null)
+            locReq.metas = incReq.metas;
+
+        // Local meta might be null if current node started after the snapshot 
creation or placement.
+        if (!incReq.nodes.contains(kctx.localNodeId()) || locReq.meta() == 
null)
+            return FINISHED_FUT;
+
+        GridFutureAdapter<HashMap<PartitionKeyV2, PartitionHashRecordV2>> 
locPartsChkFut = new GridFutureAdapter<>();
+
+        locReq.fut(locPartsChkFut);
+
+        ExecutorService executor = 
kctx.cache().context().snapshotMgr().snapshotExecutorService();
+
+        executor.submit(() -> stopFutureOnAnyFailure(locPartsChkFut, () -> {
+            // An error can occure when the local future is still null.
+            if (locReq.error() != null)
+                locPartsChkFut.onDone(locReq.error());
+
+            if (locPartsChkFut.isDone())
+                return;
+
+            File snpDir = 
kctx.cache().context().snapshotMgr().snapshotLocalDir(locReq.snapshotName(), 
locReq.snapshotPath());
+
+            try {
+                Map<PartitionKeyV2, PartitionHashRecordV2> res = 
kctx.cache().context().snapshotMgr().checker()
+                    .checkPartitions(locReq.meta(), snpDir, locReq.groups(), 
false, true, false);
+
+                locPartsChkFut.onDone(res instanceof HashMap ? 
(HashMap<PartitionKeyV2, PartitionHashRecordV2>)res
+                    : new HashMap<>(res));
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException("Failed to calculate snapshot 
partition hashes, req: " + incReq, e);
+            }
+
+            // No need to wait to the cealup if current node is just a worker.
+            if (!kctx.localNodeId().equals(locReq.opCoordId) && clusterOpFut 
== null)
+                clean(locReq.reqId, null, null, null);
+        }));
+
+        return locPartsChkFut;
+    }
+
+    /**
+     * If required, stops and clean related validation if errors occured
+     *
+     * @return {@code True} if the validation stopped and cleaned. {@code 
False} otherwise.
+     */
+    private boolean stopAndCleanOnError(SnapshotCheckProcessRequest req,
+        @Nullable Map<UUID, Throwable> occuredErrors) {
+        assert req != null;
+
+        if (!F.isEmpty(occuredErrors)) {
+            occuredErrors = occuredErrors.entrySet().stream()

Review Comment:
   I suppose the errors can appear only from nodes that are part of the 
request? Because these errors are passed in reduce with the request



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