Class AbstractLeader
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 ofmatchIndex[i] ≥ N, andlog[N].term == currentTerm: setcommitIndex = N(§5.3, §5.4)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThis messages is sent via a schedule to the Leader to prompt it to send a heart beat to its followers. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFollower(String followerId) final voidvoidclose()intgetFollower(String followerId) final Collection<String> Return an immutable collection of follower identifiers.final StringReturns the id of the leader.final shortReturns the leader's payload data version.protected inthandleMessage(ActorRef sender, Object message) Handle a message.booleaninitiateCaptureSnapshot(String followerId) Initiates a snapshot capture to install on a follower.protected booleanvoidremoveFollower(String followerId) protected voidsendAppendEntries(long timeSinceLastActivityIntervalNanos, boolean isHeartbeat) final voidsendInstallSnapshot(InstallableSnapshot snapshot) final voidMethods inherited from class org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior
getReplicatedToAllIndex, raftRole, setReplicatedToAllIndex
-
Method Details
-
getFollowerIds
Return an immutable collection of follower identifiers.- Returns:
- Collection of follower IDs
-
addFollower
-
removeFollower
-
updateMinReplicaCount
public final void updateMinReplicaCount() -
getMinIsolatedLeaderPeerCount
protected int getMinIsolatedLeaderPeerCount() -
checkConsensusReached
public final void checkConsensusReached() -
handleMessage
Description copied from class:RaftActorBehaviorHandle 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:
handleMessagein classRaftActorBehavior- Parameters:
sender- The sender of the messagemessage- 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
Initiates a snapshot capture to install on a follower. Install Snapshot works as follows:- Leader initiates the capture snapshot by calling createSnapshot on the RaftActor.
- On receipt of the CaptureSnapshotReply message, the RaftActor persists the snapshot and makes a call to the Leader's handleMessage with a SendInstallSnapshot message.
- The Leader obtains and stores the Snapshot from the SendInstallSnapshot message and sends it in chunks to the Follower via InstallSnapshot messages.
- For each chunk, the Follower sends back an InstallSnapshotReply.
- On receipt of the InstallSnapshotReply for the last chunk, the Leader marks the install complete for that follower.
- 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
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein classRaftActorBehavior
-
getLeaderId
Description copied from class:RaftActorBehaviorReturns the id of the leader.- Specified by:
getLeaderIdin classRaftActorBehavior- Returns:
- the id of the leader or null if not known
-
getLeaderPayloadVersion
public final short getLeaderPayloadVersion()Description copied from class:RaftActorBehaviorReturns the leader's payload data version.- Specified by:
getLeaderPayloadVersionin classRaftActorBehavior- Returns:
- a short representing the version
-
isLeaderIsolated
protected boolean isLeaderIsolated() -
printFollowerStates
-
getFollower
-
followerLogSize
public int followerLogSize()
-