b7c8955aad982873ee02fff78f629b7f7bc1f1b5
[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      *
90      * @return
91      */
92     long size();
93
94     /**
95      * Checks if the entry at the specified index is present or not
96      *
97      * @param index the index of the log entry
98      * @return true if the entry is present in the in-memory journal
99      */
100     boolean isPresent(long index);
101
102     /**
103      * Checks if the entry is present in a snapshot
104      *
105      * @param index the index of the log entry
106      * @return true if the entry is in the snapshot. false if the entry is not
107      * in the snapshot even if the entry may be present in the replicated log
108      */
109     boolean isInSnapshot(long index);
110
111     /**
112      * Get the snapshot
113      *
114      * @return an object representing the snapshot if it exists. null otherwise
115      */
116     Object getSnapshot();
117
118     /**
119      * Get the index of the snapshot
120      *
121      * @return the index from which the snapshot was created. -1 otherwise.
122      */
123     long getSnapshotIndex();
124
125     /**
126      * Get the term of the snapshot
127      *
128      * @return the term of the index from which the snapshot was created. -1
129      * otherwise
130      */
131     long getSnapshotTerm();
132 }