Class OzoneManagerPrepareState

java.lang.Object
org.apache.hadoop.ozone.om.OzoneManagerPrepareState

public final class OzoneManagerPrepareState extends Object
Controls the prepare state of the OzoneManager containing the instance. When prepared, an ozone manager should have no Ratis logs remaining, disallow all write requests except prepare and cancel prepare, and have a marker file present on disk that will cause it to remain prepared on restart.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    The current state of preparation is defined by the status and the prepare index that are currently set.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    OzoneManagerPrepareState(org.apache.hadoop.hdds.conf.ConfigurationSource conf)
    Sets prepare state to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPARED, ignoring any marker file that may or may not exist.
    OzoneManagerPrepareState(org.apache.hadoop.hdds.conf.ConfigurationSource conf, long currentIndex)
    Restores prepare state from the marker file if it exists, otherwise sets prepare state to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPARED.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes the prepare marker file, clears the prepare index, turns off the prepare gate, and moves the prepare status to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPARED.
    void
    Turns on the prepare gate flag, clears the prepare index, and moves the prepare status to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_GATE_ENABLED.
    void
    finishPrepare(long index)
    Enables the prepare gate, writes the prepare marker file, sets the in memory prepare index, and moves the prepare status to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_COMPLETED.
    Returns a File object representing the prepare marker file, which may or may not actually exist on disk.
     
    boolean
    requestAllowed(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type requestType)
    If the prepare gate is enabled, always returns true.
    void
    restorePrepareFromFile(long currentIndex)
    Uses the on disk marker file to determine the OM's prepare state.
    void
    restorePrepareFromIndex(long restoredPrepareIndex, long currentIndex)
    Finishes preparation the same way as finishPrepare(long), but only if currentIndex is at least as large as minIndex.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • OzoneManagerPrepareState

      public OzoneManagerPrepareState(org.apache.hadoop.hdds.conf.ConfigurationSource conf)
      Sets prepare state to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPARED, ignoring any marker file that may or may not exist.
    • OzoneManagerPrepareState

      public OzoneManagerPrepareState(org.apache.hadoop.hdds.conf.ConfigurationSource conf, long currentIndex) throws IOException
      Restores prepare state from the marker file if it exists, otherwise sets prepare state to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPARED.
      Parameters:
      conf - Configuration used to determine marker file location.
      currentIndex - The OM's current log index to verify the prepare index against. Prepare index should not be larger than the current index.
      Throws:
      IOException - On error restoring prepare state from marker file.
  • Method Details

    • enablePrepareGate

      public void enablePrepareGate()
      Turns on the prepare gate flag, clears the prepare index, and moves the prepare status to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_GATE_ENABLED. Turning on the prepare gate flag will enable a gate in the OzoneManagerStateMachine.preAppendTransaction(org.apache.ratis.statemachine.TransactionContext) (called on leader OM only) and OzoneManagerRatisServer.submitRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) (called on all OMs) that block write requests from reaching the OM and fail them with error responses to the client.
    • cancelPrepare

      public void cancelPrepare() throws IOException
      Removes the prepare marker file, clears the prepare index, turns off the prepare gate, and moves the prepare status to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPARED. This can be called from any state to clear the current prepare state.
      Throws:
      IOException - If the prepare marker file exists but cannot be deleted.
    • finishPrepare

      public void finishPrepare(long index) throws IOException
      Enables the prepare gate, writes the prepare marker file, sets the in memory prepare index, and moves the prepare status to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_COMPLETED. This can be called from any state to move the OM into prepare mode.
      Parameters:
      index - The log index to prepare the OM on.
      Throws:
      IOException - If the marker file cannot be written.
    • restorePrepareFromIndex

      public void restorePrepareFromIndex(long restoredPrepareIndex, long currentIndex) throws IOException
      Finishes preparation the same way as finishPrepare(long), but only if currentIndex is at least as large as minIndex. This is useful if the current log index needs to be checked against a prepare index saved to disk for validity.
      Throws:
      IOException
    • restorePrepareFromFile

      public void restorePrepareFromFile(long currentIndex) throws IOException
      Uses the on disk marker file to determine the OM's prepare state. If the marker file exists and contains an index matching currentIndex, the necessary steps will be taken to finish preparation and the state will be moved to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_COMPLETED. Else, the status will be moved to OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPARED and any preparation steps will be cancelled.
      Throws:
      IOException - If the marker file cannot be read, and it cannot be deleted as part of moving to the OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPARED state.
    • requestAllowed

      public boolean requestAllowed(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type requestType)
      If the prepare gate is enabled, always returns true. If the prepare gate is disabled, returns true only if requestType is Prepare or CancelPrepare. Returns false otherwise.
    • getState

      public OzoneManagerPrepareState.State getState()
      Returns:
      the current log index and status of preparation. Both fields are returned together to provide a consistent view of the state, which would not be guaranteed if they had to be retrieved through separate getters.
    • getPrepareMarkerFile

      public File getPrepareMarkerFile()
      Returns a File object representing the prepare marker file, which may or may not actually exist on disk. This method should be used for testing only.