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.
  • Constructor Details

    • AbstractReplicatedLog

      protected AbstractReplicatedLog(@NonNull String memberId)
  • Method Details

    • adjustedIndex

      protected final int adjustedIndex(long logEntryIndex)
    • resetToLog

      public final void resetToLog(ReplicatedLog prev)
      Description copied from interface: ReplicatedLog
      Reset interal state to match specified ReplicatedLog.
      Specified by:
      resetToLog in interface ReplicatedLog
      Parameters:
      prev - the log to reset to
    • resetToSnapshot

      public final void resetToSnapshot(Snapshot snapshot)
      Description copied from interface: ReplicatedLog
      Reset internal state to specified Snapshot.
      Specified by:
      resetToSnapshot in interface ReplicatedLog
      Parameters:
      snapshot - snapshot to reset to
    • entryAt

      public final LogEntry entryAt(long offset)
      Description copied from interface: ReplicatedLog
      Returns the entry and specified offset.
      Specified by:
      entryAt in interface ReplicatedLog
      Parameters:
      offset - the offset
      Returns:
      the LogEntry
    • lookup

      public final T lookup(long logEntryIndex)
      Description copied from interface: ReplicatedLog
      Return the replicated log entry at the specified index.
      Specified by:
      lookup in interface ReplicatedLog
      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

      public final ReplicatedLog.StoredEntryMeta lookupStoredMeta(long index)
      Description copied from interface: ReplicatedLog
      Return ReplicatedLog.StoredEntryMeta a replicated entry.
      Specified by:
      lookupStoredMeta in interface ReplicatedLog
      Parameters:
      index - the index of the log entry
      Returns:
      the ReplicatedLog.StoredEntryMeta if found, otherwise null if the adjusted index less than 0 or greater than the size of the in-memory journal
    • last

      public final T last()
      Description copied from interface: ReplicatedLog
      Return the last replicated log entry in the log or null of not found.
      Specified by:
      last in interface ReplicatedLog
      Returns:
      the last replicated log entry in the log or null of not found.
    • getCommitIndex

      public final long getCommitIndex()
      Description copied from interface: ReplicatedLog
      Returns the index of highest log entry known to be committed.
      Specified by:
      getCommitIndex in interface ReplicatedLog
      Returns:
      index of highest log entry known to be committed.
    • setCommitIndex

      public final void setCommitIndex(long commitIndex)
      Description copied from interface: ReplicatedLog
      Sets the index of highest log entry known to be committed.
      Specified by:
      setCommitIndex in interface ReplicatedLog
      Parameters:
      commitIndex - new commit index
    • getLastApplied

      public final long getLastApplied()
      Description copied from interface: ReplicatedLog
      Returns index of highest log entry applied to state machine.
      Specified by:
      getLastApplied in interface ReplicatedLog
      Returns:
      index of highest log entry applied to state machine.
    • setLastApplied

      public final void setLastApplied(long lastApplied)
      Description copied from interface: ReplicatedLog
      Sets index of highest log entry applied to state machine.
      Specified by:
      setLastApplied in interface ReplicatedLog
      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

      public final boolean append(LogEntry entry)
      Description copied from interface: ReplicatedLog
      Appends an entry to the log if its index is already included in the log.
      Specified by:
      append in interface ReplicatedLog
      Parameters:
      entry - the entry to append
      Returns:
      true if the entry was successfully appended, false otherwise.
    • appendImpl

      protected final boolean appendImpl(@NonNull T entry)
    • adoptEntry

      @NonNullByDefault protected abstract @NonNull T adoptEntry(LogEntry entry)
    • increaseJournalLogCapacity

      public final void increaseJournalLogCapacity(int amount)
      Description copied from interface: ReplicatedLog
      Optimization method to increase the capacity of the journal log prior to appending entries.
      Specified by:
      increaseJournalLogCapacity in interface ReplicatedLog
      Parameters:
      amount - the amount to increase by
    • getFrom

      public final List<ReplicatedLogEntry> getFrom(long logEntryIndex)
      Description copied from interface: ReplicatedLog
      Returns a list of log entries starting from the given index to the end of the log.
      Specified by:
      getFrom in interface ReplicatedLog
      Parameters:
      logEntryIndex - the index of the first log entry to get.
      Returns:
      the List of entries
    • getFrom

      public final List<ReplicatedLogEntry> getFrom(long logEntryIndex, int maxEntries, long maxDataSize)
      Description copied from interface: ReplicatedLog
      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.
      Specified by:
      getFrom in interface ReplicatedLog
      Parameters:
      logEntryIndex - the index of the first log entry to get
      maxEntries - the maximum number of entries to get
      maxDataSize - 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: ReplicatedLog
      Returns the number of entries in the journal.
      Specified by:
      size in interface ReplicatedLog
      Returns:
      the number of entries
    • dataSize

      public int dataSize()
      Description copied from interface: ReplicatedLog
      Returns the size of the data in the log (in bytes).
      Specified by:
      dataSize in interface ReplicatedLog
      Returns:
      the size of the data in the log (in bytes)
    • isPresent

      public final boolean isPresent(long logEntryIndex)
      Description copied from interface: ReplicatedLog
      Checks if the entry at the specified index is present or not.
      Specified by:
      isPresent in interface ReplicatedLog
      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: ReplicatedLog
      Checks if the entry is present in a snapshot.
      Specified by:
      isInSnapshot in interface ReplicatedLog
      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: ReplicatedLog
      Returns the journal index corresponding to the first entry in the journal.
      Specified by:
      firstJournalIndex in interface ReplicatedLog
      Returns:
      the journal index corresponding to the first entry in the journal
    • lastAppliedJournalIndex

      public final long lastAppliedJournalIndex()
      Description copied from interface: ReplicatedLog
      Returns the journalIndex corresponding to ReplicatedLog.getLastApplied().
      Specified by:
      lastAppliedJournalIndex in interface ReplicatedLog
      Returns:
      the journalIndex corresponding to ReplicatedLog.getLastApplied()
    • setFirstJournalIndex

      public final void setFirstJournalIndex(long newFirstJournalIndex)
      Description copied from interface: ReplicatedLog
      Specified by:
      setFirstJournalIndex in interface ReplicatedLog
      Parameters:
      newFirstJournalIndex - the new value of ReplicatedLog.firstJournalIndex().
    • getSnapshotIndex

      public final long getSnapshotIndex()
      Description copied from interface: ReplicatedLog
      Returns the index from which the snapshot was created, -1 otherwise.
      Specified by:
      getSnapshotIndex in interface ReplicatedLog
      Returns:
      the index from which the snapshot was created, -1 otherwise
    • getSnapshotTerm

      public final long getSnapshotTerm()
      Description copied from interface: ReplicatedLog
      Returns the term of the index from which the snapshot was created, -1 otherwise.
      Specified by:
      getSnapshotTerm in interface ReplicatedLog
      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: ReplicatedLog
      Sets the snapshot index in the replicated log.
      Specified by:
      setSnapshotIndex in interface ReplicatedLog
      Parameters:
      snapshotIndex - the index to set
    • setSnapshotTerm

      public final void setSnapshotTerm(long snapshotTerm)
      Description copied from interface: ReplicatedLog
      Sets snapshot term.
      Specified by:
      setSnapshotTerm in interface ReplicatedLog
      Parameters:
      snapshotTerm - the term to set
    • clear

      public final void clear(int startIndex, int endIndex)
      Description copied from interface: ReplicatedLog
      Clears the journal entries with startIndex (inclusive) and endIndex (exclusive).
      Specified by:
      clear in interface ReplicatedLog
      Parameters:
      startIndex - the start index (inclusive)
      endIndex - the end index (exclusive)
    • clear

      @Deprecated(since="11.0.0", forRemoval=true) public final void clear()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: ReplicatedLog
      Clears all entries.
      Specified by:
      clear in interface ReplicatedLog
    • snapshotPreCommit

      public final void snapshotPreCommit(long snapshotCapturedIndex, long snapshotCapturedTerm)
      Description copied from interface: ReplicatedLog
      Handles all the bookkeeping in order to perform a rollback in the event of SaveSnapshotFailure.
      Specified by:
      snapshotPreCommit in interface ReplicatedLog
      Parameters:
      snapshotCapturedIndex - the new snapshot index
      snapshotCapturedTerm - the new snapshot term
    • snapshotCommit

      public final void snapshotCommit(boolean updateDataSize)
      Description copied from interface: ReplicatedLog
      Sets the Replicated log to state after snapshot success. Most users will want to use ReplicatedLog.snapshotCommit() instead.
      Specified by:
      snapshotCommit in interface ReplicatedLog
      Parameters:
      updateDataSize - true if ReplicatedLog.dataSize() should also be updated
    • snapshotRollback

      public final void snapshotRollback()
      Description copied from interface: ReplicatedLog
      Restores the replicated log to a state in the event of a save snapshot failure.
      Specified by:
      snapshotRollback in interface ReplicatedLog
    • newCaptureSnapshot

      public final @NonNull SnapshotManager.CaptureSnapshot newCaptureSnapshot(EntryMeta lastLogEntry, long replicatedToAllIndex, boolean mandatoryTrim, boolean hasFollowers)
      Description copied from interface: ReplicatedLog
      Constructs a SnapshotManager.CaptureSnapshot instance.
      Specified by:
      newCaptureSnapshot in interface ReplicatedLog
      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.