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 org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot;
14 * Interface for a snapshot phase state.
17 * @author Thomas Pantelis
19 public interface SnapshotState {
21 * Returns whether or not a capture is in progress.
23 * @return true when a snapshot is being captured, false otherwise
25 boolean isCapturing();
28 * Initiates a capture snapshot.
30 * @param lastLogEntry the last entry in the replicated log
31 * @param replicatedToAllIndex the current replicatedToAllIndex
32 * @return true if capture was started
34 boolean capture(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex);
37 * Initiates a capture snapshot for the purposing of installing the snapshot on a follower.
39 * @param lastLogEntry the last entry in the replicated log
40 * @param replicatedToAllIndex the current replicatedToAllIndex
41 * @param targetFollower the id of the follower on which to install
42 * @return true if capture was started
44 boolean captureToInstall(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex, String targetFollower);
47 * Applies a snapshot on a follower that was installed by the leader.
49 * @param snapshot the Snapshot to apply.
51 void apply(ApplySnapshot snapshot);
54 * Persists a snapshot.
56 * @param snapshotBytes the snapshot bytes
57 * @param totalMemory the total memory threshold
59 void persist(byte[] snapshotBytes, long totalMemory);
62 * Commit the snapshot by trimming the log.
64 * @param sequenceNumber the sequence number of the persisted snapshot
65 * @param timeStamp the time stamp of the persisted snapshot
67 void commit(long sequenceNumber, long timeStamp);
70 * Rolls back the snapshot on failure.
75 * Trims the in-memory log.
77 * @param desiredTrimIndex the desired index to trim from
78 * @return the actual trim index
80 long trimLog(long desiredTrimIndex);