Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / SnapshotState.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.raft;
10
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;
15
16 /**
17  * Interface for a snapshot phase state.
18  *
19  * @author Moiz Raja
20  * @author Thomas Pantelis
21  */
22 public interface SnapshotState {
23     /**
24      * Returns whether or not a capture is in progress.
25      *
26      * @return true when a snapshot is being captured, false otherwise
27      */
28     boolean isCapturing();
29
30     /**
31      * Initiates a capture snapshot.
32      *
33      * @param lastLogEntry the last entry in the replicated log
34      * @param replicatedToAllIndex the current replicatedToAllIndex
35      * @return true if capture was started
36      */
37     boolean capture(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex);
38
39     /**
40      * Initiates a capture snapshot for the purposing of installing the snapshot on a follower.
41      *
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
46      */
47     boolean captureToInstall(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex, String targetFollower);
48
49     /**
50      * Initiates a capture snapshot, while enforcing trimming of the log up to lastAppliedIndex.
51      * @param lastLogEntry the last entry in the replicated log
52      * @param replicatedToAllIndex the current replicatedToAllIndex
53      * @return true if capture was started
54      */
55     boolean captureWithForcedTrim(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex);
56
57     /**
58      * Applies a snapshot on a follower that was installed by the leader.
59      *
60      * @param snapshot the Snapshot to apply.
61      */
62     void apply(ApplySnapshot snapshot);
63
64     /**
65      * Persists a snapshot.
66      *
67      * @param snapshotState the snapshot State
68      * @param installSnapshotStream Optional OutputStream that is present if the snapshot is to also be installed
69      *        on a follower.
70      * @param totalMemory the total memory threshold
71      */
72     void persist(Snapshot.State snapshotState, Optional<OutputStream> installSnapshotStream, long totalMemory);
73
74     /**
75      * Commit the snapshot by trimming the log.
76      *
77      * @param sequenceNumber the sequence number of the persisted snapshot
78      * @param timeStamp the time stamp of the persisted snapshot
79      */
80     void commit(long sequenceNumber, long timeStamp);
81
82     /**
83      * Rolls back the snapshot on failure.
84      */
85     void rollback();
86
87     /**
88      * Trims the in-memory log.
89      *
90      * @param desiredTrimIndex the desired index to trim from
91      * @return the actual trim index
92      */
93     long trimLog(long desiredTrimIndex);
94 }