Fix remaining CS errors in sal-akka-raft and enable enforcement
[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 org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot;
12
13 /**
14  * Interface for a snapshot phase state.
15  *
16  * @author Moiz Raja
17  * @author Thomas Pantelis
18  */
19 public interface SnapshotState {
20     /**
21      * Returns whether or not a capture is in progress.
22      *
23      * @return true when a snapshot is being captured, false otherwise
24      */
25     boolean isCapturing();
26
27     /**
28      * Initiates a capture snapshot.
29      *
30      * @param lastLogEntry the last entry in the replicated log
31      * @param replicatedToAllIndex the current replicatedToAllIndex
32      * @return true if capture was started
33      */
34     boolean capture(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex);
35
36     /**
37      * Initiates a capture snapshot for the purposing of installing the snapshot on a follower.
38      *
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
43      */
44     boolean captureToInstall(ReplicatedLogEntry lastLogEntry, long replicatedToAllIndex, String targetFollower);
45
46     /**
47      * Applies a snapshot on a follower that was installed by the leader.
48      *
49      * @param snapshot the Snapshot to apply.
50      */
51     void apply(ApplySnapshot snapshot);
52
53     /**
54      * Persists a snapshot.
55      *
56      * @param snapshotBytes the snapshot bytes
57      * @param totalMemory the total memory threshold
58      */
59     void persist(byte[] snapshotBytes, long totalMemory);
60
61     /**
62      * Commit the snapshot by trimming the log.
63      *
64      * @param sequenceNumber the sequence number of the persisted snapshot
65      * @param timeStamp the time stamp of the persisted snapshot
66      */
67     void commit(long sequenceNumber, long timeStamp);
68
69     /**
70      * Rolls back the snapshot on failure.
71      */
72     void rollback();
73
74     /**
75      * Trims the in-memory log.
76      *
77      * @param desiredTrimIndex the desired index to trim from
78      * @return the actual trim index
79      */
80     long trimLog(long desiredTrimIndex);
81 }