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);
77 * @param replicatedLogEntry
79 void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry);
83 * @param index the index of the log entry
85 List<ReplicatedLogEntry> getFrom(long index);
95 * Checks if the entry at the specified index is present or not
97 * @param index the index of the log entry
98 * @return true if the entry is present in the in-memory journal
100 boolean isPresent(long index);
103 * Checks if the entry is present in a snapshot
105 * @param index the index of the log entry
106 * @return true if the entry is in the snapshot. false if the entry is not
107 * in the snapshot even if the entry may be present in the replicated log
109 boolean isInSnapshot(long index);
114 * @return an object representing the snapshot if it exists. null otherwise
116 Object getSnapshot();
119 * Get the index of the snapshot
121 * @return the index from which the snapshot was created. -1 otherwise.
123 long getSnapshotIndex();
126 * Get the term of the snapshot
128 * @return the term of the index from which the snapshot was created. -1
131 long getSnapshotTerm();