Class AbstractReplicatedLogImpl
- java.lang.Object
-
- org.opendaylight.controller.cluster.raft.AbstractReplicatedLogImpl
-
- All Implemented Interfaces:
ReplicatedLog
public abstract class AbstractReplicatedLogImpl extends Object implements ReplicatedLog
Abstract class handling the mapping of logical LogEntry Index and the physical list index.
-
-
Field Summary
-
Fields inherited from interface org.opendaylight.controller.cluster.raft.ReplicatedLog
NO_MAX_SIZE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractReplicatedLogImpl()protectedAbstractReplicatedLogImpl(long snapshotIndex, long snapshotTerm, List<ReplicatedLogEntry> unAppliedEntries, String logContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intadjustedIndex(long logEntryIndex)booleanappend(ReplicatedLogEntry replicatedLogEntry)Appends an entry to the log.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).ReplicatedLogEntryget(long logEntryIndex)Return the replicated log entry at the specified index.List<ReplicatedLogEntry>getFrom(long logEntryIndex)Returns a list of log entries starting from the given index to the end of the log.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.longgetSnapshotIndex()Returns the index of the snapshot.longgetSnapshotTerm()Returns the term of the snapshot.voidincreaseJournalLogCapacity(int amount)Optimization method to increase the capacity of the journal log prior to appending entries.booleanisInSnapshot(long logEntryIndex)Checks if the entry is present in a snapshot.booleanisPresent(long logEntryIndex)Checks if the entry at the specified index is present or not.ReplicatedLogEntrylast()Return the last replicated log entry in the log or null of not found.longlastIndex()Return the index of the last entry in the log or -1 if the log is empty.longlastTerm()Return the term of the last entry in the log or -1 if the log is empty.longremoveFrom(long logEntryIndex)Removes entries from the in-memory log starting at the given index.voidsetSnapshotIndex(long snapshotIndex)Sets the snapshot index in the replicated log.voidsetSnapshotTerm(long snapshotTerm)Sets snapshot term.longsize()Returns the number of entries in the journal.voidsnapshotCommit(boolean updateDataSize)Sets the Replicated log to state after snapshot success.voidsnapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm)Handles all the bookkeeping in order to perform a rollback in the event of SaveSnapshotFailure.voidsnapshotRollback()Restores 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, wait
-
Methods inherited from interface org.opendaylight.controller.cluster.raft.ReplicatedLog
appendAndPersist, captureSnapshotIfReady, removeFromAndPersist, shouldCaptureSnapshot, snapshotCommit
-
-
-
-
Constructor Detail
-
AbstractReplicatedLogImpl
protected AbstractReplicatedLogImpl(long snapshotIndex, long snapshotTerm, List<ReplicatedLogEntry> unAppliedEntries, String logContext)
-
AbstractReplicatedLogImpl
protected AbstractReplicatedLogImpl()
-
-
Method Detail
-
adjustedIndex
protected int adjustedIndex(long logEntryIndex)
-
get
public ReplicatedLogEntry get(long logEntryIndex)
Description copied from interface:ReplicatedLogReturn the replicated log entry at the specified index.- Specified by:
getin 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
-
last
public ReplicatedLogEntry 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.
-
lastIndex
public long lastIndex()
Description copied from interface:ReplicatedLogReturn the index of the last entry in the log or -1 if the log is empty.- Specified by:
lastIndexin interfaceReplicatedLog- Returns:
- the index of the last entry in the log or -1 if the log is empty.
-
lastTerm
public long lastTerm()
Description copied from interface:ReplicatedLogReturn the term of the last entry in the log or -1 if the log is empty.- Specified by:
lastTermin interfaceReplicatedLog- Returns:
- the term of the last entry in the log or -1 if the log is empty.
-
removeFrom
public long removeFrom(long logEntryIndex)
Description copied from interface:ReplicatedLogRemoves entries from the in-memory log starting at the given index.- Specified by:
removeFromin interfaceReplicatedLog- Parameters:
logEntryIndex- 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
public boolean append(ReplicatedLogEntry replicatedLogEntry)
Description copied from interface:ReplicatedLogAppends an entry to the log.- Specified by:
appendin interfaceReplicatedLog- Parameters:
replicatedLogEntry- the entry to append- Returns:
- true if the entry was successfully appended, false otherwise. An entry can fail to append if the index is already included in the log.
-
increaseJournalLogCapacity
public 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
public List<ReplicatedLogEntry> getFrom(long logEntryIndex)
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
public List<ReplicatedLogEntry> getFrom(long logEntryIndex, int maxEntries, long maxDataSize)
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- Returns:
- the List of entries meeting the criteria.
-
size
public 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 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 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
-
getSnapshotIndex
public long getSnapshotIndex()
Description copied from interface:ReplicatedLogReturns the index of the snapshot.- Specified by:
getSnapshotIndexin interfaceReplicatedLog- Returns:
- the index from which the snapshot was created. -1 otherwise.
-
getSnapshotTerm
public long getSnapshotTerm()
Description copied from interface:ReplicatedLogReturns the term of the snapshot.- Specified by:
getSnapshotTermin interfaceReplicatedLog- Returns:
- the term of the index from which the snapshot was created. -1 otherwise
-
setSnapshotIndex
public 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 void setSnapshotTerm(long snapshotTerm)
Description copied from interface:ReplicatedLogSets snapshot term.- Specified by:
setSnapshotTermin interfaceReplicatedLog- Parameters:
snapshotTerm- the term to set
-
clear
public 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)
-
snapshotPreCommit
public 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 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 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
-
-