Fixup comparison formatting
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / SnapshotState.java
index 2ff30ec53b24fd6c3664e23a591d574c93878fe7..acb6e01230ecd64b8b6625f3f1c54eae227bd629 100644 (file)
@@ -8,66 +8,86 @@
 
 package org.opendaylight.controller.cluster.raft;
 
-import akka.japi.Procedure;
-import org.opendaylight.controller.cluster.DataPersistenceProvider;
-import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
+import java.io.OutputStream;
+import java.util.Optional;
+import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot;
+import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
 
+/**
+ * Interface for a snapshot phase state.
+ *
+ * @author Moiz Raja
+ * @author Thomas Pantelis
+ */
 public interface SnapshotState {
     /**
-     * Should return true when a snapshot is being captured
-     * @return
+     * Returns whether or not a capture is in progress.
+     *
+     * @return true when a snapshot is being captured, false otherwise
      */
     boolean isCapturing();
 
     /**
-     * Initiate capture snapshot
+     * Initiates a capture snapshot.
      *
      * @param lastLogEntry the last entry in the replicated log
      * @param replicatedToAllIndex the current replicatedToAllIndex
+     * @return true if capture was started
      */
-    void capture(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex);
+    boolean capture(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex);
 
     /**
-     * Initiate capture snapshot for the purposing of installing that snapshot
+     * Initiates a capture snapshot for the purposing of installing the snapshot on a follower.
      *
-     * @param lastLogEntry
-     * @param replicatedToAllIndex
+     * @param lastLogEntry the last entry in the replicated log
+     * @param replicatedToAllIndex the current replicatedToAllIndex
+     * @param targetFollower the id of the follower on which to install
+     * @return true if capture was started
+     */
+    boolean captureToInstall(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex, String targetFollower);
+
+    /**
+     * Initiates a capture snapshot, while enforcing trimming of the log up to lastAppliedIndex.
+     * @param lastLogEntry the last entry in the replicated log
+     * @param replicatedToAllIndex the current replicatedToAllIndex
+     * @return true if capture was started
      */
-    void captureToInstall(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex);
+    boolean captureWithForcedTrim(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex);
 
     /**
-     * Create the snapshot
+     * Applies a snapshot on a follower that was installed by the leader.
      *
-     * @param callback a procedure to be called which should create the snapshot
+     * @param snapshot the Snapshot to apply.
      */
-    void create(Procedure<Void> callback);
+    void apply(ApplySnapshot snapshot);
 
     /**
-     * Persist the snapshot
+     * Persists a snapshot.
      *
-     * @param persistenceProvider
-     * @param snapshotBytes
-     * @param currentBehavior
+     * @param snapshotState the snapshot State
+     * @param installSnapshotStream Optional OutputStream that is present if the snapshot is to also be installed
+     *        on a follower.
+     * @param totalMemory the total memory threshold
      */
-    void persist(DataPersistenceProvider persistenceProvider, byte[] snapshotBytes, RaftActorBehavior currentBehavior);
+    void persist(Snapshot.State snapshotState, Optional<OutputStream> installSnapshotStream, long totalMemory);
 
     /**
-     * Commit the snapshot by trimming the log
+     * Commit the snapshot by trimming the log.
      *
-     * @param persistenceProvider
-     * @param sequenceNumber
+     * @param sequenceNumber the sequence number of the persisted snapshot
+     * @param timeStamp the time stamp of the persisted snapshot
      */
-    void commit(DataPersistenceProvider persistenceProvider, long sequenceNumber);
+    void commit(long sequenceNumber, long timeStamp);
 
     /**
-     * Rollback the snapshot
+     * Rolls back the snapshot on failure.
      */
     void rollback();
 
     /**
-     * Trim the log
+     * Trims the in-memory log.
      *
-     * @param desiredTrimIndex
+     * @param desiredTrimIndex the desired index to trim from
      * @return the actual trim index
      */
     long trimLog(long desiredTrimIndex);