Fix intermittent testOwnerChangesOnPeerAvailabilityChanges failure
[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      * Applies a snapshot on a follower that was installed by the leader.
51      *
52      * @param snapshot the Snapshot to apply.
53      */
54     void apply(ApplySnapshot snapshot);
55
56     /**
57      * Persists a snapshot.
58      *
59      * @param snapshotState the snapshot State
60      * @param installSnapshotStream Optional OutputStream that is present if the snapshot is to also be installed
61      *        on a follower.
62      * @param totalMemory the total memory threshold
63      */
64     void persist(Snapshot.State snapshotState, Optional<OutputStream> installSnapshotStream, long totalMemory);
65
66     /**
67      * Commit the snapshot by trimming the log.
68      *
69      * @param sequenceNumber the sequence number of the persisted snapshot
70      * @param timeStamp the time stamp of the persisted snapshot
71      */
72     void commit(long sequenceNumber, long timeStamp);
73
74     /**
75      * Rolls back the snapshot on failure.
76      */
77     void rollback();
78
79     /**
80      * Trims the in-memory log.
81      *
82      * @param desiredTrimIndex the desired index to trim from
83      * @return the actual trim index
84      */
85     long trimLog(long desiredTrimIndex);
86 }