Fix bug in ReplicatedLogImpl#removeFrom and use akka-persistence for removing entries
[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      * Remove all the entries from the logs >= index
48      *
49      * @param index the index of the log entry
50      */
51     void removeFrom(long index);
52
53
54     /**
55      * Remove all entries starting from the specified entry and persist the
56      * information to disk
57      *
58      * @param index
59      */
60     void removeFromAndPersist(long index);
61
62     /**
63      * Append an entry to the log
64      * @param replicatedLogEntry
65      */
66     void append(ReplicatedLogEntry replicatedLogEntry);
67
68     /**
69      *
70      * @param replicatedLogEntry
71      */
72     void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry);
73
74     /**
75      *
76      * @param index the index of the log entry
77      */
78     List<ReplicatedLogEntry> getFrom(long index);
79
80
81     /**
82      *
83      * @return
84      */
85     long size();
86
87     /**
88      * Checks if the entry at the specified index is present or not
89      *
90      * @param index the index of the log entry
91      * @return true if the entry is present in the in-memory journal
92      */
93     boolean isPresent(long index);
94
95     /**
96      * Checks if the entry is present in a snapshot
97      *
98      * @param index the index of the log entry
99      * @return true if the entry is in the snapshot. false if the entry is not
100      * in the snapshot even if the entry may be present in the replicated log
101      */
102     boolean isInSnapshot(long index);
103
104     /**
105      * Get the snapshot
106      *
107      * @return an object representing the snapshot if it exists. null otherwise
108      */
109     Object getSnapshot();
110
111     /**
112      * Get the index of the snapshot
113      *
114      * @return the index from which the snapshot was created. -1 otherwise.
115      */
116     long getSnapshotIndex();
117
118     /**
119      * Get the term of the snapshot
120      *
121      * @return the term of the index from which the snapshot was created. -1
122      * otherwise
123      */
124     long getSnapshotTerm();
125 }