@ThreadSafe public class JournalStateMachine extends org.apache.ratis.statemachine.impl.BaseStateMachine
upgrade()
. Once the state machine is upgraded,
it will ignore all entries appended by Ratis because those entries are applied to primary
master state before being written to Rati.org.apache.ratis.statemachine.impl.BaseStateMachine.Task
org.apache.ratis.statemachine.StateMachine.DataApi, org.apache.ratis.statemachine.StateMachine.DataChannel, org.apache.ratis.statemachine.StateMachine.DataStream, org.apache.ratis.statemachine.StateMachine.EventApi, org.apache.ratis.statemachine.StateMachine.FollowerEventApi, org.apache.ratis.statemachine.StateMachine.LeaderEventApi, org.apache.ratis.statemachine.StateMachine.Registry
Constructor and Description |
---|
JournalStateMachine(Map<String,RaftJournal> journals,
RaftJournalSystem journalSystem) |
Modifier and Type | Method and Description |
---|---|
protected void |
afterServerClosing()
Called by
RaftJournalSystem stop internal method after
shutting down the raft server. |
void |
applyJournalEntryCommand(org.apache.ratis.statemachine.TransactionContext commit)
Applies a journal entry commit to the state machine.
|
CompletableFuture<org.apache.ratis.protocol.Message> |
applyTransaction(org.apache.ratis.statemachine.TransactionContext trx) |
CatchupFuture |
catchup(long sequence)
Initiates catching up of masters to given sequence.
|
void |
close() |
long |
getLastAppliedCommitIndex() |
long |
getLastAppliedSequenceNumber() |
long |
getLastPrimaryStartSequenceNumber() |
org.apache.ratis.statemachine.SnapshotInfo |
getLatestSnapshot() |
SnapshotReplicationManager |
getSnapshotReplicationManager() |
org.apache.ratis.statemachine.StateMachineStorage |
getStateMachineStorage() |
void |
initialize(org.apache.ratis.server.RaftServer server,
org.apache.ratis.protocol.RaftGroupId groupId,
org.apache.ratis.server.storage.RaftStorage raftStorage) |
boolean |
isSnapshotting() |
boolean |
isSuspended() |
void |
notifyConfigurationChanged(long term,
long index,
org.apache.ratis.proto.RaftProtos.RaftConfigurationProto newRaftConfiguration) |
CompletableFuture<org.apache.ratis.server.protocol.TermIndex> |
notifyInstallSnapshotFromLeader(org.apache.ratis.proto.RaftProtos.RoleInfoProto roleInfoProto,
org.apache.ratis.server.protocol.TermIndex firstTermIndexInLog) |
void |
notifyLeaderChanged(org.apache.ratis.protocol.RaftGroupMemberId groupMemberId,
org.apache.ratis.protocol.RaftPeerId raftPeerId) |
void |
notifyNotLeader(Collection<org.apache.ratis.statemachine.TransactionContext> pendingEntries) |
void |
pause() |
CompletableFuture<org.apache.ratis.protocol.Message> |
query(org.apache.ratis.protocol.Message request) |
void |
reinitialize() |
void |
resume()
Resumes applying to masters.
|
protected void |
setServerClosing()
Called by
RaftJournalSystem stop internal method before
shutting down the raft server to prevent a deadlock on
the lock in RaftServerProxy. |
void |
suspend(Runnable interruptCallback)
Suspends applying to masters.
|
long |
takeLocalSnapshot(boolean hasStateLock)
Takes a snapshot of local state machine.
|
long |
takeSnapshot() |
void |
unpause()
Unpause the StateMachine.
|
long |
upgrade()
Upgrades the journal state machine to primary mode.
|
applyTransactionSerial, cancelTransaction, getGroupId, getId, getLastAppliedTermIndex, getLifeCycle, getLifeCycleState, getServer, notifyTermIndexUpdated, preAppendTransaction, queryStale, recordTime, setLastAppliedTermIndex, startTransaction, toString, updateLastAppliedTermIndex
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
data, event, followerEvent, leaderEvent, toStateMachineLogEntryString
flush, link, read, stream, truncate, write
notifyGroupRemove, notifyLogFailed
public JournalStateMachine(Map<String,RaftJournal> journals, RaftJournalSystem journalSystem)
journals
- master journals; these journals are still owned by the caller, not by the
journal state machinejournalSystem
- the raft journal systempublic void initialize(org.apache.ratis.server.RaftServer server, org.apache.ratis.protocol.RaftGroupId groupId, org.apache.ratis.server.storage.RaftStorage raftStorage) throws IOException
initialize
in interface org.apache.ratis.statemachine.StateMachine
initialize
in class org.apache.ratis.statemachine.impl.BaseStateMachine
IOException
public void reinitialize() throws IOException
reinitialize
in interface org.apache.ratis.statemachine.StateMachine
reinitialize
in class org.apache.ratis.statemachine.impl.BaseStateMachine
IOException
protected void setServerClosing()
RaftJournalSystem
stop internal method before
shutting down the raft server to prevent a deadlock on
the lock in RaftServerProxy.protected void afterServerClosing()
RaftJournalSystem
stop internal method after
shutting down the raft server.public long takeSnapshot()
takeSnapshot
in interface org.apache.ratis.statemachine.StateMachine
takeSnapshot
in class org.apache.ratis.statemachine.impl.BaseStateMachine
public org.apache.ratis.statemachine.SnapshotInfo getLatestSnapshot()
getLatestSnapshot
in interface org.apache.ratis.statemachine.StateMachine
getLatestSnapshot
in class org.apache.ratis.statemachine.impl.BaseStateMachine
public org.apache.ratis.statemachine.StateMachineStorage getStateMachineStorage()
getStateMachineStorage
in interface org.apache.ratis.statemachine.StateMachine
getStateMachineStorage
in class org.apache.ratis.statemachine.impl.BaseStateMachine
public CompletableFuture<org.apache.ratis.protocol.Message> query(org.apache.ratis.protocol.Message request)
query
in interface org.apache.ratis.statemachine.StateMachine
query
in class org.apache.ratis.statemachine.impl.BaseStateMachine
public void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class org.apache.ratis.statemachine.impl.BaseStateMachine
public CompletableFuture<org.apache.ratis.protocol.Message> applyTransaction(org.apache.ratis.statemachine.TransactionContext trx)
applyTransaction
in interface org.apache.ratis.statemachine.StateMachine
applyTransaction
in class org.apache.ratis.statemachine.impl.BaseStateMachine
public void notifyNotLeader(Collection<org.apache.ratis.statemachine.TransactionContext> pendingEntries)
public void notifyConfigurationChanged(long term, long index, org.apache.ratis.proto.RaftProtos.RaftConfigurationProto newRaftConfiguration)
public CompletableFuture<org.apache.ratis.server.protocol.TermIndex> notifyInstallSnapshotFromLeader(org.apache.ratis.proto.RaftProtos.RoleInfoProto roleInfoProto, org.apache.ratis.server.protocol.TermIndex firstTermIndexInLog)
public void pause()
pause
in interface org.apache.ratis.statemachine.StateMachine
pause
in class org.apache.ratis.statemachine.impl.BaseStateMachine
public void unpause()
public void applyJournalEntryCommand(org.apache.ratis.statemachine.TransactionContext commit)
commit
- the commitpublic long takeLocalSnapshot(boolean hasStateLock)
hasStateLock
- indicates whether this method call is guarded by a state lockRaftLog.INVALID_LOG_INDEX
if it failspublic void suspend(Runnable interruptCallback) throws IOException
interruptCallback
- a callback function to be called when the suspend is interruptedIOException
- if suspension failspublic void resume() throws IOException
IOException
- if resuming failspublic CatchupFuture catchup(long sequence)
sequence
- the target sequencepublic long upgrade()
public long getLastAppliedSequenceNumber()
public long getLastPrimaryStartSequenceNumber()
public long getLastAppliedCommitIndex()
public boolean isSnapshotting()
public void notifyLeaderChanged(org.apache.ratis.protocol.RaftGroupMemberId groupMemberId, org.apache.ratis.protocol.RaftPeerId raftPeerId)
public SnapshotReplicationManager getSnapshotReplicationManager()
public boolean isSuspended()
Copyright © 2023. All Rights Reserved.