[ https://issues.apache.org/jira/browse/IGNITE-14070?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Pavel Pereslegin updated IGNITE-14070: -------------------------------------- Description: Sometimes the user is faced with the task of adding post-processing to the snapshot operation, for example, calculating the checksum of files, checking the consistency, etc. The same applies to the automatic restore procedure - the user should be able to check the consistency of files, checksums, etc. before restore them. It is impossible to implement pre/post-processing using standard Ignite events. if a custom check detects a problem, the entire operation with the snapshot must be aborted. We need to provide the ability to extend snapshot operations (CREATE/RESTORE) using plugin extensions. The API proposal: {code:java} /** handler */ public interface SnapshotHandler<T> extends Extension { /** Snapshot handler type. */ public SnapshotHandlerType type(); /** Local processing of a snapshot operation. */ public @Nullable T invoke(SnapshotHandlerContext ctx) throws Exception; /** Processing of results from all nodes. */ public default void complete(String name, Collection<SnapshotHandlerResult<T>> results) throws Exception { for (SnapshotHandlerResult<T> res : results) { if (res.error() == null) continue;; throw new IgniteCheckedException("Snapshot handler has failed " + "[snapshot=" + name + ", handler=" + getClass().getName() + ", nodeId=" + res.node().id() + "].", res.error()); } } } /** type */ public enum SnapshotHandlerType { /** Handler is called immediately after the snapshot is taken. */ CREATE, /** Handler is called just before restore operation is started. */ RESTORE } /** context */ public class SnapshotHandlerContext { SnapshotMetadata metadata; Collection<String> grps; ClusterNode locNode; } /** * Result of local processing on the node. In addition to the result received from the handler, it also includes information about the error (if any) and the node on which this result was received. */ public class SnapshotHandlerResult<T> implements Serializable { T data; Exception err; ClusterNode node; } {code} was: Sometimes the user is faced with the task of adding post-processing to the snapshot operation, for example, calculating the checksum of files, checking the consistency, etc. The same applies to the automatic restore procedure - the user should be able to check the consistency of files, checksums, etc. before restore them. It is impossible to implement pre/post-processing using standard Ignite events. if a custom check detects a problem, the entire operation with the snapshot must be aborted. We need to provide the ability to extend snapshot operations (CREATE/RESTORE) using plugin extensions. The API proposal: {code:java} /** handler */ public interface SnapshotHandler<T> extends Extension { /** Snapshot handler type. */ public SnapshotHandlerType type(); /** * Local processing of a snapshot operation. * Called on every node that contains snapshot data. * * @param ctx Snapshot handler context. * @return Result of local processing. * @throws IgniteCheckedException If failed. */ public @Nullable T invoke(SnapshotHandlerContext ctx) throws IgniteCheckedException; /** * Processing of results from all nodes. * Called on one of the nodes containing the snapshot data. * * @param name Snapshot name. * @param results Results from all nodes. * @throws IgniteCheckedException If failed. */ public default void complete(String name, Collection<SnapshotHandlerResult<T>> results) throws IgniteCheckedException { for (SnapshotHandlerResult<T> res : results) { if (res.error() == null) continue;; throw new IgniteCheckedException("Snapshot handler has failed " + "[snapshot=" + name + ", handler=" + getClass().getName() + ", nodeId=" + res.node().id() + "].", res.error()); } } } /** type */ public enum SnapshotHandlerType { /** Handler is called immediately after the snapshot is taken. */ CREATE, /** Handler is called just before restore operation is started. */ RESTORE } /** context */ public class SnapshotHandlerContext { /** Snapshot metadata. */ private final SnapshotMetadata metadata; /** The names of the cache groups on which the operation is performed. */ private final Collection<String> grps; /** Local node. */ private final ClusterNode locNode; /** * @param metadata Snapshot metadata. * @param grps The names of the cache groups on which the operation is performed. * @param locNode Local node. */ public SnapshotHandlerContext(SnapshotMetadata metadata, @Nullable Collection<String> grps, ClusterNode locNode) { this.metadata = metadata; this.grps = grps; this.locNode = locNode; } /** * @return Snapshot metadata. */ public SnapshotMetadata metadata() { return metadata; } /** * @return The names of the cache groups on which the operation is performed. May be {@code null} if the operation * is performed on all available cache groups. */ public @Nullable Collection<String> groups() { return grps; } /** * @return Local node. */ public ClusterNode localNode() { return locNode; } } /** * Result of local processing on the node. In addition to the result received from the handler, it also includes * information about the error (if any) and the node on which this result was received. * * @param <T> Type of the local processing result. */ public class SnapshotHandlerResult<T> implements Serializable { /** Serial version uid. */ private static final long serialVersionUID = 0L; /** Result of local processing. */ private final T data; /** Processing error. */ private final Exception err; /** Processing node. */ private final ClusterNode node; /** * @param data Result of local processing. * @param err Processing error. * @param node Processing node. */ public SnapshotHandlerResult(@Nullable T data, @Nullable Exception err, ClusterNode node) { this.data = data; this.err = err; this.node = node; } /** @return Result of local processing. */ public @Nullable T data() { return data; } /** @return Processing error. */ public @Nullable Exception error() { return err; } /** @return Processing node. */ public ClusterNode node() { return node; } } {code} > Implement API for custom snapshot lifecycle handlers (extensions). > ------------------------------------------------------------------ > > Key: IGNITE-14070 > URL: https://issues.apache.org/jira/browse/IGNITE-14070 > Project: Ignite > Issue Type: New Feature > Reporter: Denis Garus > Assignee: Pavel Pereslegin > Priority: Major > Labels: iep-43 > Fix For: 2.12 > > Time Spent: 20m > Remaining Estimate: 0h > > Sometimes the user is faced with the task of adding post-processing to the > snapshot operation, for example, calculating the checksum of files, checking > the consistency, etc. The same applies to the automatic restore procedure - > the user should be able to check the consistency of files, checksums, etc. > before restore them. It is impossible to implement pre/post-processing using > standard Ignite events. if a custom check detects a problem, the entire > operation with the snapshot must be aborted. > We need to provide the ability to extend snapshot operations (CREATE/RESTORE) > using plugin extensions. > The API proposal: > {code:java} > /** handler */ > public interface SnapshotHandler<T> extends Extension { > /** Snapshot handler type. */ > public SnapshotHandlerType type(); > /** Local processing of a snapshot operation. */ > public @Nullable T invoke(SnapshotHandlerContext ctx) throws Exception; > /** Processing of results from all nodes. */ > public default void complete(String name, > Collection<SnapshotHandlerResult<T>> results) throws Exception { > for (SnapshotHandlerResult<T> res : results) { > if (res.error() == null) > continue;; > throw new IgniteCheckedException("Snapshot handler has failed " + > "[snapshot=" + name + > ", handler=" + getClass().getName() + > ", nodeId=" + res.node().id() + "].", res.error()); > } > } > } > /** type */ > public enum SnapshotHandlerType { > /** Handler is called immediately after the snapshot is taken. */ > CREATE, > /** Handler is called just before restore operation is started. */ > RESTORE > } > /** context */ > public class SnapshotHandlerContext { > SnapshotMetadata metadata; > Collection<String> grps; > ClusterNode locNode; > } > /** > * Result of local processing on the node. In addition to the result received > from the handler, it also includes information about the error (if any) and > the node on which this result was received. > */ > public class SnapshotHandlerResult<T> implements Serializable { > T data; > Exception err; > ClusterNode node; > } > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)