Package org.apache.hadoop.ozone.om
Class OzoneManagerPrepareState
java.lang.Object
org.apache.hadoop.ozone.om.OzoneManagerPrepareState
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 ClassesModifier and TypeClassDescriptionstatic classThe current state of preparation is defined by the status and the prepare index that are currently set. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOzoneManagerPrepareState(org.apache.hadoop.hdds.conf.ConfigurationSource conf) Sets prepare state toOzoneManagerProtocolProtos.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 toOzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPARED. -
Method Summary
Modifier and TypeMethodDescriptionvoidRemoves the prepare marker file, clears the prepare index, turns off the prepare gate, and moves the prepare status toOzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPARED.voidTurns on the prepare gate flag, clears the prepare index, and moves the prepare status toOzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_GATE_ENABLED.voidfinishPrepare(long index) Enables the prepare gate, writes the prepare marker file, sets the in memory prepare index, and moves the prepare status toOzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_COMPLETED.Returns aFileobject representing the prepare marker file, which may or may not actually exist on disk.getState()booleanrequestAllowed(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type requestType) If the prepare gate is enabled, always returns true.voidrestorePrepareFromFile(long currentIndex) Uses the on disk marker file to determine the OM's prepare state.voidrestorePrepareFromIndex(long restoredPrepareIndex, long currentIndex) Finishes preparation the same way asfinishPrepare(long), but only ifcurrentIndexis at least as large asminIndex.
-
Field Details
-
NO_PREPARE_INDEX
public static final long NO_PREPARE_INDEX- See Also:
-
-
Constructor Details
-
OzoneManagerPrepareState
public OzoneManagerPrepareState(org.apache.hadoop.hdds.conf.ConfigurationSource conf) Sets prepare state toOzoneManagerProtocolProtos.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 toOzoneManagerProtocolProtos.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 toOzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_GATE_ENABLED. Turning on the prepare gate flag will enable a gate in theOzoneManagerStateMachine.preAppendTransaction(org.apache.ratis.statemachine.TransactionContext)(called on leader OM only) andOzoneManagerRatisServer.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
Removes the prepare marker file, clears the prepare index, turns off the prepare gate, and moves the prepare status toOzoneManagerProtocolProtos.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
Enables the prepare gate, writes the prepare marker file, sets the in memory prepare index, and moves the prepare status toOzoneManagerProtocolProtos.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 asfinishPrepare(long), but only ifcurrentIndexis at least as large asminIndex. This is useful if the current log index needs to be checked against a prepare index saved to disk for validity.- Throws:
IOException
-
restorePrepareFromFile
Uses the on disk marker file to determine the OM's prepare state. If the marker file exists and contains an index matchingcurrentIndex, the necessary steps will be taken to finish preparation and the state will be moved toOzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_COMPLETED. Else, the status will be moved toOzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPAREDand 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 theOzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.NOT_PREPAREDstate.
-
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 ifrequestTypeisPrepareorCancelPrepare. Returns false otherwise. -
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
Returns aFileobject representing the prepare marker file, which may or may not actually exist on disk. This method should be used for testing only.
-