Class AbstractReplicatedLog<T extends ReplicatedLogEntry>
java.lang.Object
org.opendaylight.controller.cluster.raft.AbstractReplicatedLog<T>
- All Implemented Interfaces:
ReplicatedLog
public abstract class AbstractReplicatedLog<T extends ReplicatedLogEntry>
extends Object
implements ReplicatedLog
Abstract class handling the mapping of
logical LogEntry Index and the physical list index.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.opendaylight.controller.cluster.raft.ReplicatedLog
ReplicatedLog.StoredEntryMeta -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final intadjustedIndex(long logEntryIndex) protected abstract @NonNull TadoptEntry(LogEntry entry) final booleanAppends an entry to the log if its index is already included in the log.protected final booleanappendImpl(@NonNull T entry) final voidclear()Deprecated, for removal: This API element is subject to removal in a future version.final voidclear(int startIndex, int endIndex) Clears the journal entries with startIndex (inclusive) and endIndex (exclusive).intdataSize()Returns the size of the data in the log (in bytes).final LogEntryentryAt(long offset) Returns the entry and specified offset.final longReturns the journal index corresponding to the first entry in the journal.final longReturns the index of highest log entry known to be committed.final List<ReplicatedLogEntry> getFrom(long logEntryIndex) Returns a list of log entries starting from the given index to the end of the log.final List<ReplicatedLogEntry> getFrom(long logEntryIndex, int maxEntries, long maxDataSize) Returns a list of log entries starting from the given index up to the given maximum of entries or the given maximum accumulated size, whichever comes first.final longReturns index of highest log entry applied to state machine.final longReturns the index from which the snapshot was created,-1otherwise.final longReturns the term of the index from which the snapshot was created, -1 otherwise.final voidincreaseJournalLogCapacity(int amount) Optimization method to increase the capacity of the journal log prior to appending entries.final booleanisInSnapshot(long logEntryIndex) Checks if the entry is present in a snapshot.final booleanisPresent(long logEntryIndex) Checks if the entry at the specified index is present or not.final Tlast()Return the last replicated log entry in the log or null of not found.final longReturns thejournalIndexcorresponding toReplicatedLog.getLastApplied().final Tlookup(long logEntryIndex) Return the replicated log entry at the specified index.lookupStoredMeta(long index) ReturnReplicatedLog.StoredEntryMetaa replicated entry.final @NonNull SnapshotManager.CaptureSnapshotnewCaptureSnapshot(EntryMeta lastLogEntry, long replicatedToAllIndex, boolean mandatoryTrim, boolean hasFollowers) Constructs aSnapshotManager.CaptureSnapshotinstance.protected final longremoveFrom(long fromIndex) Removes entries from the in-memory log starting at the given index.final voidresetToLog(ReplicatedLog prev) Reset interal state to match specifiedReplicatedLog.final voidresetToSnapshot(Snapshot snapshot) Reset internal state to specifiedSnapshot.final voidsetCommitIndex(long commitIndex) Sets the index of highest log entry known to be committed.final voidsetFirstJournalIndex(long newFirstJournalIndex) Sets theReplicatedLog.firstJournalIndex()value.final voidsetLastApplied(long lastApplied) Sets index of highest log entry applied to state machine.final voidsetSnapshotIndex(long snapshotIndex) Sets the snapshot index in the replicated log.final voidsetSnapshotTerm(long snapshotTerm) Sets snapshot term.final longsize()Returns the number of entries in the journal.final voidsnapshotCommit(boolean updateDataSize) Sets the Replicated log to state after snapshot success.final voidsnapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm) Handles all the bookkeeping in order to perform a rollback in the event of SaveSnapshotFailure.final voidRestores the replicated log to a state in the event of a save snapshot failure.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opendaylight.controller.cluster.raft.ReplicatedLog
appendReceived, appendSubmitted, captureSnapshotIfReady, getLogEntryIndex, getLogEntryOrSnapshotTerm, getLogEntryTerm, isLogEntryPresent, lastIndex, lastMeta, lastTerm, lookupMeta, markLastApplied, shouldCaptureSnapshot, snapshotCommit, trimToReceive
-
Constructor Details
-
AbstractReplicatedLog
-
-
Method Details
-
adjustedIndex
protected final int adjustedIndex(long logEntryIndex) -
resetToLog
Description copied from interface:ReplicatedLogReset interal state to match specifiedReplicatedLog.- Specified by:
resetToLogin interfaceReplicatedLog- Parameters:
prev- the log to reset to
-
resetToSnapshot
Description copied from interface:ReplicatedLogReset internal state to specifiedSnapshot.- Specified by:
resetToSnapshotin interfaceReplicatedLog- Parameters:
snapshot- snapshot to reset to
-
entryAt
Description copied from interface:ReplicatedLogReturns the entry and specified offset.- Specified by:
entryAtin interfaceReplicatedLog- Parameters:
offset- the offset- Returns:
- the
LogEntry
-
lookup
Description copied from interface:ReplicatedLogReturn the replicated log entry at the specified index.- Specified by:
lookupin interfaceReplicatedLog- Parameters:
logEntryIndex- the index of the log entry- Returns:
- the ReplicatedLogEntry if found, otherwise null if the adjusted index less than 0 or greater than the size of the in-memory journal
-
lookupStoredMeta
Description copied from interface:ReplicatedLogReturnReplicatedLog.StoredEntryMetaa replicated entry.- Specified by:
lookupStoredMetain interfaceReplicatedLog- Parameters:
index- the index of the log entry- Returns:
- the
ReplicatedLog.StoredEntryMetaif found, otherwise null if the adjusted index less than 0 or greater than the size of the in-memory journal
-
last
Description copied from interface:ReplicatedLogReturn the last replicated log entry in the log or null of not found.- Specified by:
lastin interfaceReplicatedLog- Returns:
- the last replicated log entry in the log or null of not found.
-
getCommitIndex
public final long getCommitIndex()Description copied from interface:ReplicatedLogReturns the index of highest log entry known to be committed.- Specified by:
getCommitIndexin interfaceReplicatedLog- Returns:
- index of highest log entry known to be committed.
-
setCommitIndex
public final void setCommitIndex(long commitIndex) Description copied from interface:ReplicatedLogSets the index of highest log entry known to be committed.- Specified by:
setCommitIndexin interfaceReplicatedLog- Parameters:
commitIndex- new commit index
-
getLastApplied
public final long getLastApplied()Description copied from interface:ReplicatedLogReturns index of highest log entry applied to state machine.- Specified by:
getLastAppliedin interfaceReplicatedLog- Returns:
- index of highest log entry applied to state machine.
-
setLastApplied
public final void setLastApplied(long lastApplied) Description copied from interface:ReplicatedLogSets index of highest log entry applied to state machine.- Specified by:
setLastAppliedin interfaceReplicatedLog- Parameters:
lastApplied- the new applied index.
-
removeFrom
protected final long removeFrom(long fromIndex) Removes entries from the in-memory log starting at the given index.- Parameters:
fromIndex- the index of the first log entry to remove- Returns:
- the adjusted index of the first log entry removed or -1 if the log entry is not found
-
append
Description copied from interface:ReplicatedLogAppends an entry to the log if its index is already included in the log.- Specified by:
appendin interfaceReplicatedLog- Parameters:
entry- the entry to append- Returns:
trueif the entry was successfully appended,falseotherwise.
-
appendImpl
-
adoptEntry
-
increaseJournalLogCapacity
public final void increaseJournalLogCapacity(int amount) Description copied from interface:ReplicatedLogOptimization method to increase the capacity of the journal log prior to appending entries.- Specified by:
increaseJournalLogCapacityin interfaceReplicatedLog- Parameters:
amount- the amount to increase by
-
getFrom
Description copied from interface:ReplicatedLogReturns a list of log entries starting from the given index to the end of the log.- Specified by:
getFromin interfaceReplicatedLog- Parameters:
logEntryIndex- the index of the first log entry to get.- Returns:
- the List of entries
-
getFrom
Description copied from interface:ReplicatedLogReturns a list of log entries starting from the given index up to the given maximum of entries or the given maximum accumulated size, whichever comes first.- Specified by:
getFromin interfaceReplicatedLog- Parameters:
logEntryIndex- the index of the first log entry to getmaxEntries- the maximum number of entries to getmaxDataSize- the maximum accumulated size of the log entries to get, negative means no limit- Returns:
- the List of entries meeting the criteria.
-
size
public final long size()Description copied from interface:ReplicatedLogReturns the number of entries in the journal.- Specified by:
sizein interfaceReplicatedLog- Returns:
- the number of entries
-
dataSize
public int dataSize()Description copied from interface:ReplicatedLogReturns the size of the data in the log (in bytes).- Specified by:
dataSizein interfaceReplicatedLog- Returns:
- the size of the data in the log (in bytes)
-
isPresent
public final boolean isPresent(long logEntryIndex) Description copied from interface:ReplicatedLogChecks if the entry at the specified index is present or not.- Specified by:
isPresentin interfaceReplicatedLog- Parameters:
logEntryIndex- the index of the log entry- Returns:
- true if the entry is present in the in-memory journal
-
isInSnapshot
public final boolean isInSnapshot(long logEntryIndex) Description copied from interface:ReplicatedLogChecks if the entry is present in a snapshot.- Specified by:
isInSnapshotin interfaceReplicatedLog- Parameters:
logEntryIndex- the index of the log entry- Returns:
- true if the entry is in the snapshot. false if the entry is not in the snapshot even if the entry may be present in the replicated log
-
firstJournalIndex
public final long firstJournalIndex()Description copied from interface:ReplicatedLogReturns the journal index corresponding to the first entry in the journal.- Specified by:
firstJournalIndexin interfaceReplicatedLog- Returns:
- the journal index corresponding to the first entry in the journal
-
lastAppliedJournalIndex
public final long lastAppliedJournalIndex()Description copied from interface:ReplicatedLogReturns thejournalIndexcorresponding toReplicatedLog.getLastApplied().- Specified by:
lastAppliedJournalIndexin interfaceReplicatedLog- Returns:
- the
journalIndexcorresponding toReplicatedLog.getLastApplied()
-
setFirstJournalIndex
public final void setFirstJournalIndex(long newFirstJournalIndex) Description copied from interface:ReplicatedLogSets theReplicatedLog.firstJournalIndex()value.- Specified by:
setFirstJournalIndexin interfaceReplicatedLog- Parameters:
newFirstJournalIndex- the new value ofReplicatedLog.firstJournalIndex().
-
getSnapshotIndex
public final long getSnapshotIndex()Description copied from interface:ReplicatedLogReturns the index from which the snapshot was created,-1otherwise.- Specified by:
getSnapshotIndexin interfaceReplicatedLog- Returns:
- the index from which the snapshot was created,
-1otherwise
-
getSnapshotTerm
public final long getSnapshotTerm()Description copied from interface:ReplicatedLogReturns the term of the index from which the snapshot was created, -1 otherwise.- Specified by:
getSnapshotTermin interfaceReplicatedLog- Returns:
- the term of the index from which the snapshot was created, -1 otherwise
-
setSnapshotIndex
public final void setSnapshotIndex(long snapshotIndex) Description copied from interface:ReplicatedLogSets the snapshot index in the replicated log.- Specified by:
setSnapshotIndexin interfaceReplicatedLog- Parameters:
snapshotIndex- the index to set
-
setSnapshotTerm
public final void setSnapshotTerm(long snapshotTerm) Description copied from interface:ReplicatedLogSets snapshot term.- Specified by:
setSnapshotTermin interfaceReplicatedLog- Parameters:
snapshotTerm- the term to set
-
clear
public final void clear(int startIndex, int endIndex) Description copied from interface:ReplicatedLogClears the journal entries with startIndex (inclusive) and endIndex (exclusive).- Specified by:
clearin interfaceReplicatedLog- Parameters:
startIndex- the start index (inclusive)endIndex- the end index (exclusive)
-
clear
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:ReplicatedLogClears all entries.- Specified by:
clearin interfaceReplicatedLog
-
snapshotPreCommit
public final void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm) Description copied from interface:ReplicatedLogHandles all the bookkeeping in order to perform a rollback in the event of SaveSnapshotFailure.- Specified by:
snapshotPreCommitin interfaceReplicatedLog- Parameters:
snapshotCapturedIndex- the new snapshot indexsnapshotCapturedTerm- the new snapshot term
-
snapshotCommit
public final void snapshotCommit(boolean updateDataSize) Description copied from interface:ReplicatedLogSets the Replicated log to state after snapshot success. Most users will want to useReplicatedLog.snapshotCommit()instead.- Specified by:
snapshotCommitin interfaceReplicatedLog- Parameters:
updateDataSize- true ifReplicatedLog.dataSize()should also be updated
-
snapshotRollback
public final void snapshotRollback()Description copied from interface:ReplicatedLogRestores the replicated log to a state in the event of a save snapshot failure.- Specified by:
snapshotRollbackin interfaceReplicatedLog
-
newCaptureSnapshot
public final @NonNull SnapshotManager.CaptureSnapshot newCaptureSnapshot(EntryMeta lastLogEntry, long replicatedToAllIndex, boolean mandatoryTrim, boolean hasFollowers) Description copied from interface:ReplicatedLogConstructs aSnapshotManager.CaptureSnapshotinstance.- Specified by:
newCaptureSnapshotin interfaceReplicatedLog- Parameters:
lastLogEntry- the last log entry for the snapshot.replicatedToAllIndex- the index of the last entry replicated to all followers.- Returns:
- a new CaptureSnapshot instance.
-