Class AbstractLeader
- All Implemented Interfaces:
AutoCloseable,RaftActorBehavior
- Direct Known Subclasses:
IsolatedLeader,Leader,PreLeader
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).
-
Field Summary
Fields inherited from class org.opendaylight.controller.cluster.raft.behaviors.AbstractRaftActorBehavior
context, log -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractLeader(RaftActorContext context, RaftState state) protectedAbstractLeader(RaftActorContext context, RaftState state, @Nullable AbstractLeader initializeFromLeader) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFollower(String followerId) protected 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 intprotected RaftActorBehaviorhandleAppendEntries(ActorRef sender, AppendEntries appendEntries) Derived classes should not directly handle AppendEntries messages it should let the base class handle it first.protected RaftActorBehaviorhandleAppendEntriesReply(ActorRef sender, AppendEntriesReply appendEntriesReply) Derived classes should not directly handle AppendEntriesReply messages it should let the base class handle it first.handleMessage(ActorRef sender, Object message) Handle a message.protected RaftActorBehaviorhandleRequestVoteReply(ActorRef sender, RequestVoteReply requestVoteReply) Derived classes should not directly handle RequestVoteReply messages it should let the base class handle it first.booleaninitiateCaptureSnapshot(String followerId) Initiates a snapshot capture to install on a follower.protected booleanvoidremoveFollower(String followerId) protected voidsendAppendEntries(long timeSinceLastActivityIntervalNanos, boolean isHeartbeat) final voidMethods inherited from class org.opendaylight.controller.cluster.raft.behaviors.AbstractRaftActorBehavior
actor, appendEntries, applyLogToStateMachine, canGrantVote, canStartElection, createBehavior, currentTerm, electionDuration, getId, getLogEntryIndex, getLogEntryOrSnapshotTerm, getLogEntryTerm, getMajorityVoteCount, getReplicatedToAllIndex, internalSwitchBehavior, internalSwitchBehavior, lastIndex, lastTerm, logName, performSnapshotWithoutCapture, requestVote, scheduleElection, setReplicatedToAllIndex, shouldUpdateTerm, state, stopElection, switchBehavior, votedFor
-
Constructor Details
-
AbstractLeader
protected AbstractLeader(RaftActorContext context, RaftState state, @Nullable AbstractLeader initializeFromLeader) -
AbstractLeader
-
-
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() -
handleAppendEntries
Description copied from class:AbstractRaftActorBehaviorDerived classes should not directly handle AppendEntries messages it should let the base class handle it first. Once the base class handles the AppendEntries message and does the common actions that are applicable in all RaftState's it will delegate the handling of the AppendEntries message to the derived class to do more state specific handling by calling this method- Specified by:
handleAppendEntriesin classAbstractRaftActorBehavior- Parameters:
sender- The actor that sent this messageappendEntries- The AppendEntries message- Returns:
- a new behavior if it was changed or the current behavior
-
handleAppendEntriesReply
protected RaftActorBehavior handleAppendEntriesReply(ActorRef sender, AppendEntriesReply appendEntriesReply) Description copied from class:AbstractRaftActorBehaviorDerived classes should not directly handle AppendEntriesReply messages it should let the base class handle it first. Once the base class handles the AppendEntriesReply message and does the common actions that are applicable in all RaftState's it will delegate the handling of the AppendEntriesReply message to the derived class to do more state specific handling by calling this method- Specified by:
handleAppendEntriesReplyin classAbstractRaftActorBehavior- Parameters:
sender- The actor that sent this messageappendEntriesReply- The AppendEntriesReply message- Returns:
- a new behavior if it was changed or the current behavior
-
handleRequestVoteReply
protected RaftActorBehavior handleRequestVoteReply(ActorRef sender, RequestVoteReply requestVoteReply) Description copied from class:AbstractRaftActorBehaviorDerived classes should not directly handle RequestVoteReply messages it should let the base class handle it first. Once the base class handles the RequestVoteReply message and does the common actions that are applicable in all RaftState's it will delegate the handling of the RequestVoteReply message to the derived class to do more state specific handling by calling this method- Specified by:
handleRequestVoteReplyin classAbstractRaftActorBehavior- Parameters:
sender- The actor that sent this messagerequestVoteReply- The RequestVoteReply message- Returns:
- a new behavior if it was changed or the current behavior
-
beforeSendHeartbeat
protected void beforeSendHeartbeat() -
handleMessage
Description copied from interface: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.- Specified by:
handleMessagein interfaceRaftActorBehavior- Overrides:
handleMessagein classAbstractRaftActorBehavior- 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 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.
-
close
public void close() -
getLeaderId
Description copied from interface:RaftActorBehaviorReturns the id of the leader.- Returns:
- the id of the leader or null if not known
-
getLeaderPayloadVersion
public final short getLeaderPayloadVersion()Description copied from interface:RaftActorBehaviorReturns the leader's payload data version.- Returns:
- a short representing the version
-
isLeaderIsolated
protected boolean isLeaderIsolated() -
printFollowerStates
-
getFollower
-
followerLogSize
public int followerLogSize()
-