X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FRaftActorSnapshotCohort.java;h=8887a650c099e9c0427ca5f28db7922557f02bfc;hp=ad68726371621cf210f0ba1407955ca84672e9c7;hb=7cb260aeb0738104e3bee8a086de9e2e5f77b7e0;hpb=c31a6fcf9fb070d4419ca4c32d8b531fdcb5030d diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotCohort.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotCohort.java index ad68726371..8887a650c0 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotCohort.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotCohort.java @@ -8,6 +8,12 @@ package org.opendaylight.controller.cluster.raft; import akka.actor.ActorRef; +import com.google.common.io.ByteSource; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Optional; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.controller.cluster.raft.persisted.Snapshot.State; /** * Interface for a class that participates in raft actor snapshotting. @@ -21,13 +27,30 @@ public interface RaftActorSnapshotCohort { * created. The implementation should send a CaptureSnapshotReply to the given actor. * * @param actorRef the actor to which to respond + * @param installSnapshotStream Optional OutputStream that is present if the snapshot is to also be installed + * on a follower. The implementation must serialize its state to the OutputStream and return the + * installSnapshotStream instance in the CaptureSnapshotReply along with the snapshot State instance. + * The snapshot State is serialized directly to the snapshot store while the OutputStream is used to send + * the state data to follower(s) in chunks. The {@link #deserializeSnapshot} method is used to convert the + * serialized data back to a State instance on the follower end. The serialization for snapshot install is + * passed off so the cost of serialization is not charged to the raft actor's thread. */ - void createSnapshot(ActorRef actorRef); + void createSnapshot(@NonNull ActorRef actorRef, @NonNull Optional installSnapshotStream); /** * This method is called to apply a snapshot installed by the leader. * - * @param snapshotBytes a snapshot of the state of the actor + * @param snapshotState a snapshot of the state of the actor */ - void applySnapshot(byte[] snapshotBytes); + void applySnapshot(@NonNull State snapshotState); + + /** + * This method is called to de-serialize snapshot data that was previously serialized via {@link #createSnapshot} + * to a State instance. + * + * @param snapshotBytes the ByteSource containing the serialized data + * @return the converted snapshot State + * @throws IOException if an error occurs accessing the ByteSource or de-serializing + */ + @NonNull State deserializeSnapshot(@NonNull ByteSource snapshotBytes) throws IOException; }