java.lang.Object
org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior
org.opendaylight.controller.cluster.raft.behaviors.AbstractLeader
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
IsolatedLeader, Leader, PreLeader

public abstract sealed class AbstractLeader extends RaftActorBehavior permits IsolatedLeader, Leader, PreLeader
The behavior of a RaftActor when it is in the Leader state.

Leaders:

  • Upon election: send initial empty AppendEntries RPCs (heartbeat) to each server; repeat during idle periods to prevent election timeouts (§5.2)
  • If command received from client: append entry to local log, respond after entry applied to state machine (§5.3)
  • If last log index ≥ nextIndex for a follower: send AppendEntries RPC with log entries starting at nextIndex
  • If successful: update nextIndex and matchIndex for follower (§5.3)
  • If AppendEntries fails because of log inconsistency: decrement nextIndex and retry (§5.3)
  • If there exists an N such that N > commitIndex, a majority of matchIndex[i] ≥ N, and log[N].term == currentTerm: set commitIndex = N (§5.3, §5.4)
  • Method Details

    • getFollowerIds

      public final Collection<String> getFollowerIds()
      Return an immutable collection of follower identifiers.
      Returns:
      Collection of follower IDs
    • addFollower

      public void addFollower(String followerId)
    • removeFollower

      public void removeFollower(String followerId)
    • updateMinReplicaCount

      public final void updateMinReplicaCount()
    • getMinIsolatedLeaderPeerCount

      protected int getMinIsolatedLeaderPeerCount()
    • checkConsensusReached

      public final void checkConsensusReached()
    • handleMessage

      public RaftActorBehavior handleMessage(org.apache.pekko.actor.ActorRef sender, Object message)
      Description copied from class: RaftActorBehavior
      Handle a message. If the processing of the message warrants a state change then a new behavior should be returned otherwise this method should return the current behavior.
      Overrides:
      handleMessage in class RaftActorBehavior
      Parameters:
      sender - The sender of the message
      message - A message that needs to be processed
      Returns:
      The new behavior or current behavior, or null if the message was not handled.
    • sendAppendEntries

      protected void sendAppendEntries(long timeSinceLastActivityIntervalNanos, boolean isHeartbeat)
    • initiateCaptureSnapshot

      public boolean initiateCaptureSnapshot(String followerId)
      Initiates a snapshot capture to install on a follower. Install Snapshot works as follows:
      1. Leader initiates the capture snapshot by calling createSnapshot on the RaftActor.
      2. On receipt of the CaptureSnapshotReply message, the RaftActor persists the snapshot and makes a call to the Leader's handleMessage with a SendInstallSnapshot message.
      3. The Leader obtains and stores the Snapshot from the SendInstallSnapshot message and sends it in chunks to the Follower via InstallSnapshot messages.
      4. For each chunk, the Follower sends back an InstallSnapshotReply.
      5. On receipt of the InstallSnapshotReply for the last chunk, the Leader marks the install complete for that follower.
      6. If another follower requires a snapshot and a snapshot has been collected (via SendInstallSnapshot) then send the existing snapshot in chunks to the follower.
      Parameters:
      followerId - the id of the follower.
      Returns:
      true if capture was initiated, false otherwise.
    • sendInstallSnapshot

      @NonNullByDefault public final void sendInstallSnapshot(InstallableSnapshot snapshot)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in class RaftActorBehavior
    • getLeaderId

      public final String getLeaderId()
      Description copied from class: RaftActorBehavior
      Returns the id of the leader.
      Specified by:
      getLeaderId in class RaftActorBehavior
      Returns:
      the id of the leader or null if not known
    • getLeaderPayloadVersion

      public final short getLeaderPayloadVersion()
      Description copied from class: RaftActorBehavior
      Returns the leader's payload data version.
      Specified by:
      getLeaderPayloadVersion in class RaftActorBehavior
      Returns:
      a short representing the version
    • isLeaderIsolated

      protected boolean isLeaderIsolated()
    • printFollowerStates

      public String printFollowerStates()
    • getFollower

      public FollowerLogInformation getFollower(String followerId)
    • followerLogSize

      public int followerLogSize()