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

    DEFAULT

    Fields inherited from interface org.apache.ratis.statemachine.StateMachine.EventApi

    DEFAULT

    Fields inherited from interface org.apache.ratis.statemachine.StateMachine.FollowerEventApi

    DEFAULT

    Fields inherited from interface org.apache.ratis.statemachine.StateMachine.LeaderEventApi

    DEFAULT
  • Constructor Summary

    Constructors
    Constructor
    Description
    OzoneManagerStateMachine(OzoneManagerRatisServer ratisServer, boolean isTracingEnabled)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    CompletableFuture<org.apache.ratis.protocol.Message>
    applyTransaction(org.apache.ratis.statemachine.TransactionContext trx)
     
    void
    Wait until both buffers are flushed.
     
    void
     
     
    org.apache.ratis.server.protocol.TermIndex
     
    org.apache.ratis.statemachine.SnapshotInfo
     
     
    void
    initialize(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.
    void
     
    void
    notifyConfigurationChanged(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.
    void
    notifyLeaderChanged(org.apache.ratis.protocol.RaftGroupMemberId groupMemberId, org.apache.ratis.protocol.RaftPeerId newLeaderId)
     
    void
     
    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.
    void
    notifyTermIndexUpdated(long currentTerm, long newIndex)
    Notified by Ratis for non-StateMachine term-index update.
    void
     
    org.apache.ratis.statemachine.TransactionContext
    preAppendTransaction(org.apache.ratis.statemachine.TransactionContext trx)
     
    CompletableFuture<org.apache.ratis.protocol.Message>
    query(org.apache.ratis.protocol.Message request)
    Query the state machine.
    void
     
    void
     
    org.apache.ratis.statemachine.TransactionContext
    startTransaction(org.apache.ratis.protocol.RaftClientRequest raftClientRequest)
    Validate/pre-process the incoming update request in the state machine.
    void
     
    long
    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.
    toStateMachineLogEntryString(org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto proto)
     
    void
    unpause(long newLastAppliedSnaphsotIndex, long newLastAppliedSnapShotTermIndex)
    Unpause the StateMachine, re-initialize the DoubleBuffer and update the lastAppliedIndex.
    protected boolean
    updateLastAppliedTermIndex(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, updateLastAppliedTermIndex

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.ratis.statemachine.StateMachine

    data, event, followerEvent, leaderEvent, startTransaction

    Methods inherited from interface org.apache.ratis.statemachine.StateMachine.DataApi

    flush, link, read, read, stream, truncate, write, write

    Methods inherited from interface org.apache.ratis.statemachine.StateMachine.EventApi

    notifyGroupRemove, notifyLogFailed, notifyServerShutdown, notifyServerShutdown

    Methods inherited from interface org.apache.ratis.statemachine.StateMachine.FollowerEventApi

    notifyExtendedNoLeader

    Methods inherited from interface org.apache.ratis.statemachine.StateMachine.LeaderEventApi

    notifyFollowerSlowness, notifyFollowerSlowness, notifyNotLeader
  • Constructor Details

  • 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:
      initialize in interface org.apache.ratis.statemachine.StateMachine
      Overrides:
      initialize in class org.apache.ratis.statemachine.impl.BaseStateMachine
      Throws:
      IOException
    • reinitialize

      public void reinitialize() throws IOException
      Specified by:
      reinitialize in interface org.apache.ratis.statemachine.StateMachine
      Overrides:
      reinitialize in class org.apache.ratis.statemachine.impl.BaseStateMachine
      Throws:
      IOException
    • getLatestSnapshot

      public org.apache.ratis.statemachine.SnapshotInfo getLatestSnapshot()
      Specified by:
      getLatestSnapshot in interface org.apache.ratis.statemachine.StateMachine
      Overrides:
      getLatestSnapshot in class org.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:
      notifyTermIndexUpdated in interface org.apache.ratis.statemachine.StateMachine.EventApi
      Overrides:
      notifyTermIndexUpdated in class org.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:
      updateLastAppliedTermIndex in class org.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 - InstallSnapshotResult
      snapshotIndex - the index of installed snapshot
      peer - 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:
      startTransaction in interface org.apache.ratis.statemachine.StateMachine
      Overrides:
      startTransaction in class org.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:
      preAppendTransaction in interface org.apache.ratis.statemachine.StateMachine
      Overrides:
      preAppendTransaction in class org.apache.ratis.statemachine.impl.BaseStateMachine
      Throws:
      IOException
    • applyTransaction

      public CompletableFuture<org.apache.ratis.protocol.Message> applyTransaction(org.apache.ratis.statemachine.TransactionContext trx)
      Specified by:
      applyTransaction in interface org.apache.ratis.statemachine.StateMachine
      Overrides:
      applyTransaction in class org.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:
      query in interface org.apache.ratis.statemachine.StateMachine
      Overrides:
      query in class org.apache.ratis.statemachine.impl.BaseStateMachine
    • pause

      public void pause()
      Specified by:
      pause in interface org.apache.ratis.statemachine.StateMachine
      Overrides:
      pause in class org.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

      public OzoneManagerDoubleBuffer buildDoubleBufferForRatis()
    • takeSnapshot

      public long takeSnapshot() throws IOException
      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:
      takeSnapshot in interface org.apache.ratis.statemachine.StateMachine
      Overrides:
      takeSnapshot in class org.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 information
      firstTermIndexInLog - 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:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class org.apache.ratis.statemachine.impl.BaseStateMachine
    • loadSnapshotInfoFromDB

      public void loadSnapshotInfoFromDB() throws IOException
      Throws:
      IOException
    • setHandler

      public void setHandler(OzoneManagerRequestHandler handler)
    • getHandler

      public OzoneManagerRequestHandler getHandler()
    • stop

      public void stop()
    • awaitDoubleBufferFlush

      public void awaitDoubleBufferFlush() throws InterruptedException
      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

      public OzoneManagerDoubleBuffer getOzoneManagerDoubleBuffer()