Versions Compared

Key

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

...

Code Block
languagejava
themeMidnight
titleSnapshotLifecycleListener.javaSnapshot handlers API
collapsetrue
/**
 * Snapshot lifecycle listener.
 handler */
public interface SnapshotLifecycleListener<TSnapshotHandler<T> extends Serializable> extends Extension {
    /** ListenerSnapshot invocation priority (ascending order is used)handler type. */
    public defaultSnapshotHandlerType int prioritytype();

 {
   /** Local processing of a return 0;snapshot operation. */
    }

public @Nullable T invoke(SnapshotHandlerContext ctx) throws Exception;

    /**
 Processing of results from all nodes. */
 Called  locally afterpublic thedefault snapshotvoid files have been created on the node.complete(String name, Collection<SnapshotHandlerResult<T>> results) throws Exception {
     *
   for (SnapshotHandlerResult<T> *res @param: name Snapshot name.results) {
     * @param metadata Snapshot metadata file.
  if (res.error()  * @param binaryDir Snapshot binary metadata directory.
== null)
          * @param marshallerDir Snapshot marshaller data directory. continue;;

     * @param cacheDir Snapshot cache data directory.
 throw new IgniteCheckedException("Snapshot handler *has @throwsfailed IgniteCheckedException If failed.
 " +
    */
    public default void afterCreate(
     "[snapshot=" + name +
 String name,
        File metadata,
     ", handler="  Path binaryDir,+ getClass().getName() +
        Path marshallerDir,
       ", Path cacheDir
    ) throws IgniteCheckedException {
nodeId=" + res.node().id() + "].", res.error());
        }
    }
}

// No-op.
    }
** type */
public enum SnapshotHandlerType {
    /**
 Handler is called immediately *after Calledthe locallysnapshot beforeis restore snapshot files.taken. */
     *CREATE,

    /** *Handler @paramis namecalled Snapshotjust name.
before restore operation is started. */
 @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 lifecycle listener.
 */
public interface SnapshotLifecycleListener extends Extension {
        /**
     * Called locally after the snapshot files have been created on the node.
     *
     * @param metadata Snapshot metdata.
     * @throws IgniteCheckedException If failed.
     */
    public void onCreate(SnapshotMetadata metadata) throws IgniteCheckedException;

    /**
     * Called locally before performing a snapshot consistency check.
     *
     * @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 onCheck(SnapshotMetadata metadata, @Nullable Collection<String> grps) throws IgniteCheckedException;

    /**
     * Called locally before restoring cache data files from a snapshot.
     *
     * @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 onRestore(SnapshotMetadata metadata, @Nullable Collection<String> grps) throws IgniteCheckedException;
}
 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;
}


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.

...