Vladsz83 commented on code in PR #11897: URL: https://github.com/apache/ignite/pull/11897#discussion_r2229385855
########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotHandlerRestoreTask.java: ########## @@ -26,92 +26,112 @@ import java.util.UUID; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; -import org.apache.ignite.compute.ComputeJobResult; -import org.apache.ignite.internal.util.typedef.F; -import org.jetbrains.annotations.Nullable; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree; /** * Snapshot restore operation handling task. */ -public class SnapshotHandlerRestoreTask extends AbstractSnapshotVerificationTask { - /** Serial version uid. */ - private static final long serialVersionUID = 0L; - - /** {@inheritDoc} */ - @Override protected SnapshotHandlerRestoreJob createJob( - String name, - String folderName, - String consId, - SnapshotPartitionsVerifyTaskArg args +public class SnapshotHandlerRestoreTask { + /** */ + private final IgniteEx ignite; + + /** */ + private final IgniteLogger log; + + /** */ + private final SnapshotHandlerRestoreJob job; + + /** */ + SnapshotHandlerRestoreTask( + IgniteEx ignite, + IgniteLogger log, + SnapshotFileTree sft, + Collection<String> grps, + boolean check ) { - return new SnapshotHandlerRestoreJob(name, args.snapshotPath(), folderName, consId, args.cacheGroupNames(), args.check()); + job = new SnapshotHandlerRestoreJob(ignite, sft, grps, check); + this.ignite = ignite; + this.log = log; } - /** {@inheritDoc} */ - @SuppressWarnings("rawtypes") - @Nullable @Override public SnapshotPartitionsVerifyTaskResult reduce(List<ComputeJobResult> results) { + /** */ + public Map<String, SnapshotHandlerResult<Object>> execute() { + return job.execute0(); + } + + /** */ + public void reduce( + String snpName, + Map<ClusterNode, Map<Object, Map<String, SnapshotHandlerResult<?>>>> results + ) { Map<String, List<SnapshotHandlerResult<?>>> clusterResults = new HashMap<>(); Collection<UUID> execNodes = new ArrayList<>(results.size()); - for (ComputeJobResult res : results) { - if (res.getException() != null) - throw res.getException(); + // Checking node -> Map by snapshot part's consistend id. + for (Map.Entry<ClusterNode, Map<Object, Map<String, SnapshotHandlerResult<?>>>> nodeRes : results.entrySet()) { + // Consistent id -> Map by handler name. + for (Map.Entry<Object, Map<String, SnapshotHandlerResult<?>>> res : nodeRes.getValue().entrySet()) { + // Depending on the job mapping, we can get several different results from one node. + execNodes.add(nodeRes.getKey().id()); - // Depending on the job mapping, we can get several different results from one node. - execNodes.add(res.getNode().id()); + Map<String, SnapshotHandlerResult<?>> nodeDataMap = res.getValue(); - Map<String, SnapshotHandlerResult> nodeDataMap = res.getData(); + assert nodeDataMap != null : "At least the default snapshot restore handler should have been executed "; - assert nodeDataMap != null : "At least the default snapshot restore handler should have been executed "; + for (Map.Entry<String, SnapshotHandlerResult<?>> entry : nodeDataMap.entrySet()) { + String hndName = entry.getKey(); - for (Map.Entry<String, SnapshotHandlerResult> entry : nodeDataMap.entrySet()) { - String hndName = entry.getKey(); - - clusterResults.computeIfAbsent(hndName, v -> new ArrayList<>()).add(entry.getValue()); + clusterResults.computeIfAbsent(hndName, v -> new ArrayList<>()).add(entry.getValue()); + } } } - String snapshotName = F.first(F.first(metas.values())).snapshotName(); - try { ignite.context().cache().context().snapshotMgr().handlers().completeAll( - SnapshotHandlerType.RESTORE, snapshotName, clusterResults, execNodes, wrns -> {}); + SnapshotHandlerType.RESTORE, snpName, clusterResults, execNodes, wrns -> {}); } catch (Exception e) { - log.warning("The snapshot operation will be aborted due to a handler error [snapshot=" + snapshotName + "].", e); + log.warning("The snapshot operation will be aborted due to a handler error [snapshot=" + snpName + "].", e); throw new IgniteException(e); } - - return new SnapshotPartitionsVerifyTaskResult(metas, null); } /** Invokes all {@link SnapshotHandlerType#RESTORE} handlers locally. */ - private static class SnapshotHandlerRestoreJob extends AbstractSnapshotVerificationJob { - /** Serial version uid. */ - private static final long serialVersionUID = 0L; + private static class SnapshotHandlerRestoreJob { + /** */ + private final IgniteEx ignite; + + /** */ + private final SnapshotFileTree sft; + + /** */ + private final Collection<String> rqGrps; + + /** */ + private final boolean check; /** - * @param snpName Snapshot name. - * @param snpPath Snapshot directory path. - * @param folderName Folder name for snapshot. - * @param consId Consistent id of the related node. * @param grps Cache group names. * @param check If {@code true} check snapshot before restore. */ public SnapshotHandlerRestoreJob( - String snpName, Review Comment: Resolved? -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org