Interface ReplicatedLog
- All Known Implementing Classes:
 AbstractReplicatedLog
@NonNullByDefault
public interface ReplicatedLog
Represents the ReplicatedLog that needs to be kept in sync by the RaftActor.
- 
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordA combination ofEntryMetaand indicator of whether the entry is stable. - 
Method Summary
Modifier and TypeMethodDescriptionbooleanAppends an entry to the log if its index is already included in the log.booleanappendReceived(LogEntry entry, @Nullable Consumer<LogEntry> callback) Appends an entry received by a follower to the in-memory log and persists it as well, returning an indication whether or not a snapshot should be taken.booleanappendSubmitted(long index, long term, Payload command, Consumer<ReplicatedLogEntry> callback) Appends an entry submitted on the leader to the in-memory log and persists it as well.voidcaptureSnapshotIfReady(EntryMeta lastEntry) Determines if a snapshot needs to be captured based on the count/memory consumed and initiates the capture.voidclear()Deprecated, for removal: This API element is subject to removal in a future version.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).entryAt(long offset) Returns the entry and specified offset.longReturns the journal index corresponding to the first entry in the journal.longReturns the index of highest log entry known to be committed.getFrom(long index) Returns a list of log entries starting from the given index to the end of the log.getFrom(long index, 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.longReturns index of highest log entry applied to state machine.default longgetLogEntryIndex(long index) Returns the actual index of the entry in replicated log for the given index or -1 if not found.default longgetLogEntryOrSnapshotTerm(long index) Returns the actual term of the entry in the replicated log for the given index or, if not present, returns the snapshot term if the given index is in the snapshot or -1 otherwise.default longgetLogEntryTerm(long index) Returns the actual term of the entry in the replicated log for the given index or -1 if not found.longReturns the index from which the snapshot was created,-1otherwise.longReturns the term of the index from which the snapshot was created, -1 otherwise.voidincreaseJournalLogCapacity(int amount) Optimization method to increase the capacity of the journal log prior to appending entries.booleanisInSnapshot(long index) Checks if the entry is present in a snapshot.default booleanisLogEntryPresent(long index) booleanisPresent(long index) Checks if the entry at the specified index is present or not.@Nullable LogEntrylast()Return the last replicated log entry in the log or null of not found.longReturns thejournalIndexcorresponding togetLastApplied().default longReturn the index of the last entry in the log or -1 if the log is empty.default @Nullable EntryMetalastMeta()Return the last replicated log entry in the log or null of not found.default longlastTerm()Return the term of the last entry in the log or -1 if the log is empty.@Nullable LogEntrylookup(long index) Return the replicated log entry at the specified index.default @Nullable EntryMetalookupMeta(long index) Return metadata about a replicated entry.@Nullable ReplicatedLog.StoredEntryMetalookupStoredMeta(long index) ReturnReplicatedLog.StoredEntryMetaa replicated entry.voidMark the current valuegetLastApplied()for recovery purposes.newCaptureSnapshot(@Nullable EntryMeta lastLogEntry, long replicatedToAllIndex, boolean mandatoryTrim, boolean hasFollowers) Constructs aSnapshotManager.CaptureSnapshotinstance.voidresetToLog(ReplicatedLog prev) Reset interal state to match specifiedReplicatedLog.voidresetToSnapshot(Snapshot snapshot) Reset internal state to specifiedSnapshot.voidsetCommitIndex(long commitIndex) Sets the index of highest log entry known to be committed.voidsetFirstJournalIndex(long newFirstJournalIndex) Sets thefirstJournalIndex()value.voidsetLastApplied(long lastApplied) Sets index of highest log entry applied to state machine.voidsetSnapshotIndex(long snapshotIndex) Sets the snapshot index in the replicated log.voidsetSnapshotTerm(long snapshotTerm) Sets snapshot term.booleanshouldCaptureSnapshot(long logIndex) Determines if a snapshot should be captured based on the count/memory consumed.longsize()Returns the number of entries in the journal.default voidSets the Replicated log to state after snapshot success.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.voidRestores the replicated log to a state in the event of a save snapshot failure.booleantrimToReceive(long nextIndex) Removes entries all entries from the log starting at the given index, resettinglastIndex()tonextIndex - 1. 
- 
Method Details
- 
entryAt
Returns the entry and specified offset.- Parameters:
 offset- the offset- Returns:
 - the 
LogEntry - Throws:
 IndexOutOfBoundsException- if the offset is out of range (offset < 0 || offset >= size())
 - 
lookup
Return the replicated log entry at the specified index.- Parameters:
 index- 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
 
 - 
lookupMeta
Return metadata about a replicated entry.- Parameters:
 index- the index of the log entry- Returns:
 - the 
EntryMetaif found, otherwise null if the adjusted index less than 0 or greater than the size of the in-memory journal 
 - 
lookupStoredMeta
ReturnReplicatedLog.StoredEntryMetaa replicated entry.- 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
@Nullable LogEntry last()Return the last replicated log entry in the log or null of not found.- Returns:
 - the last replicated log entry in the log or null of not found.
 
 - 
lastMeta
Return the last replicated log entry in the log or null of not found.- Returns:
 - the last replicated log entry in the log or null of not found.
 
 - 
lastIndex
default long lastIndex()Return the index of the last entry in the log or -1 if the log is empty.- Returns:
 - the index of the last entry in the log or -1 if the log is empty.
 
 - 
lastTerm
default long lastTerm()Return the term of the last entry in the log or -1 if the log is empty.- Returns:
 - the term of the last entry in the log or -1 if the log is empty.
 
 - 
getCommitIndex
long getCommitIndex()Returns the index of highest log entry known to be committed.- Returns:
 - index of highest log entry known to be committed.
 
 - 
setCommitIndex
void setCommitIndex(long commitIndex) Sets the index of highest log entry known to be committed.- Parameters:
 commitIndex- new commit index
 - 
getLastApplied
long getLastApplied()Returns index of highest log entry applied to state machine.- Returns:
 - index of highest log entry applied to state machine.
 
 - 
setLastApplied
void setLastApplied(long lastApplied) Sets index of highest log entry applied to state machine.- Parameters:
 lastApplied- the new applied index.
 - 
markLastApplied
void markLastApplied()Mark the current valuegetLastApplied()for recovery purposes. - 
trimToReceive
boolean trimToReceive(long nextIndex) Removes entries all entries from the log starting at the given index, resettinglastIndex()tonextIndex - 1.- Parameters:
 nextIndex- the index of the first log entry to remove- Returns:
 trueif the operation succeeds
 - 
append
Appends an entry to the log if its index is already included in the log.- Parameters:
 entry- the entry to append- Returns:
 trueif the entry was successfully appended,falseotherwise.
 - 
increaseJournalLogCapacity
void increaseJournalLogCapacity(int amount) Optimization method to increase the capacity of the journal log prior to appending entries.- Parameters:
 amount- the amount to increase by
 - 
appendReceived
Appends an entry received by a follower to the in-memory log and persists it as well, returning an indication whether or not a snapshot should be taken.- Parameters:
 entry- the entry to appendcallback- optional callback to be notified when persistence is complete- Returns:
 trueif the journal requires trimming and a snapshot needs to be taken
 - 
appendSubmitted
boolean appendSubmitted(long index, long term, Payload command, Consumer<ReplicatedLogEntry> callback) Appends an entry submitted on the leader to the in-memory log and persists it as well.- Parameters:
 index- the indexterm- the termcommand- the commandcallback- the callback to be notified when persistence is complete- Returns:
 trueif the entry was successfully appended, false otherwise
 - 
getFrom
Returns a list of log entries starting from the given index to the end of the log.- Parameters:
 index- the index of the first log entry to get.- Returns:
 - the List of entries
 
 - 
getFrom
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.- Parameters:
 index- 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
long size()Returns the number of entries in the journal.- Returns:
 - the number of entries
 
 - 
isPresent
boolean isPresent(long index) Checks if the entry at the specified index is present or not.- Parameters:
 index- the index of the log entry- Returns:
 - true if the entry is present in the in-memory journal
 
 - 
isInSnapshot
boolean isInSnapshot(long index) Checks if the entry is present in a snapshot.- Parameters:
 index- 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
long firstJournalIndex()Returns the journal index corresponding to the first entry in the journal.- Returns:
 - the journal index corresponding to the first entry in the journal
 
 - 
setFirstJournalIndex
void setFirstJournalIndex(long newFirstJournalIndex) Sets thefirstJournalIndex()value.- Parameters:
 newFirstJournalIndex- the new value offirstJournalIndex().
 - 
lastAppliedJournalIndex
long lastAppliedJournalIndex()Returns thejournalIndexcorresponding togetLastApplied().- Returns:
 - the 
journalIndexcorresponding togetLastApplied() 
 - 
getSnapshotIndex
long getSnapshotIndex()Returns the index from which the snapshot was created,-1otherwise.- Returns:
 - the index from which the snapshot was created, 
-1otherwise 
 - 
getSnapshotTerm
long getSnapshotTerm()Returns the term of the index from which the snapshot was created, -1 otherwise.- Returns:
 - the term of the index from which the snapshot was created, -1 otherwise
 
 - 
setSnapshotIndex
void setSnapshotIndex(long snapshotIndex) Sets the snapshot index in the replicated log.- Parameters:
 snapshotIndex- the index to set
 - 
setSnapshotTerm
void setSnapshotTerm(long snapshotTerm) Sets snapshot term.- Parameters:
 snapshotTerm- the term to set
 - 
getLogEntryIndex
default long getLogEntryIndex(long index) Returns the actual index of the entry in replicated log for the given index or -1 if not found.- Returns:
 - the log entry index or -1 if not found
 
 - 
getLogEntryTerm
default long getLogEntryTerm(long index) Returns the actual term of the entry in the replicated log for the given index or -1 if not found.- Returns:
 - the log entry term or -1 if not found
 
 - 
getLogEntryOrSnapshotTerm
default long getLogEntryOrSnapshotTerm(long index) Returns the actual term of the entry in the replicated log for the given index or, if not present, returns the snapshot term if the given index is in the snapshot or -1 otherwise.- Returns:
 - the term or -1 otherwise
 
 - 
isLogEntryPresent
default boolean isLogEntryPresent(long index)  - 
clear
Deprecated, for removal: This API element is subject to removal in a future version.UseresetToSnapshot(Snapshot)instead.Clears all entries. - 
clear
void clear(int startIndex, int endIndex) Clears the journal entries with startIndex (inclusive) and endIndex (exclusive).- Parameters:
 startIndex- the start index (inclusive)endIndex- the end index (exclusive)
 - 
snapshotPreCommit
void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm) Handles all the bookkeeping in order to perform a rollback in the event of SaveSnapshotFailure.- Parameters:
 snapshotCapturedIndex- the new snapshot indexsnapshotCapturedTerm- the new snapshot term
 - 
