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 com.google.protobuf.ByteString;
13 import java.util.List;
16 * Represents the ReplicatedLog that needs to be kept in sync by the RaftActor
18 public interface ReplicatedLog {
20 * Get a replicated log entry at the specified index
22 * @param index the index of the log entry
23 * @return the ReplicatedLogEntry at index. null if index less than 0 or
24 * greater than the size of the in-memory journal.
26 ReplicatedLogEntry get(long index);
30 * Get the last replicated log entry
34 ReplicatedLogEntry last();
49 * To be called when we need to remove entries from the in-memory log.
50 * This method will remove all entries >= index. This method should be used
51 * during recovery to appropriately trim the log based on persisted
54 * @param index the index of the log entry
56 void 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);
92 * @param index the index of the log entry
94 List<ReplicatedLogEntry> getFrom(long index);
98 * @param index the index of the log entry
100 List<ReplicatedLogEntry> getFrom(long index, int max);
109 * Checks if the entry at the specified index is present or not
111 * @param index the index of the log entry
112 * @return true if the entry is present in the in-memory journal
114 boolean isPresent(long index);
117 * Checks if the entry is present in a snapshot
119 * @param index the index of the log entry
120 * @return true if the entry is in the snapshot. false if the entry is not
121 * in the snapshot even if the entry may be present in the replicated log
123 boolean isInSnapshot(long index);
128 * @return an object representing the snapshot if it exists. null otherwise
130 ByteString getSnapshot();
133 * Get the index of the snapshot
135 * @return the index from which the snapshot was created. -1 otherwise.
137 long getSnapshotIndex();
140 * Get the term of the snapshot
142 * @return the term of the index from which the snapshot was created. -1
145 long getSnapshotTerm();
148 * sets the snapshot index in the replicated log
149 * @param snapshotIndex
151 void setSnapshotIndex(long snapshotIndex);
155 * @param snapshotTerm
157 public void setSnapshotTerm(long snapshotTerm);
160 * sets the snapshot in bytes
163 public void setSnapshot(ByteString snapshot);
166 * Clears the journal entries with startIndex(inclusive) and endIndex (exclusive)
170 public void clear(int startIndex, int endIndex);
173 * Handles all the bookkeeping in order to perform a rollback in the
174 * event of SaveSnapshotFailure
176 * @param snapshotCapturedIndex
177 * @param snapshotCapturedTerm
179 public void snapshotPreCommit(ByteString snapshot,
180 long snapshotCapturedIndex, long snapshotCapturedTerm);
183 * Sets the Replicated log to state after snapshot success.
185 public void snapshotCommit();
188 * Restores the replicated log to a state in the event of a save snapshot failure
190 public void snapshotRollback();