3de0de5131ae6c9195128b73a873cf8ca25bb9bf
[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      * Append an entry to the log
55      * @param replicatedLogEntry
56      */
57     void append(ReplicatedLogEntry replicatedLogEntry);
58
59     /**
60      *
61      * @param replicatedLogEntry
62      */
63     void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry);
64
65     /**
66      *
67      * @param index the index of the log entry
68      */
69     List<ReplicatedLogEntry> getFrom(long index);
70
71
72     /**
73      *
74      * @return
75      */
76     long size();
77
78     /**
79      * Checks if the entry at the specified index is present or not
80      *
81      * @param index the index of the log entry
82      * @return true if the entry is present in the in-memory journal
83      */
84     boolean isPresent(long index);
85
86     /**
87      * Checks if the entry is present in a snapshot
88      *
89      * @param index the index of the log entry
90      * @return true if the entry is in the snapshot. false if the entry is not
91      * in the snapshot even if the entry may be present in the replicated log
92      */
93     boolean isInSnapshot(long index);
94
95     /**
96      * Get the snapshot
97      *
98      * @return an object representing the snapshot if it exists. null otherwise
99      */
100     Object getSnapshot();
101
102     /**
103      * Get the index of the snapshot
104      *
105      * @return the index from which the snapshot was created. -1 otherwise.
106      */
107     long getSnapshotIndex();
108
109     /**
110      * Get the term of the snapshot
111      *
112      * @return the term of the index from which the snapshot was created. -1
113      * otherwise
114      */
115     long getSnapshotTerm();
116 }