Class FollowerLogInformation


  • public final class FollowerLogInformation
    extends Object
    The state of the followers log as known by the Leader.
    Author:
    Moiz Raja, Thomas Pantelis
    • Constructor Detail

      • FollowerLogInformation

        public FollowerLogInformation​(PeerInfo peerInfo,
                                      RaftActorContext context)
        Constructs an instance with no matching index.
        Parameters:
        peerInfo - the associated PeerInfo of the follower.
        context - the RaftActorContext.
    • Method Detail

      • decrNextIndex

        public boolean decrNextIndex​(long followerLastIndex)
        Decrements the value of the follower's next index, taking into account its reported last log index.
        Parameters:
        followerLastIndex - follower's last reported index.
        Returns:
        true if the next index was decremented, i.e. it was previously >= 0, false otherwise.
      • setNextIndex

        public boolean setNextIndex​(long nextIndex)
        Sets the index of the follower's next log entry.
        Parameters:
        nextIndex - the new index.
        Returns:
        true if the new index differed from the current index and the current index was updated, false otherwise.
      • incrMatchIndex

        public long incrMatchIndex()
        Increments the value of the follower's match index.
        Returns:
        the new value of matchIndex.
      • setMatchIndex

        public boolean setMatchIndex​(long matchIndex)
        Sets the index of the follower's highest log entry.
        Parameters:
        matchIndex - the new index.
        Returns:
        true if the new index differed from the current index and the current index was updated, false otherwise.
      • getId

        public String getId()
        Returns the identifier of the follower.
        Returns:
        the identifier of the follower.
      • getNextIndex

        public long getNextIndex()
        Returns the index of the next log entry to send to the follower.
        Returns:
        index of the follower's next log entry.
      • getMatchIndex

        public long getMatchIndex()
        Returns the index of highest log entry known to be replicated on the follower.
        Returns:
        the index of highest log entry.
      • isFollowerActive

        public boolean isFollowerActive()
        Checks if the follower is active by comparing the time of the last activity with the election time out. The follower is active if some activity has occurred for the follower within the election time out interval.
        Returns:
        true if follower is active, false otherwise.
      • markFollowerActive

        public void markFollowerActive()
        Marks the follower as active. This should be called when some activity has occurred for the follower.
      • markFollowerInActive

        public void markFollowerInActive()
        Marks the follower as inactive. This should only be called from unit tests.
      • nanosSinceLastActivity

        public long nanosSinceLastActivity()
        Returns the time since the last activity occurred for the follower.
        Returns:
        time in nanoseconds since the last activity from the follower.
      • okToReplicate

        public boolean okToReplicate​(long commitIndex)
        This method checks if the next replicate message can be sent to the follower. This is an optimization to avoid sending duplicate message too frequently if the last replicate message was sent and no reply has been received yet within the current heart beat interval
        Parameters:
        commitIndex - current commitIndex
        Returns:
        true if it is OK to replicate, false otherwise
      • getPayloadVersion

        public short getPayloadVersion()
        Returns the log entry payload data version of the follower.
        Returns:
        the payload data version.
      • setPayloadVersion

        public void setPayloadVersion​(short payloadVersion)
        Sets the payload data version of the follower.
        Parameters:
        payloadVersion - the payload data version.
      • getRaftVersion

        public short getRaftVersion()
        Returns the the raft version of the follower.
        Returns:
        the raft version of the follower.
      • setRaftVersion

        public void setRaftVersion​(short raftVersion)
        Sets the raft version of the follower.
        Parameters:
        raftVersion - the raft version.
      • getInstallSnapshotState

        public @Nullable LeaderInstallSnapshotState getInstallSnapshotState()
        Returns the LeaderInstallSnapshotState for the in progress install snapshot.
        Returns:
        the LeaderInstallSnapshotState if a snapshot install is in progress, null otherwise.
      • setLeaderInstallSnapshotState

        public void setLeaderInstallSnapshotState​(@NonNull LeaderInstallSnapshotState state)
        Sets the LeaderInstallSnapshotState when an install snapshot is initiated.
        Parameters:
        state - the LeaderInstallSnapshotState
      • clearLeaderInstallSnapshotState

        public void clearLeaderInstallSnapshotState()
        Clears the LeaderInstallSnapshotState when an install snapshot is complete.
      • setSlicedLogEntryIndex

        public void setSlicedLogEntryIndex​(long index)
        Sets the index of the log entry whose payload size exceeds the maximum size for a single message and thus needs to be sliced into smaller chunks.
        Parameters:
        index - the log entry index or NO_INDEX to clear it
      • isLogEntrySlicingInProgress

        public boolean isLogEntrySlicingInProgress()
        Return whether or not log entry slicing is currently in progress.
        Returns:
        true if slicing is currently in progress, false otherwise
      • setNeedsLeaderAddress

        public void setNeedsLeaderAddress​(boolean value)
      • needsLeaderAddress

        public @Nullable String needsLeaderAddress​(String leaderId)
      • hasStaleCommitIndex

        public boolean hasStaleCommitIndex​(long commitIndex)
      • setSentCommitIndex

        public void setSentCommitIndex​(long commitIndex)