2 * Copyright (c) 2015 Cisco 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
9 package org.opendaylight.controller.cluster.raft;
11 import java.io.OutputStream;
12 import java.util.Optional;
13 import org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot;
14 import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
17 * Interface for a snapshot phase state.
20 * @author Thomas Pantelis
22 public interface SnapshotState {
24 * Returns whether or not a capture is in progress.
26 * @return true when a snapshot is being captured, false otherwise
28 boolean isCapturing();
31 * Initiates a capture snapshot.
33 * @param lastLogEntry the last entry in the replicated log
34 * @param replicatedToAllIndex the current replicatedToAllIndex
35 * @return true if capture was started
37 boolean capture(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex);
40 * Initiates a capture snapshot for the purposing of installing the snapshot on a follower.
42 * @param lastLogEntry the last entry in the replicated log
43 * @param replicatedToAllIndex the current replicatedToAllIndex
44 * @param targetFollower the id of the follower on which to install
45 * @return true if capture was started
47 boolean captureToInstall(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex, String targetFollower);
50 * Applies a snapshot on a follower that was installed by the leader.
52 * @param snapshot the Snapshot to apply.
54 void apply(ApplySnapshot snapshot);
57 * Persists a snapshot.
59 * @param snapshotState the snapshot State
60 * @param installSnapshotStream Optional OutputStream that is present if the snapshot is to also be installed
62 * @param totalMemory the total memory threshold
64 void persist(Snapshot.State snapshotState, Optional<OutputStream> installSnapshotStream, long totalMemory);
67 * Commit the snapshot by trimming the log.
69 * @param sequenceNumber the sequence number of the persisted snapshot
70 * @param timeStamp the time stamp of the persisted snapshot
72 void commit(long sequenceNumber, long timeStamp);
75 * Rolls back the snapshot on failure.
80 * Trims the in-memory log.
82 * @param desiredTrimIndex the desired index to trim from
83 * @return the actual trim index
85 long trimLog(long desiredTrimIndex);