Merge "Fix checkstyle warnings in logback-config"
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / ReplicatedLog.java
1 /*
2  * Copyright (c) 2014 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.util.List;
12
13 /**
14  * Represents the ReplicatedLog that needs to be kept in sync by the RaftActor
15  */
16 public interface ReplicatedLog {
17     /**
18      * Get a replicated log entry at the specified index
19      *
20      * @param index the index of the log entry
21      * @return the ReplicatedLogEntry at index. null if index less than 0 or
22      * greater than the size of the in-memory journal.
23      */
24     ReplicatedLogEntry get(long index);
25
26
27     /**
28      * Get the last replicated log entry
29      *
30      * @return
31      */
32     ReplicatedLogEntry last();
33
34     /**
35      *
36      * @return
37      */
38     long lastIndex();
39
40     /**
41      *
42      * @return
43      */
44     long lastTerm();
45
46     /**
47      * To be called when we need to remove entries from the in-memory log.
48      * This method will remove all entries >= index. This method should be used
49      * during recovery to appropriately trim the log based on persisted
50      * information
51      *
52      * @param index the index of the log entry
53      */
54     void removeFrom(long index);
55
56
57     /**
58      * To be called when we need to remove entries from the in-memory log and we
59      * need that information persisted to disk. This method will remove all
60      * entries >= index.
61      * <p>
62      * The persisted information would then be used during recovery to properly
63      * reconstruct the state of the in-memory replicated log
64      *
65      * @param index the index of the log entry
66      */
67     void removeFromAndPersist(long index);
68
69     /**
70      * Append an entry to the log
71      * @param replicatedLogEntry
72      */
73     void append(ReplicatedLogEntry replicatedLogEntry);
74
75     /**
76      * Optimization method to increase the capacity of the journal log prior to appending entries.
77      *
78      * @param amount the amount to increase by
79      */
80     void increaseJournalLogCapacity(int amount);
81
82     /**
83      *
84      * @param replicatedLogEntry
85      */
86     void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry);
87
88     /**
89      *
90      * @param index the index of the log entry
91      */
92     List<ReplicatedLogEntry> getFrom(long index);
93
94     /**
95      *
96      * @param index the index of the log entry
97      */
98     List<ReplicatedLogEntry> getFrom(long index, int max);
99
100     /**
101      *
102      * @return
103      */
104     long size();
105
106     /**
107      * Checks if the entry at the specified index is present or not
108      *
109      * @param index the index of the log entry
110      * @return true if the entry is present in the in-memory journal
111      */
112     boolean isPresent(long index);
113
114     /**
115      * Checks if the entry is present in a snapshot
116      *
117      * @param index the index of the log entry
118      * @return true if the entry is in the snapshot. false if the entry is not
119      * in the snapshot even if the entry may be present in the replicated log
120      */
121     boolean isInSnapshot(long index);
122
123     /**
124      * Get the index of the snapshot
125      *
126      * @return the index from which the snapshot was created. -1 otherwise.
127      */
128     long getSnapshotIndex();
129
130     /**
131      * Get the term of the snapshot
132      *
133      * @return the term of the index from which the snapshot was created. -1
134      * otherwise
135      */
136     long getSnapshotTerm();
137
138     /**
139      * sets the snapshot index in the replicated log
140      * @param snapshotIndex
141      */
142     void setSnapshotIndex(long snapshotIndex);
143
144     /**
145      * sets snapshot term
146      * @param snapshotTerm
147      */
148     public void setSnapshotTerm(long snapshotTerm);
149
150     /**
151      * Clears the journal entries with startIndex(inclusive) and endIndex (exclusive)
152      * @param startIndex
153      * @param endIndex
154      */
155     public void clear(int startIndex, int endIndex);
156
157     /**
158      * Handles all the bookkeeping in order to perform a rollback in the
159      * event of SaveSnapshotFailure
160      * @param snapshotCapturedIndex
161      * @param snapshotCapturedTerm
162      */
163     public void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm);
164
165     /**
166      * Sets the Replicated log to state after snapshot success.
167      */
168     public void snapshotCommit();
169
170     /**
171      * Restores the replicated log to a state in the event of a save snapshot failure
172      */
173     public void snapshotRollback();
174
175     /**
176      * Size of the data in the log (in bytes)
177      */
178     public int dataSize();
179 }