Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
themeMidnight
titleSnapshotLifecycleListener.java
collapsetrue
/**
 * Snapshot lifecycle listener.
 */
public interface SnapshotLifecycleListener<T extends Serializable> extends Extension {
    /** Default listener priority. */
    public static final int DEFAULT_PRIORITY = 0;

    /** Listener invocation priority (ascending order is used). */
    public default int priority() {
        return DEFAULT_PRIORITY0;
    }

    /**
     * Called locally after the snapshot files have been created on the node.
     *
     * @param name Snapshot name.
     * @param metadata Snapshot metadata file.
     * @param binaryDir Snapshot binary metadata directory.
     * @param marshallerDir Snapshot marshaller data directory.
     * @param cacheDir Snapshot cache data directory.
     * @throws IgniteCheckedException If failed.
     */
    public default void afterCreate(String name, File metadata,
        Path binaryDir, Path marshallerDir, Path cacheDir) throws IgniteCheckedException {
        // No-op.
    }

    /**
     * Called locally before restore snapshot files.
     *
     * @param name Snapshot name.
     * @param grps Cache groups to be restored ({@code null} if all cache groups are restored from the snapshot).
     * @param metadata Snapshot metadata file.
     * @param binaryDir Snapshot binary metadata directory.
     * @param marshallerDir Snapshot marshaller data directory.
     * @param cacheDir Snapshot cache data directory.
     *
     * @return Local node result, or {@code null} if cluster-wide aggregation is not required.
     * @throws IgniteCheckedException If failed.
     */
    @Nullable public default T beforeRestore(String name, @Nullable Collection<String> grps, File metadata,
        Path binaryDir, Path marshallerDir, Path cacheDir) throws IgniteCheckedException {
        return null;
    }

    /**
     * Process the results of a pre-restore operation across the cluster.
     *
     * @param res Results from all nodes.
     * @throws IgniteCheckedException If failed.
     */
    public default void handlePreRestoreResults(
        String snapshotName,
        @Nullable Collection<String> grps,
        Map<ClusterNode, T> res,
        Map<ClusterNode, Exception> errs
    ) throws IgniteCheckedException {
        Map.Entry<ClusterNode, Exception> exEntry = F.first(errs.entrySet());

        if (exEntry == null)
            return;

        throw new IgniteCheckedException("Snapshot restore handler " + getClass().getSimpleName() +
            " has failed on node " + exEntry.getKey().id() + '.', exEntry.getValue());
    }
}

...