public abstract class RaftActor extends AbstractUntypedPersistentActor
RaftActor has 3 states and each state has a certain behavior associated with it. A Raft actor can behave as,
A RaftActor MUST be a Leader in order to accept requests from clients to change the state of it's encapsulated state machine. Once a RaftActor becomes a Leader it is also responsible for ensuring that all followers ultimately have the same log and therefore the same state machine as itself.
The current behavior of a RaftActor determines how election for leadership is initiated and how peer RaftActors react to request for votes.
Each RaftActor also needs to know the current election term. It uses this information for a couple of things. One is to simply figure out who it voted for in the last election. Another is to figure out if the message it received to update it's state is stale.
The RaftActor uses akka-persistence to store it's replicated log. Furthermore through it's behaviors a Raft Actor determines
akka.persistence.Eventsourced.AsyncHandlerInvocation, akka.persistence.Eventsourced.AsyncHandlerInvocation$, akka.persistence.Eventsourced.PendingHandlerInvocation, akka.persistence.Eventsourced.ProcessingState, akka.persistence.Eventsourced.RecoveryTick, akka.persistence.Eventsourced.RecoveryTick$, akka.persistence.Eventsourced.StashingHandlerInvocation, akka.persistence.Eventsourced.StashingHandlerInvocation$, akka.persistence.Eventsourced.State
LOG
Modifier | Constructor and Description |
---|---|
protected |
RaftActor(String id,
Map<String,String> peerAddresses,
com.google.common.base.Optional<ConfigParams> configParams,
short payloadVersion) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
applyState(akka.actor.ActorRef clientActor,
org.opendaylight.yangtools.concepts.Identifier identifier,
Object data)
The applyState method will be called by the RaftActor when some data
needs to be applied to the actor's state.
|
protected void |
changeCurrentBehavior(RaftActorBehavior newBehavior) |
protected RaftActorBehavior |
getCurrentBehavior() |
protected Long |
getCurrentTerm() |
protected String |
getId() |
akka.actor.ActorSelection |
getLeader()
Derived actor can call getLeader if they need a reference to the Leader.
|
protected String |
getLeaderId()
Returns the id of the current leader.
|
protected RaftActorContext |
getRaftActorContext() |
protected abstract RaftActorRecoveryCohort |
getRaftActorRecoveryCohort()
Returns the RaftActorRecoveryCohort to participate in persistence recovery.
|
protected abstract RaftActorSnapshotCohort |
getRaftActorSnapshotCohort()
Returns the RaftActorSnapshotCohort to participate in snapshot captures.
|
protected RaftState |
getRaftState() |
protected abstract com.google.common.base.Optional<akka.actor.ActorRef> |
getRoleChangeNotifier()
Notifier Actor for this RaftActor to notify when a role change happens.
|
protected void |
handleCommand(Object message)
Deprecated.
This method is not final for testing purposes. DO NOT OVERRIDE IT, override
handleNonRaftCommand(Object) instead. |
protected void |
handleNonRaftCommand(Object message)
Method exposed for subclasses to plug-in their logic.
|
protected void |
handleRecover(Object message) |
protected boolean |
hasFollowers() |
protected boolean |
isLeader()
Derived actors can call the isLeader method to check if the current
RaftActor is the Leader or not.
|
protected boolean |
isLeaderActive() |
protected boolean |
isLeadershipTransferInProgress() |
protected LeaderStateChanged |
newLeaderStateChanged(String memberId,
String leaderId,
short leaderPayloadVersion) |
protected OnDemandRaftState.AbstractBuilder<?,?> |
newOnDemandRaftStateBuilder() |
protected org.opendaylight.controller.cluster.raft.RaftActorRecoverySupport |
newRaftActorRecoverySupport() |
protected void |
onLeaderChanged(String oldLeader,
String newLeader) |
protected abstract void |
onRecoveryComplete()
This method is called when recovery is complete.
|
protected abstract void |
onStateChanged()
This method will be called by the RaftActor when the state of the
RaftActor changes.
|
protected void |
onVotingStateChangeComplete()
This method is called on the leader when a voting change operation completes.
|
protected void |
pauseLeader(Runnable operation)
This method is called prior to operations such as leadership transfer and actor shutdown when the leader
must pause or stop its duties.
|
protected void |
persistData(akka.actor.ActorRef clientActor,
org.opendaylight.yangtools.concepts.Identifier identifier,
Payload data,
boolean batchHint)
Persists the given Payload in the journal and replicates to any followers.
|
DataPersistenceProvider |
persistence() |
void |
postStop() |
void |
preStart() |
protected void |
setPeerAddress(String peerId,
String peerAddress)
setPeerAddress sets the address of a known peer at a later time.
|
protected void |
setPersistence(boolean persistent) |
void |
setPersistence(DataPersistenceProvider provider) |
long |
snapshotSequenceNr() |
protected void |
unpauseLeader()
This method is invoked when the actions hooked to the leader becoming paused failed to execute and the leader
should resume normal operations.
|
protected void |
updateConfigParams(ConfigParams configParams) |
executeInSelf, ignoreMessage, onReceiveCommand, onReceiveRecover, unknownMessage
akka$actor$StashSupport$_setter_$akka$actor$StashSupport$$capacity_$eq, akka$actor$StashSupport$_setter_$mailbox_$eq, akka$actor$StashSupport$$capacity, akka$actor$StashSupport$$theStash_$eq, akka$actor$StashSupport$$theStash, akka$persistence$Eventsourced$_setter_$akka$persistence$Eventsourced$$extension_$eq, akka$persistence$Eventsourced$_setter_$akka$persistence$Eventsourced$$instanceId_$eq, akka$persistence$Eventsourced$_setter_$akka$persistence$Eventsourced$$internalStash_$eq, akka$persistence$Eventsourced$_setter_$akka$persistence$Eventsourced$$maxMessageBatchSize_$eq, akka$persistence$Eventsourced$_setter_$akka$persistence$Eventsourced$$pendingInvocations_$eq, akka$persistence$Eventsourced$_setter_$akka$persistence$Eventsourced$$persistingEvents_$eq, akka$persistence$Eventsourced$_setter_$akka$persistence$Eventsourced$$processingCommands_$eq, akka$persistence$Eventsourced$_setter_$akka$persistence$Eventsourced$$unstashFilterPredicate_$eq, akka$persistence$Eventsourced$_setter_$akka$persistence$Eventsourced$$writerUuid_$eq, akka$persistence$Eventsourced$$_lastSequenceNr_$eq, akka$persistence$Eventsourced$$_lastSequenceNr, akka$persistence$Eventsourced$$currentState_$eq, akka$persistence$Eventsourced$$currentState, akka$persistence$Eventsourced$$eventBatch_$eq, akka$persistence$Eventsourced$$eventBatch, akka$persistence$Eventsourced$$extension, akka$persistence$Eventsourced$$instanceId, akka$persistence$Eventsourced$$internalStash, akka$persistence$Eventsourced$$journalBatch_$eq, akka$persistence$Eventsourced$$journalBatch, akka$persistence$Eventsourced$$maxMessageBatchSize, akka$persistence$Eventsourced$$pendingInvocations, akka$persistence$Eventsourced$$pendingStashingPersistInvocations_$eq, akka$persistence$Eventsourced$$pendingStashingPersistInvocations, akka$persistence$Eventsourced$$persistingEvents, akka$persistence$Eventsourced$$processingCommands, akka$persistence$Eventsourced$$sequenceNr_$eq, akka$persistence$Eventsourced$$sequenceNr, akka$persistence$Eventsourced$$unstashFilterPredicate, akka$persistence$Eventsourced$$writeInProgress_$eq, akka$persistence$Eventsourced$$writeInProgress, akka$persistence$Eventsourced$$writerUuid, aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, clearStash, createStash, deferAsync, deleteMessages, deleteSnapshot, deleteSnapshots, internalDeferAsync, internalPersist, internalPersistAll, internalPersistAllAsync, internalPersistAsync, internalStashOverflowStrategy, journal, journalPluginId, lastSequenceNr, loadSnapshot, mailbox, onPersistFailure, onPersistRejected, onReceive, onRecoveryFailure, onReplaySuccess, persist, persistAll, persistAllAsync, persistAsync, prepend, preRestart, receiveCommand, receiveRecover, recovery, recoveryFinished, recoveryRunning, saveSnapshot, snapshotPluginId, snapshotStore, snapshotterId, stash, unhandled, unstash, unstashAll, unstashAll
akka$actor$Actor$_setter_$context_$eq, akka$actor$Actor$_setter_$self_$eq, context, getContext, getSelf, getSender, postRestart, receive, self, sender, supervisorStrategy
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
$init$, akka$persistence$Eventsourced$$changeState, akka$persistence$Eventsourced$$flushBatch, akka$persistence$Eventsourced$$flushJournalBatch, akka$persistence$Eventsourced$$peekApplyHandler, akka$persistence$Eventsourced$$recovering, akka$persistence$Eventsourced$$setLastSequenceNr, akka$persistence$Eventsourced$$startRecovery, akka$persistence$Eventsourced$$stashInternally, akka$persistence$Eventsourced$$unstashInternally, akka$persistence$Eventsourced$$updateLastSequenceNr
protected RaftActor(String id, Map<String,String> peerAddresses, com.google.common.base.Optional<ConfigParams> configParams, short payloadVersion)
public void preStart() throws Exception
preStart
in interface akka.actor.Actor
preStart
in class akka.actor.UntypedActor
Exception
public void postStop()
postStop
in interface akka.actor.Actor
postStop
in interface akka.actor.UnrestrictedStash
postStop
in class akka.persistence.UntypedPersistentActor
protected void handleRecover(Object message)
handleRecover
in class AbstractUntypedPersistentActor
protected org.opendaylight.controller.cluster.raft.RaftActorRecoverySupport newRaftActorRecoverySupport()
protected void changeCurrentBehavior(RaftActorBehavior newBehavior)
protected void handleNonRaftCommand(Object message)
handleCommand(Object)
for messages which are not handled by this class. Subclasses overriding this class should fall back to this
implementation for messages which they do not handlemessage
- Incoming command message@Deprecated protected void handleCommand(Object message)
handleNonRaftCommand(Object)
instead.handleCommand
in class AbstractUntypedPersistentActor
protected OnDemandRaftState.AbstractBuilder<?,?> newOnDemandRaftStateBuilder()
protected LeaderStateChanged newLeaderStateChanged(String memberId, String leaderId, short leaderPayloadVersion)
public long snapshotSequenceNr()
snapshotSequenceNr
in interface akka.persistence.Eventsourced
snapshotSequenceNr
in interface akka.persistence.Snapshotter
snapshotSequenceNr
in class akka.persistence.UntypedPersistentActor
protected final void persistData(akka.actor.ActorRef clientActor, org.opendaylight.yangtools.concepts.Identifier identifier, Payload data, boolean batchHint)
applyState(ActorRef, Identifier, Object)
is notified.clientActor
- optional ActorRef that is provided via the applyState callbackidentifier
- the payload identifierdata
- the payload data to persistbatchHint
- if true, an attempt is made to delay immediate replication and batch the payload with
subsequent payloads for efficiency. Otherwise the payload is immediately replicated.protected String getId()
protected RaftActorBehavior getCurrentBehavior()
protected boolean isLeader()
protected final boolean isLeaderActive()
protected boolean isLeadershipTransferInProgress()
public akka.actor.ActorSelection getLeader()
protected final String getLeaderId()
protected final RaftState getRaftState()
protected Long getCurrentTerm()
protected RaftActorContext getRaftActorContext()
protected void updateConfigParams(ConfigParams configParams)
public final DataPersistenceProvider persistence()
public void setPersistence(DataPersistenceProvider provider)
protected void setPersistence(boolean persistent)
protected void setPeerAddress(String peerId, String peerAddress)
This is to account for situations where a we know that a peer exists but we do not know an address up-front. This may also be used in situations where a known peer starts off in a different location and we need to change it's address
Note that if the peerId does not match the list of peers passed to this actor during construction an IllegalStateException will be thrown.
protected abstract void applyState(akka.actor.ActorRef clientActor, org.opendaylight.yangtools.concepts.Identifier identifier, Object data)
clientActor
- A reference to the client who sent this message. This
is the same reference that was passed to persistData
by the derived actor. clientActor may be null when
the RaftActor is behaving as a follower or during
recovery.identifier
- The identifier of the persisted data. This is also
the same identifier that was passed to persistData by
the derived actor. identifier may be null when
the RaftActor is behaving as a follower or during
recoverydata
- A piece of data that was persisted by the persistData call.
This should NEVER be null.@Nonnull protected abstract RaftActorRecoveryCohort getRaftActorRecoveryCohort()
protected abstract void onRecoveryComplete()
@Nonnull protected abstract RaftActorSnapshotCohort getRaftActorSnapshotCohort()
protected abstract void onStateChanged()
protected abstract com.google.common.base.Optional<akka.actor.ActorRef> getRoleChangeNotifier()
protected void onVotingStateChangeComplete()
protected void pauseLeader(Runnable operation)
The default implementation immediately runs the operation.
operation
- the operation to runprotected void unpauseLeader()
Note this method can be invoked even before the operation supplied to pauseLeader(Runnable)
is invoked.
protected boolean hasFollowers()
Copyright © 2019 OpenDaylight. All rights reserved.