public class BaseStateMachine extends Object implements StateMachine, StateMachine.DataApi
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
BaseStateMachine.Task |
StateMachine.DataApi, StateMachine.DataStream, StateMachine.RegistryLOGDEFAULT| Constructor and Description |
|---|
BaseStateMachine() |
| 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).
|
void |
close() |
RaftGroupId |
getGroupId() |
RaftPeerId |
getId() |
TermIndex |
getLastAppliedTermIndex() |
SnapshotInfo |
getLatestSnapshot()
Returns the information for the latest durable snapshot.
|
LifeCycle |
getLifeCycle() |
LifeCycle.State |
getLifeCycleState()
Returns the lifecycle state for this StateMachine.
|
CompletableFuture<RaftServer> |
getServer() |
StateMachineStorage |
getStateMachineStorage() |
void |
initialize(RaftServer raftServer,
RaftGroupId raftGroupId,
RaftStorage storage)
Initializes the State Machine with the given server, group and storage.
|
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.
|
void |
notifyNotLeader(Collection<TransactionContext> pendingEntries)
Notify the state machine that the raft peer is no longer leader.
|
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.
|
protected CompletableFuture<Message> |
recordTime(com.codahale.metrics.Timer timer,
BaseStateMachine.Task task) |
void |
reinitialize()
Re-initializes the State Machine in PAUSED state.
|
protected void |
setLastAppliedTermIndex(TermIndex newTI) |
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.
|
String |
toString() |
protected boolean |
updateLastAppliedTermIndex(long term,
long index) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitdata, notifyExtendedNoLeader, notifyGroupRemove, notifyInstallSnapshotFromLeader, notifyLeaderChanged, notifyLogFailed, notifySlowness, toStateMachineLogEntryStringpublic RaftPeerId getId()
public LifeCycle getLifeCycle()
public CompletableFuture<RaftServer> getServer()
public RaftGroupId getGroupId()
public LifeCycle.State getLifeCycleState()
StateMachinegetLifeCycleState in interface StateMachinepublic void initialize(RaftServer raftServer, RaftGroupId raftGroupId, RaftStorage storage) throws IOException
StateMachineinitialize in interface StateMachineIOExceptionpublic SnapshotInfo getLatestSnapshot()
StateMachinegetLatestSnapshot in interface StateMachinepublic void notifyNotLeader(Collection<TransactionContext> pendingEntries) throws IOException
StateMachinenotifyNotLeader in interface StateMachineIOExceptionpublic void pause()
StateMachinepause in interface StateMachinepublic void reinitialize()
throws IOException
StateMachinereinitialize in interface StateMachineIOExceptionpublic TransactionContext applyTransactionSerial(TransactionContext trx)
StateMachineapplyTransactionSerial in interface StateMachinetrx - the transaction state including the log entry that has been committed to a quorum
of the raft peerspublic CompletableFuture<Message> applyTransaction(TransactionContext trx)
StateMachineapplyTransaction in interface StateMachinetrx - the transaction state including the log entry that has been committed to a quorum
of the raft peerspublic TermIndex getLastAppliedTermIndex()
getLastAppliedTermIndex in interface StateMachineprotected void setLastAppliedTermIndex(TermIndex newTI)
public void notifyIndexUpdate(long term,
long index)
StateMachinenotifyIndexUpdate in interface StateMachineterm - term of the current log entryindex - index which is being updatedprotected boolean updateLastAppliedTermIndex(long term,
long index)
public long takeSnapshot()
throws IOException
StateMachineRaftServerConfigKeys.Snapshot.AUTO_TRIGGER_ENABLED_KEY is enabled.
The snapshot should include the latest raft configuration.takeSnapshot in interface StateMachineIOExceptionpublic StateMachineStorage getStateMachineStorage()
getStateMachineStorage in interface StateMachinepublic CompletableFuture<Message> queryStale(Message request, long minIndex)
StateMachineStateMachine.getLastAppliedTermIndex(),
the state machine may choose to either
(1) return exceptionally, or
(2) wait until minIndex <= StateMachine.getLastAppliedTermIndex() before running the query.queryStale in interface StateMachinepublic CompletableFuture<Message> query(Message request)
StateMachinequery in interface StateMachinepublic TransactionContext startTransaction(RaftClientRequest request) throws IOException
StateMachinestartTransaction in interface StateMachineIOException - thrown by the state machine while validationpublic TransactionContext cancelTransaction(TransactionContext trx) throws IOException
StateMachinecancelTransaction in interface StateMachinetrx - the transaction to cancelIOExceptionpublic TransactionContext preAppendTransaction(TransactionContext trx) throws IOException
StateMachinepreAppendTransaction in interface StateMachineIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionprotected CompletableFuture<Message> recordTime(com.codahale.metrics.Timer timer, BaseStateMachine.Task task)
Copyright © 2017–2020 The Apache Software Foundation. All rights reserved.