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 * Remove all the entries from the logs >= index
49 * @param index the index of the log entry
51 void removeFrom(long index);
55 * Remove all entries starting from the specified entry and persist the
60 void removeFromAndPersist(long index);
63 * Append an entry to the log
64 * @param replicatedLogEntry
66 void append(ReplicatedLogEntry replicatedLogEntry);
70 * @param replicatedLogEntry
72 void appendAndPersist(final ReplicatedLogEntry replicatedLogEntry);
76 * @param index the index of the log entry
78 List<ReplicatedLogEntry> getFrom(long index);
88 * Checks if the entry at the specified index is present or not
90 * @param index the index of the log entry
91 * @return true if the entry is present in the in-memory journal
93 boolean isPresent(long index);
96 * Checks if the entry is present in a snapshot
98 * @param index the index of the log entry
99 * @return true if the entry is in the snapshot. false if the entry is not
100 * in the snapshot even if the entry may be present in the replicated log
102 boolean isInSnapshot(long index);
107 * @return an object representing the snapshot if it exists. null otherwise
109 Object getSnapshot();
112 * Get the index of the snapshot
114 * @return the index from which the snapshot was created. -1 otherwise.
116 long getSnapshotIndex();
119 * Get the term of the snapshot
121 * @return the term of the index from which the snapshot was created. -1
124 long getSnapshotTerm();