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
54 * @return the adjusted index of the first log entry removed or -1 if log entry not found.
56 long removeFrom(long index);
60 * To be called when we need to remove entries from the in-memory log and we
61 * need that information persisted to disk. This method will remove all
64 * The persisted information would then be used during recovery to properly
65 * reconstruct the state of the in-memory replicated log
67 * @param index the index of the log entry
69 void removeFromAndPersist(long index);
72 * Append an entry to the log
73 * @param replicatedLogEntry
75 void append(ReplicatedLogEntry replicatedLogEntry);
78 * Optimization method to increase the capacity of the journal log prior to appending entries.
80 * @param amount the amount to increase by
82 void increaseJournalLogCapacity(int amount);
86 * @param replicatedLogEntry
88 void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry);
90 void appendAndPersist(ReplicatedLogEntry replicatedLogEntry, Procedure<ReplicatedLogEntry> callback);
94 * @param index the index of the log entry
96 List<ReplicatedLogEntry> getFrom(long index);
100 * @param index the index of the log entry
102 List<ReplicatedLogEntry> getFrom(long index, int max);
111 * Checks if the entry at the specified index is present or not
113 * @param index the index of the log entry
114 * @return true if the entry is present in the in-memory journal
116 boolean isPresent(long index);
119 * Checks if the entry is present in a snapshot
121 * @param index the index of the log entry
122 * @return true if the entry is in the snapshot. false if the entry is not
123 * in the snapshot even if the entry may be present in the replicated log
125 boolean isInSnapshot(long index);
128 * Get the index of the snapshot
130 * @return the index from which the snapshot was created. -1 otherwise.
132 long getSnapshotIndex();
135 * Get the term of the snapshot
137 * @return the term of the index from which the snapshot was created. -1
140 long getSnapshotTerm();
143 * sets the snapshot index in the replicated log
144 * @param snapshotIndex
146 void setSnapshotIndex(long snapshotIndex);
150 * @param snapshotTerm
152 void setSnapshotTerm(long snapshotTerm);
155 * Clears the journal entries with startIndex(inclusive) and endIndex (exclusive)
159 void clear(int startIndex, int endIndex);
162 * Handles all the bookkeeping in order to perform a rollback in the
163 * event of SaveSnapshotFailure
164 * @param snapshotCapturedIndex
165 * @param snapshotCapturedTerm
167 void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm);
170 * Sets the Replicated log to state after snapshot success.
172 void snapshotCommit();
175 * Restores the replicated log to a state in the event of a save snapshot failure
177 void snapshotRollback();
180 * Size of the data in the log (in bytes)