Merge "Fix usage of StringBuilder when getting parent path in PathUtils Making consta...
[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      *
77      * @param replicatedLogEntry
78      */
79     void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry);
80
81     /**
82      *
83      * @param index the index of the log entry
84      */
85     List<ReplicatedLogEntry> getFrom(long index);
86
87     /**
88      *
89      * @param index the index of the log entry
90      */
91     List<ReplicatedLogEntry> getFrom(long index, int max);
92
93     /**
94      *
95      * @return
96      */
97     long size();
98
99     /**
100      * Checks if the entry at the specified index is present or not
101      *
102      * @param index the index of the log entry
103      * @return true if the entry is present in the in-memory journal
104      */
105     boolean isPresent(long index);
106
107     /**
108      * Checks if the entry is present in a snapshot
109      *
110      * @param index the index of the log entry
111      * @return true if the entry is in the snapshot. false if the entry is not
112      * in the snapshot even if the entry may be present in the replicated log
113      */
114     boolean isInSnapshot(long index);
115
116     /**
117      * Get the snapshot
118      *
119      * @return an object representing the snapshot if it exists. null otherwise
120      */
121     Object getSnapshot();
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 }