public interface StateMachine extends Closeable
| Modifier and Type | Interface and Description |
|---|---|
static interface |
StateMachine.DataApi |
static interface |
StateMachine.DataStream
For streaming state machine data.
|
static interface |
StateMachine.Registry
A registry to support different state machines in multi-raft environment.
|
| Modifier and Type | Field and Description |
|---|---|
static org.slf4j.Logger |
LOG |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Message> |
applyTransaction(TransactionContext trx)
Apply a committed log entry to the state machine.
|
TransactionContext |
applyTransactionSerial(TransactionContext trx)
Called for transactions that have been committed to the RAFT log.
|
TransactionContext |
cancelTransaction(TransactionContext trx)
Called to notify the state machine that the Transaction passed cannot be appended (or synced).
|
default StateMachine.DataApi |
data()
Get the optional
StateMachine.DataApi object. |
TermIndex |
getLastAppliedTermIndex() |
SnapshotInfo |
getLatestSnapshot()
Returns the information for the latest durable snapshot.
|
LifeCycle.State |
getLifeCycleState()
Returns the lifecycle state for this StateMachine.
|
StateMachineStorage |
getStateMachineStorage() |
void |
initialize(RaftServer server,
RaftGroupId groupId,
RaftStorage storage)
Initializes the State Machine with the given server, group and storage.
|
default void |
notifyExtendedNoLeader(org.apache.ratis.proto.RaftProtos.RoleInfoProto roleInfoProto)
Notify the Leader's state machine that a leader has not been elected for a long time
this notification is based on "raft.server.leader.election.timeout"
|
default void |
notifyGroupRemove()
Notify about group removal in the state machine.
|
default void |
notifyIndexUpdate(long term,
long index)
Called to notify state machine about indexes which are processed
internally by Raft Server, this currently happens when conf entries are
processed in raft Server.
|
default CompletableFuture<TermIndex> |
notifyInstallSnapshotFromLeader(org.apache.ratis.proto.RaftProtos.RoleInfoProto roleInfoProto,
TermIndex firstTermIndexInLog)
Notify the Follower's state machine that the leader has purged entries
from its log and hence to catch up, the Follower state machine would have
to install the latest snapshot.
|
default void |
notifyLeaderChanged(RaftGroupMemberId groupMemberId,
RaftPeerId raftPeerId)
Notify the state machine that a RaftPeer has been elected as leader.
|
default void |
notifyLogFailed(Throwable t,
org.apache.ratis.proto.RaftProtos.LogEntryProto failedEntry)
Notify the state machine that the pipeline has failed.
|
void |
notifyNotLeader(Collection<TransactionContext> pendingEntries)
Notify the state machine that the raft peer is no longer leader.
|
default void |
notifySlowness(org.apache.ratis.proto.RaftProtos.RoleInfoProto roleInfoProto)
Notify the Leader's state machine that one of the followers is slow
this notification is based on "raft.server.rpc.slowness.timeout"
|
void |
pause()
Pauses the state machine.
|
TransactionContext |
preAppendTransaction(TransactionContext trx)
This is called before the transaction passed from the StateMachine is appended to the raft log.
|
CompletableFuture<Message> |
query(Message request)
Query the state machine.
|
CompletableFuture<Message> |
queryStale(Message request,
long minIndex)
Query the state machine, provided minIndex <= commit index.
|
void |
reinitialize()
Re-initializes the State Machine in PAUSED state.
|
TransactionContext |
startTransaction(RaftClientRequest request)
Validate/pre-process the incoming update request in the state machine.
|
long |
takeSnapshot()
Dump the in-memory state into a snapshot file in the RaftStorage.
|
default String |
toStateMachineLogEntryString(org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto proto)
Converts the proto object into a useful log string to add information about state machine data.
|
default StateMachine.DataApi data()
StateMachine.DataApi object.
If this StateMachine chooses to support StateMachine.DataApi,
it may either implement StateMachine.DataApi directly or override this method to return a StateMachine.DataApi object.
Otherwise, this StateMachine does not support StateMachine.DataApi.
Then, this method returns the default noop StateMachine.DataApi object.StateMachine.DataApi object.void initialize(RaftServer server, RaftGroupId groupId, RaftStorage storage) throws IOException
IOExceptionLifeCycle.State getLifeCycleState()
void pause()
void reinitialize()
throws IOException
IOExceptionlong takeSnapshot()
throws IOException
RaftServerConfigKeys.Snapshot.AUTO_TRIGGER_ENABLED_KEY is enabled.
The snapshot should include the latest raft configuration.IOExceptionStateMachineStorage getStateMachineStorage()
SnapshotInfo getLatestSnapshot()
CompletableFuture<Message> query(Message request)
CompletableFuture<Message> queryStale(Message request, long minIndex)
getLastAppliedTermIndex(),
the state machine may choose to either
(1) return exceptionally, or
(2) wait until minIndex <= getLastAppliedTermIndex() before running the query.TransactionContext startTransaction(RaftClientRequest request) throws IOException
IOException - thrown by the state machine while validationTransactionContext preAppendTransaction(TransactionContext trx) throws IOException
IOExceptionTransactionContext cancelTransaction(TransactionContext trx) throws IOException
trx - the transaction to cancelIOExceptionTransactionContext applyTransactionSerial(TransactionContext trx)
trx - the transaction state including the log entry that has been committed to a quorum
of the raft peersdefault void notifyIndexUpdate(long term,
long index)
term - term of the current log entryindex - index which is being updatedCompletableFuture<Message> applyTransaction(TransactionContext trx)
trx - the transaction state including the log entry that has been committed to a quorum
of the raft peersTermIndex getLastAppliedTermIndex()
void notifyNotLeader(Collection<TransactionContext> pendingEntries) throws IOException
IOExceptiondefault void notifySlowness(org.apache.ratis.proto.RaftProtos.RoleInfoProto roleInfoProto)
roleInfoProto - information about the current node role and rpc delay informationdefault void notifyLogFailed(Throwable t, org.apache.ratis.proto.RaftProtos.LogEntryProto failedEntry)
t - Exception which was caught, indicates possible cause.failedEntry - if append failed for a specific entry, null otherwise.default void notifyExtendedNoLeader(org.apache.ratis.proto.RaftProtos.RoleInfoProto roleInfoProto)
roleInfoProto - information about the current node role and rpc delay informationdefault CompletableFuture<TermIndex> notifyInstallSnapshotFromLeader(org.apache.ratis.proto.RaftProtos.RoleInfoProto roleInfoProto, TermIndex firstTermIndexInLog)
firstTermIndexInLog - TermIndex of the first append entry available
in the Leader's log.roleInfoProto - information about the current node role and
rpc delay informationdefault void notifyLeaderChanged(RaftGroupMemberId groupMemberId, RaftPeerId raftPeerId)
default void notifyGroupRemove()
default String toStateMachineLogEntryString(org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto proto)
proto - state machine protoCopyright © 2017–2020 The Apache Software Foundation. All rights reserved.