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);
79 * @param replicatedLogEntry
81 void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry);
85 * @param index the index of the log entry
87 List<ReplicatedLogEntry> getFrom(long index);
91 * @param index the index of the log entry
93 List<ReplicatedLogEntry> getFrom(long index, int max);
102 * Checks if the entry at the specified index is present or not
104 * @param index the index of the log entry
105 * @return true if the entry is present in the in-memory journal
107 boolean isPresent(long index);
110 * Checks if the entry is present in a snapshot
112 * @param index the index of the log entry
113 * @return true if the entry is in the snapshot. false if the entry is not
114 * in the snapshot even if the entry may be present in the replicated log
116 boolean isInSnapshot(long index);
121 * @return an object representing the snapshot if it exists. null otherwise
123 ByteString getSnapshot();
126 * Get the index of the snapshot
128 * @return the index from which the snapshot was created. -1 otherwise.
130 long getSnapshotIndex();
133 * Get the term of the snapshot
135 * @return the term of the index from which the snapshot was created. -1
138 long getSnapshotTerm();
141 * sets the snapshot index in the replicated log
142 * @param snapshotIndex
144 void setSnapshotIndex(long snapshotIndex);
148 * @param snapshotTerm
150 public void setSnapshotTerm(long snapshotTerm);
153 * sets the snapshot in bytes
156 public void setSnapshot(ByteString snapshot);
159 * Clears the journal entries with startIndex(inclusive) and endIndex (exclusive)
163 public void clear(int startIndex, int endIndex);
166 * Handles all the bookkeeping in order to perform a rollback in the
167 * event of SaveSnapshotFailure
169 * @param snapshotCapturedIndex
170 * @param snapshotCapturedTerm
172 public void snapshotPreCommit(ByteString snapshot,
173 long snapshotCapturedIndex, long snapshotCapturedTerm);
176 * Sets the Replicated log to state after snapshot success.
178 public void snapshotCommit();
181 * Restores the replicated log to a state in the event of a save snapshot failure
183 public void snapshotRollback();