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 {
    /** Listener invocation priority (ascending order is used). */
    public default int priority() {
        return 0;
    }

    /**
     * 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 name Snapshot name.
     * @param grps Cache groups to be restored ({@code null} if all cache groups are restored from the snapshot).
     * @param res Results from all nodes.
     * @param errs Errors from all nodes.
     * @throws IgniteCheckedException If failed.
     */
    public default void handlePreRestoreResults(
        String name,
        @Nullable Collection<String> grps,
        Map<ClusterNode, T> res,
        Map<ClusterNode, Exception> errs
    ) throws IgniteCheckedException {
        Map.Entry<ClusterNode, Exception> errEntry = F.first(errs.entrySet());

        if (errEntry == null)
            return;

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


Code Block
languagejava
themeMidnight
titleSnapshotLifecycleListener.java (alternate version)
collapsetrue
/**
 * Snapshot local lifecycle listener.
 */
public interface SnapshotLifecycleListener extends Extension {
    /**
     * @param req Snapshot operation start request.
     * @throws IgniteCheckedException If failed.
     */
    public void beforeCreate(SnapshotOperationRequest req) throws IgniteCheckedException;

    /**
     * @param metadata Snapshot metdata.
     * @throws IgniteCheckedException If failed.
     */
    public void afterCreate(SnapshotMetadata metadata) throws IgniteCheckedException;

    /**
     * @param metadata Snapshot metdata.
     * @param grps Cache groups to be restored ({@code null} if all cache groups are restored from the snapshot).
     * @throws IgniteCheckedException If failed.
     */
    public void beforeValidate(SnapshotMetadata metadata, @Nullable Collection<String> grps) throws IgniteCheckedException;

    /**
     * @param metadata Snapshot metdata.
     * @param grps Cache groups to be restored ({@code null} if all cache groups are restored from the snapshot).
     * @throws IgniteCheckedException If failed.
     */
    public void afterValidate(SnapshotMetadata metadata, @Nullable Collection<String> grps) throws IgniteCheckedException;

    /**
     * @param metadata Snapshot metdata.
     * @param grps Cache groups to be restored ({@code null} if all cache groups are restored from the snapshot).
     * @throws IgniteCheckedException If failed.
     */
    public void beforeRestore(SnapshotMetadata metadata, @Nullable Collection<String> grps) throws IgniteCheckedException;

    /**
     * @param metadata Snapshot metdata.
     * @param grps Cache groups to be restored ({@code null} if all cache groups are restored from the snapshot).
     * @throws IgniteCheckedException If failed.
     */
    public void afterRestore(SnapshotMetadata metadata, @Nullable Collection<String> grps) throws IgniteCheckedException;
}


Snapshot requirements

  1. Users must have the ability to create a snapshot of persisted user data (in-memory is out of the scope).
  2. Users must have the ability to create a snapshot from the cluster under the load without cluster deactivation.
  3. The snapshot process must not block for a long time any of the user transactions (short-time blocks are acceptable).
  4. The snapshot process must allow creating a data snapshot on each node and transfer it to any of the remote nodes for internal cluster needs.
  5. The created snapshot at the cluster-level must be fully consistent from cluster-wide terms, there should not be any incomplete transactions inside.
  6. The snapshot of each node must be consistent – cache partitions, binary meta, etc. must not have unnecessary changes.

...