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 java.util.List;
14 * Represents the ReplicatedLog that needs to be kept in sync by the RaftActor
16 public interface ReplicatedLog {
18 * Get a replicated log entry at the specified index
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.
24 ReplicatedLogEntry get(long index);
28 * Get the last replicated log entry
32 ReplicatedLogEntry last();
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
52 * @param index the index of the log entry
54 void removeFrom(long index);
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
62 * The persisted information would then be used during recovery to properly
63 * reconstruct the state of the in-memory replicated log
65 * @param index the index of the log entry
67 void removeFromAndPersist(long index);
70 * Append an entry to the log
71 * @param replicatedLogEntry
73 void append(ReplicatedLogEntry replicatedLogEntry);
76 * Optimization method to increase the capacity of the journal log prior to appending entries.
78 * @param amount the amount to increase by
80 void increaseJournalLogCapacity(int amount);
84 * @param replicatedLogEntry
86 void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry);
90 * @param index the index of the log entry
92 List<ReplicatedLogEntry> getFrom(long index);
96 * @param index the index of the log entry
98 List<ReplicatedLogEntry> getFrom(long index, int max);
107 * Checks if the entry at the specified index is present or not
109 * @param index the index of the log entry
110 * @return true if the entry is present in the in-memory journal
112 boolean isPresent(long index);
115 * Checks if the entry is present in a snapshot
117 * @param index the index of the log entry
118 * @return true if the entry is in the snapshot. false if the entry is not
119 * in the snapshot even if the entry may be present in the replicated log
121 boolean isInSnapshot(long index);
124 * Get the index of the snapshot
126 * @return the index from which the snapshot was created. -1 otherwise.
128 long getSnapshotIndex();
131 * Get the term of the snapshot
133 * @return the term of the index from which the snapshot was created. -1
136 long getSnapshotTerm();
139 * sets the snapshot index in the replicated log
140 * @param snapshotIndex
142 void setSnapshotIndex(long snapshotIndex);
146 * @param snapshotTerm
148 void setSnapshotTerm(long snapshotTerm);
151 * Clears the journal entries with startIndex(inclusive) and endIndex (exclusive)
155 void clear(int startIndex, int endIndex);
158 * Handles all the bookkeeping in order to perform a rollback in the
159 * event of SaveSnapshotFailure
160 * @param snapshotCapturedIndex
161 * @param snapshotCapturedTerm
163 void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm);
166 * Sets the Replicated log to state after snapshot success.
168 void snapshotCommit();
171 * Restores the replicated log to a state in the event of a save snapshot failure
173 void snapshotRollback();
176 * Size of the data in the log (in bytes)