snapshotCommit
default void snapshotCommit()Sets the Replicated log to state after snapshot success. This method is equivalent tosnapshotCommit(true). - 
snapshotCommit
void snapshotCommit(boolean updateDataSize) Sets the Replicated log to state after snapshot success. Most users will want to usesnapshotCommit()instead.- Parameters:
 updateDataSize- true ifdataSize()should also be updated
 - 
snapshotRollback
void snapshotRollback()Restores the replicated log to a state in the event of a save snapshot failure. - 
dataSize
int dataSize()Returns the size of the data in the log (in bytes).- Returns:
 - the size of the data in the log (in bytes)
 
 - 
captureSnapshotIfReady
Determines if a snapshot needs to be captured based on the count/memory consumed and initiates the capture.- Parameters:
 lastEntry- the last log entry.
 - 
shouldCaptureSnapshot
boolean shouldCaptureSnapshot(long logIndex) Determines if a snapshot should be captured based on the count/memory consumed.- Parameters:
 logIndex- the log index to use to determine if the log count has exceeded the threshold- Returns:
 - true if a snapshot should be captured, false otherwise
 
 - 
resetToLog
Reset interal state to match specifiedReplicatedLog.- Parameters:
 prev- the log to reset to
 - 
resetToSnapshot
Reset internal state to specifiedSnapshot.- Parameters:
 snapshot- snapshot to reset to
 - 
newCaptureSnapshot
SnapshotManager.CaptureSnapshot newCaptureSnapshot(@Nullable EntryMeta lastLogEntry, long replicatedToAllIndex, boolean mandatoryTrim, boolean hasFollowers) Constructs aSnapshotManager.CaptureSnapshotinstance.- 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.
 
 
 - 
 
resetToSnapshot(Snapshot)instead.