2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.raft;
10 import akka.actor.ActorRef;
11 import com.google.common.io.ByteSource;
12 import java.io.IOException;
13 import java.io.OutputStream;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.controller.cluster.raft.persisted.Snapshot.State;
19 * Interface for a class that participates in raft actor snapshotting.
21 * @author Thomas Pantelis
23 public interface RaftActorSnapshotCohort {
26 * This method is called by the RaftActor when a snapshot needs to be
27 * created. The implementation should send a CaptureSnapshotReply to the given actor.
29 * @param actorRef the actor to which to respond
30 * @param installSnapshotStream Optional OutputStream that is present if the snapshot is to also be installed
31 * on a follower. The implementation must serialize its state to the OutputStream and return the
32 * installSnapshotStream instance in the CaptureSnapshotReply along with the snapshot State instance.
33 * The snapshot State is serialized directly to the snapshot store while the OutputStream is used to send
34 * the state data to follower(s) in chunks. The {@link #deserializeSnapshot} method is used to convert the
35 * serialized data back to a State instance on the follower end. The serialization for snapshot install is
36 * passed off so the cost of serialization is not charged to the raft actor's thread.
38 void createSnapshot(@NonNull ActorRef actorRef, @NonNull Optional<OutputStream> installSnapshotStream);
41 * This method is called to apply a snapshot installed by the leader.
43 * @param snapshotState a snapshot of the state of the actor
45 void applySnapshot(@NonNull State snapshotState);
48 * This method is called to de-serialize snapshot data that was previously serialized via {@link #createSnapshot}
49 * to a State instance.
51 * @param snapshotBytes the ByteSource containing the serialized data
52 * @return the converted snapshot State
53 * @throws IOException if an error occurs accessing the ByteSource or de-serializing
55 @NonNull State deserializeSnapshot(@NonNull ByteSource snapshotBytes) throws IOException;