Class Leader
java.lang.Object
org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior
org.opendaylight.controller.cluster.raft.behaviors.AbstractLeader
org.opendaylight.controller.cluster.raft.behaviors.Leader
- All Implemented Interfaces:
AutoCloseable
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).
-
Nested Class Summary
Nested classes/interfaces inherited from class org.opendaylight.controller.cluster.raft.behaviors.AbstractLeader
AbstractLeader.SendHeartBeat
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
close()
handleMessage
(org.apache.pekko.actor.ActorRef sender, Object originalMessage) Handle a message.void
transferLeadership
(@NonNull RaftActorLeadershipTransferCohort leadershipTransferCohort) Attempts to transfer leadership to a follower as per the raft paper (§3.10) as follows: Start a timer (Stopwatch). Send an initial AppendEntries heartbeat to all followers. On AppendEntriesReply, check if the follower's new match Index matches the leader's last index If it matches, Send an additional AppendEntries to ensure the follower has applied all its log entries to its state. Send an ElectionTimeout to the follower to immediately start an election. NotifyRaftActorLeadershipTransferCohort.transferComplete()
. Otherwise if the election time out period elapses, notifyRaftActorLeadershipTransferCohort.abortTransfer()
.Methods inherited from class org.opendaylight.controller.cluster.raft.behaviors.AbstractLeader
addFollower, checkConsensusReached, followerLogSize, getFollower, getFollowerIds, getLeaderId, getLeaderPayloadVersion, getMinIsolatedLeaderPeerCount, initiateCaptureSnapshot, isLeaderIsolated, printFollowerStates, removeFollower, sendAppendEntries, sendInstallSnapshot, updateMinReplicaCount
Methods inherited from class org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior
getReplicatedToAllIndex, raftRole, setReplicatedToAllIndex
-
Constructor Details
-
Leader
-
-
Method Details
-
handleMessage
public RaftActorBehavior handleMessage(org.apache.pekko.actor.ActorRef sender, Object originalMessage) 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 classAbstractLeader
- Parameters:
sender
- The sender of the messageoriginalMessage
- A message that needs to be processed- Returns:
- The new behavior or current behavior, or null if the message was not handled.
-
transferLeadership
Attempts to transfer leadership to a follower as per the raft paper (§3.10) as follows:- Start a timer (Stopwatch).
- Send an initial AppendEntries heartbeat to all followers.
- On AppendEntriesReply, check if the follower's new match Index matches the leader's last index
- If it matches,
- Send an additional AppendEntries to ensure the follower has applied all its log entries to its state.
- Send an ElectionTimeout to the follower to immediately start an election.
- Notify
RaftActorLeadershipTransferCohort.transferComplete()
.
- Otherwise if the election time out period elapses, notify
RaftActorLeadershipTransferCohort.abortTransfer()
.
- Parameters:
leadershipTransferCohort
- the cohort participating in the leadership transfer
-
close
public final void close()- Specified by:
close
in interfaceAutoCloseable
- Overrides:
close
in classAbstractLeader
-