Package org.apache.hadoop.ozone.om.ratis
Class OzoneManagerStateMachine
java.lang.Object
org.apache.ratis.statemachine.impl.BaseStateMachine
org.apache.hadoop.ozone.om.ratis.OzoneManagerStateMachine
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.ratis.statemachine.StateMachine,org.apache.ratis.statemachine.StateMachine.DataApi,org.apache.ratis.statemachine.StateMachine.EventApi,org.apache.ratis.statemachine.StateMachine.FollowerEventApi,org.apache.ratis.statemachine.StateMachine.LeaderEventApi
public class OzoneManagerStateMachine
extends org.apache.ratis.statemachine.impl.BaseStateMachine
The OM StateMachine is the state machine for OM Ratis server. It is
responsible for applying ratis committed transactions to
OzoneManager.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.ratis.statemachine.StateMachine
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 -
Field Summary
Fields inherited from interface org.apache.ratis.statemachine.StateMachine.DataApi
DEFAULTFields inherited from interface org.apache.ratis.statemachine.StateMachine.EventApi
DEFAULTFields inherited from interface org.apache.ratis.statemachine.StateMachine.FollowerEventApi
DEFAULTFields inherited from interface org.apache.ratis.statemachine.StateMachine.LeaderEventApi
DEFAULT -
Constructor Summary
ConstructorsConstructorDescriptionOzoneManagerStateMachine(OzoneManagerRatisServer ratisServer, boolean isTracingEnabled) -
Method Summary
Modifier and TypeMethodDescriptionCompletableFuture<org.apache.ratis.protocol.Message> applyTransaction(org.apache.ratis.statemachine.TransactionContext trx) voidWait until both buffers are flushed.voidclose()org.apache.ratis.server.protocol.TermIndexorg.apache.ratis.statemachine.SnapshotInfovoidinitialize(org.apache.ratis.server.RaftServer server, org.apache.ratis.protocol.RaftGroupId id, org.apache.ratis.server.storage.RaftStorage raftStorage) Initializes the State Machine with the given server, group and storage.voidvoidnotifyConfigurationChanged(long term, long index, org.apache.ratis.proto.RaftProtos.RaftConfigurationProto newRaftConfiguration) Called to notify state machine about configuration changes.CompletableFuture<org.apache.ratis.server.protocol.TermIndex> notifyInstallSnapshotFromLeader(org.apache.ratis.proto.RaftProtos.RoleInfoProto roleInfoProto, org.apache.ratis.server.protocol.TermIndex firstTermIndexInLog) Leader OM has purged entries from its log.voidnotifyLeaderChanged(org.apache.ratis.protocol.RaftGroupMemberId groupMemberId, org.apache.ratis.protocol.RaftPeerId newLeaderId) voidvoidnotifySnapshotInstalled(org.apache.ratis.proto.RaftProtos.InstallSnapshotResult result, long snapshotIndex, org.apache.ratis.protocol.RaftPeer peer) Called to notify state machine about the snapshot install result.voidnotifyTermIndexUpdated(long currentTerm, long newIndex) Notified by Ratis for non-StateMachine term-index update.voidpause()org.apache.ratis.statemachine.TransactionContextpreAppendTransaction(org.apache.ratis.statemachine.TransactionContext trx) CompletableFuture<org.apache.ratis.protocol.Message> query(org.apache.ratis.protocol.Message request) Query the state machine.voidvoidsetHandler(OzoneManagerRequestHandler handler) org.apache.ratis.statemachine.TransactionContextstartTransaction(org.apache.ratis.protocol.RaftClientRequest raftClientRequest) Validate/pre-process the incoming update request in the state machine.voidstop()longTake OM Ratis snapshot is a dummy operation as when double buffer flushes the lastAppliedIndex is flushed to DB and that is used as snapshot index.toStateMachineLogEntryString(org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto proto) voidunpause(long newLastAppliedSnaphsotIndex, long newLastAppliedSnapShotTermIndex) Unpause the StateMachine, re-initialize the DoubleBuffer and update the lastAppliedIndex.protected booleanupdateLastAppliedTermIndex(org.apache.ratis.server.protocol.TermIndex newTermIndex) Methods inherited from class org.apache.ratis.statemachine.impl.BaseStateMachine
applyTransactionSerial, cancelTransaction, getGroupId, getId, getLastAppliedTermIndex, getLifeCycle, getLifeCycleState, getServer, getStateMachineStorage, queryStale, setLastAppliedTermIndex, toString, updateLastAppliedTermIndexMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.ratis.statemachine.StateMachine
data, event, followerEvent, leaderEvent, startTransactionMethods inherited from interface org.apache.ratis.statemachine.StateMachine.DataApi
flush, link, read, read, stream, truncate, write, writeMethods inherited from interface org.apache.ratis.statemachine.StateMachine.EventApi
notifyGroupRemove, notifyLogFailed, notifyServerShutdown, notifyServerShutdownMethods inherited from interface org.apache.ratis.statemachine.StateMachine.FollowerEventApi
notifyExtendedNoLeaderMethods inherited from interface org.apache.ratis.statemachine.StateMachine.LeaderEventApi
notifyFollowerSlowness, notifyFollowerSlowness, notifyNotLeader
-
Constructor Details
-
OzoneManagerStateMachine
public OzoneManagerStateMachine(OzoneManagerRatisServer ratisServer, boolean isTracingEnabled) throws IOException - Throws:
IOException
-
-
Method Details
-
initialize
public void initialize(org.apache.ratis.server.RaftServer server, org.apache.ratis.protocol.RaftGroupId id, org.apache.ratis.server.storage.RaftStorage raftStorage) throws IOException Initializes the State Machine with the given server, group and storage.- Specified by:
initializein interfaceorg.apache.ratis.statemachine.StateMachine- Overrides:
initializein classorg.apache.ratis.statemachine.impl.BaseStateMachine- Throws:
IOException
-
reinitialize
- Specified by:
reinitializein interfaceorg.apache.ratis.statemachine.StateMachine- Overrides:
reinitializein classorg.apache.ratis.statemachine.impl.BaseStateMachine- Throws:
IOException
-
getLatestSnapshot
public org.apache.ratis.statemachine.SnapshotInfo getLatestSnapshot()- Specified by:
getLatestSnapshotin interfaceorg.apache.ratis.statemachine.StateMachine- Overrides:
getLatestSnapshotin classorg.apache.ratis.statemachine.impl.BaseStateMachine
-
notifyLeaderReady
public void notifyLeaderReady() -
notifyLeaderChanged
public void notifyLeaderChanged(org.apache.ratis.protocol.RaftGroupMemberId groupMemberId, org.apache.ratis.protocol.RaftPeerId newLeaderId) -
notifyTermIndexUpdated
public void notifyTermIndexUpdated(long currentTerm, long newIndex) Notified by Ratis for non-StateMachine term-index update.- Specified by:
notifyTermIndexUpdatedin interfaceorg.apache.ratis.statemachine.StateMachine.EventApi- Overrides:
notifyTermIndexUpdatedin classorg.apache.ratis.statemachine.impl.BaseStateMachine
-
getLastNotifiedTermIndex
public org.apache.ratis.server.protocol.TermIndex getLastNotifiedTermIndex() -
updateLastAppliedTermIndex
protected boolean updateLastAppliedTermIndex(org.apache.ratis.server.protocol.TermIndex newTermIndex) - Overrides:
updateLastAppliedTermIndexin classorg.apache.ratis.statemachine.impl.BaseStateMachine
-
notifyConfigurationChanged
public void notifyConfigurationChanged(long term, long index, org.apache.ratis.proto.RaftProtos.RaftConfigurationProto newRaftConfiguration) Called to notify state machine about configuration changes. Configurations changes include addition of newly bootstrapped OM. -
notifySnapshotInstalled
public void notifySnapshotInstalled(org.apache.ratis.proto.RaftProtos.InstallSnapshotResult result, long snapshotIndex, org.apache.ratis.protocol.RaftPeer peer) Called to notify state machine about the snapshot install result. Trigger the cleanup of candidate DB dir.- Parameters:
result- InstallSnapshotResultsnapshotIndex- the index of installed snapshotpeer- the peer which fini
-
startTransaction
public org.apache.ratis.statemachine.TransactionContext startTransaction(org.apache.ratis.protocol.RaftClientRequest raftClientRequest) throws IOException Validate/pre-process the incoming update request in the state machine.- Specified by:
startTransactionin interfaceorg.apache.ratis.statemachine.StateMachine- Overrides:
startTransactionin classorg.apache.ratis.statemachine.impl.BaseStateMachine- Returns:
- the content to be written to the log entry. Null means the request should be rejected.
- Throws:
IOException- thrown by the state machine while validating
-
preAppendTransaction
public org.apache.ratis.statemachine.TransactionContext preAppendTransaction(org.apache.ratis.statemachine.TransactionContext trx) throws IOException - Specified by:
preAppendTransactionin interfaceorg.apache.ratis.statemachine.StateMachine- Overrides:
preAppendTransactionin classorg.apache.ratis.statemachine.impl.BaseStateMachine- Throws:
IOException
-
applyTransaction
public CompletableFuture<org.apache.ratis.protocol.Message> applyTransaction(org.apache.ratis.statemachine.TransactionContext trx) - Specified by:
applyTransactionin interfaceorg.apache.ratis.statemachine.StateMachine- Overrides:
applyTransactionin classorg.apache.ratis.statemachine.impl.BaseStateMachine
-
query
public CompletableFuture<org.apache.ratis.protocol.Message> query(org.apache.ratis.protocol.Message request) Query the state machine. The request must be read-only.- Specified by:
queryin interfaceorg.apache.ratis.statemachine.StateMachine- Overrides:
queryin classorg.apache.ratis.statemachine.impl.BaseStateMachine
-
pause
public void pause()- Specified by:
pausein interfaceorg.apache.ratis.statemachine.StateMachine- Overrides:
pausein classorg.apache.ratis.statemachine.impl.BaseStateMachine
-
unpause
public void unpause(long newLastAppliedSnaphsotIndex, long newLastAppliedSnapShotTermIndex) Unpause the StateMachine, re-initialize the DoubleBuffer and update the lastAppliedIndex. This should be done after uploading new state to the StateMachine. -
buildDoubleBufferForRatis
-
takeSnapshot
Take OM Ratis snapshot is a dummy operation as when double buffer flushes the lastAppliedIndex is flushed to DB and that is used as snapshot index.- Specified by:
takeSnapshotin interfaceorg.apache.ratis.statemachine.StateMachine- Overrides:
takeSnapshotin classorg.apache.ratis.statemachine.impl.BaseStateMachine- Returns:
- the last applied index on the state machine which has been stored in the snapshot file.
- Throws:
IOException
-
notifyInstallSnapshotFromLeader
public CompletableFuture<org.apache.ratis.server.protocol.TermIndex> notifyInstallSnapshotFromLeader(org.apache.ratis.proto.RaftProtos.RoleInfoProto roleInfoProto, org.apache.ratis.server.protocol.TermIndex firstTermIndexInLog) Leader OM has purged entries from its log. To catch up, OM must download the latest checkpoint from the leader OM and install it.- Parameters:
roleInfoProto- the leader node informationfirstTermIndexInLog- TermIndex of the first append entry available in the Leader's log.- Returns:
- the last term index included in the installed snapshot.
-
toStateMachineLogEntryString
public String toStateMachineLogEntryString(org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto proto) -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classorg.apache.ratis.statemachine.impl.BaseStateMachine
-
loadSnapshotInfoFromDB
- Throws:
IOException
-
setHandler
-
getHandler
-
stop
public void stop() -
awaitDoubleBufferFlush
Wait until both buffers are flushed. This is used in cases like "follower bootstrap tarball creation" where the rocksDb for the active fs needs to synchronized with the rocksdb's for the snapshots.- Throws:
InterruptedException
-
getOzoneManagerDoubleBuffer
-