*/
package org.opendaylight.controller.cluster.raft;
-import akka.japi.Procedure;
import java.util.List;
+import java.util.function.Consumer;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
*/
@Nullable ReplicatedLogEntry get(long index);
+ /**
+ * Return metadata about a replicated entry.
+ *
+ * @param index the index of the log entry
+ * @return the RaftEntryMeta if found, otherwise null if the adjusted index less than 0 or
+ * greater than the size of the in-memory journal
+ */
+ default @Nullable RaftEntryMeta lookupMeta(final long index) {
+ return get(index);
+ }
+
/**
* Return the last replicated log entry in the log or null of not found.
*
*/
@Nullable ReplicatedLogEntry last();
+ /**
+ * Return the last replicated log entry in the log or null of not found.
+ *
+ * @return the last replicated log entry in the log or null of not found.
+ */
+ default @Nullable RaftEntryMeta lastMeta() {
+ return last();
+ }
+
/**
* Return the index of the last entry in the log or -1 if the log is empty.
*
* Appends an entry to the in-memory log and persists it as well.
*
* @param replicatedLogEntry the entry to append
- * @param callback the Procedure to be notified when persistence is complete (optional).
+ * @param callback the callback to be notified when persistence is complete (optional).
* @param doAsync if true, the persistent actor can receive subsequent messages to process in between the persist
* call and the execution of the associated callback. If false, subsequent messages are stashed and get
* delivered after persistence is complete and the associated callback is executed. In either case the
* @return true if the entry was successfully appended, false otherwise.
*/
boolean appendAndPersist(@NonNull ReplicatedLogEntry replicatedLogEntry,
- @Nullable Procedure<ReplicatedLogEntry> callback, boolean doAsync);
+ @Nullable Consumer<ReplicatedLogEntry> callback, boolean doAsync);
/**
* Returns a list of log entries starting from the given index to the end of the log.
void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm);
/**
- * Sets the Replicated log to state after snapshot success.
+ * Sets the Replicated log to state after snapshot success. This method is equivalent to
+ * {@code snapshotCommit(true)}.
+ */
+ default void snapshotCommit() {
+ snapshotCommit(true);
+ }
+
+ /**
+ * Sets the Replicated log to state after snapshot success. Most users will want to use {@link #snapshotCommit()}
+ * instead.
+ *
+ * @param updateDataSize true if {@link #dataSize()} should also be updated
*/
- void snapshotCommit();
+ void snapshotCommit(boolean updateDataSize);
/**
* Restores the replicated log to a state in the event of a save snapshot failure.
*
* @param replicatedLogEntry the last log entry.
*/
- void captureSnapshotIfReady(ReplicatedLogEntry replicatedLogEntry);
+ void captureSnapshotIfReady(RaftEntryMeta replicatedLogEntry);
/**
* Determines if a snapshot should be captured based on the count/memory consumed.