2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.raft;
11 import akka.japi.Procedure;
12 import java.util.List;
15 * Represents the ReplicatedLog that needs to be kept in sync by the RaftActor
17 public interface ReplicatedLog {
19 * Get a replicated log entry at the specified index
21 * @param index the index of the log entry
22 * @return the ReplicatedLogEntry at index. null if index less than 0 or
23 * greater than the size of the in-memory journal.
25 ReplicatedLogEntry get(long index);
29 * Get the last replicated log entry
33 ReplicatedLogEntry last();
48 * To be called when we need to remove entries from the in-memory log.
49 * This method will remove all entries >= index. This method should be used
50 * during recovery to appropriately trim the log based on persisted
53 * @param index the index of the log entry
55 void removeFrom(long index);
59 * To be called when we need to remove entries from the in-memory log and we
60 * need that information persisted to disk. This method will remove all
63 * The persisted information would then be used during recovery to properly
64 * reconstruct the state of the in-memory replicated log
66 * @param index the index of the log entry
68 void removeFromAndPersist(long index);
71 * Append an entry to the log
72 * @param replicatedLogEntry
74 void append(ReplicatedLogEntry replicatedLogEntry);
77 * Optimization method to increase the capacity of the journal log prior to appending entries.
79 * @param amount the amount to increase by
81 void increaseJournalLogCapacity(int amount);
85 * @param replicatedLogEntry
87 void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry);
89 void appendAndPersist(ReplicatedLogEntry replicatedLogEntry, Procedure<ReplicatedLogEntry> callback);
93 * @param index the index of the log entry
95 List<ReplicatedLogEntry> getFrom(long index);
99 * @param index the index of the log entry
101 List<ReplicatedLogEntry> getFrom(long index, int max);
110 * Checks if the entry at the specified index is present or not
112 * @param index the index of the log entry
113 * @return true if the entry is present in the in-memory journal
115 boolean isPresent(long index);
118 * Checks if the entry is present in a snapshot
120 * @param index the index of the log entry
121 * @return true if the entry is in the snapshot. false if the entry is not
122 * in the snapshot even if the entry may be present in the replicated log
124 boolean isInSnapshot(long index);
127 * Get the index of the snapshot
129 * @return the index from which the snapshot was created. -1 otherwise.
131 long getSnapshotIndex();
134 * Get the term of the snapshot
136 * @return the term of the index from which the snapshot was created. -1
139 long getSnapshotTerm();
142 * sets the snapshot index in the replicated log
143 * @param snapshotIndex
145 void setSnapshotIndex(long snapshotIndex);
149 * @param snapshotTerm
151 void setSnapshotTerm(long snapshotTerm);
154 * Clears the journal entries with startIndex(inclusive) and endIndex (exclusive)
158 void clear(int startIndex, int endIndex);
161 * Handles all the bookkeeping in order to perform a rollback in the
162 * event of SaveSnapshotFailure
163 * @param snapshotCapturedIndex
164 * @param snapshotCapturedTerm
166 void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm);
169 * Sets the Replicated log to state after snapshot success.
171 void snapshotCommit();
174 * Restores the replicated log to a state in the event of a save snapshot failure
176 void snapshotRollback();
179 * Size of the data in the log (in bytes)