Class HAState
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.ha.HAState
- Direct Known Subclasses:
ActiveState,BackupState,StandbyState
Namenode base state to implement state machine pattern.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.hadoop.ha.HAServiceProtocol.HAServiceState -
Constructor Summary
ConstructorsConstructorDescriptionHAState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState state) Constructor -
Method Summary
Modifier and TypeMethodDescriptionabstract voidcheckOperation(HAContext context, NameNode.OperationCategory op) Check if an operation is supported in a given state.abstract voidenterState(HAContext context) Method to be overridden by subclasses to perform steps necessary for entering a state.abstract voidMethod to be overridden by subclasses to perform steps necessary for exiting a state.longGets the most recent HA transition time in milliseconds from the epoch.org.apache.hadoop.ha.HAServiceProtocol.HAServiceStatevoidprepareToEnterState(HAContext context) Method to be overridden by subclasses to prepare to enter a state.voidprepareToExitState(HAContext context) Method to be overridden by subclasses to prepare to exit a state.voidMove from the existing state to a new stateprotected final voidsetStateInternal(HAContext context, HAState s) Internal method to move from the existing state to a new state.abstract booleantoString()
-
Field Details
-
state
protected final org.apache.hadoop.ha.HAServiceProtocol.HAServiceState state
-
-
Constructor Details
-
HAState
public HAState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState state) Constructor- Parameters:
state- HA service state.
-
-
Method Details
-
getServiceState
public org.apache.hadoop.ha.HAServiceProtocol.HAServiceState getServiceState()- Returns:
- the generic service state
-
setStateInternal
protected final void setStateInternal(HAContext context, HAState s) throws org.apache.hadoop.ha.ServiceFailedException Internal method to move from the existing state to a new state.- Parameters:
context- HA contexts- new state- Throws:
org.apache.hadoop.ha.ServiceFailedException- on failure to transition to new state.
-
getLastHATransitionTime
public long getLastHATransitionTime()Gets the most recent HA transition time in milliseconds from the epoch.- Returns:
- the most recent HA transition time in milliseconds from the epoch.
-
prepareToEnterState
public void prepareToEnterState(HAContext context) throws org.apache.hadoop.ha.ServiceFailedException Method to be overridden by subclasses to prepare to enter a state. This method is called without the context being locked, and afterprepareToExitState(HAContext)has been called for the previous state, but beforeexitState(HAContext)has been called for the previous state.- Parameters:
context- HA context- Throws:
org.apache.hadoop.ha.ServiceFailedException- on precondition failure
-
enterState
public abstract void enterState(HAContext context) throws org.apache.hadoop.ha.ServiceFailedException Method to be overridden by subclasses to perform steps necessary for entering a state.- Parameters:
context- HA context- Throws:
org.apache.hadoop.ha.ServiceFailedException- on failure to enter the state.
-
prepareToExitState
public void prepareToExitState(HAContext context) throws org.apache.hadoop.ha.ServiceFailedException Method to be overridden by subclasses to prepare to exit a state. This method is called without the context being locked. This is used by the standby state to cancel any checkpoints that are going on. It can also be used to check any preconditions for the state transition. This method should not make any destructive changes to the state (eg stopping threads) sinceprepareToEnterState(HAContext)may subsequently cancel the state transition.- Parameters:
context- HA context- Throws:
org.apache.hadoop.ha.ServiceFailedException- on precondition failure
-
exitState
public abstract void exitState(HAContext context) throws org.apache.hadoop.ha.ServiceFailedException Method to be overridden by subclasses to perform steps necessary for exiting a state.- Parameters:
context- HA context- Throws:
org.apache.hadoop.ha.ServiceFailedException- on failure to enter the state.
-
setState
public void setState(HAContext context, HAState s) throws org.apache.hadoop.ha.ServiceFailedException Move from the existing state to a new state- Parameters:
context- HA contexts- new state- Throws:
org.apache.hadoop.ha.ServiceFailedException- on failure to transition to new state.
-
checkOperation
public abstract void checkOperation(HAContext context, NameNode.OperationCategory op) throws org.apache.hadoop.ipc.StandbyException Check if an operation is supported in a given state.- Parameters:
context- HA contextop- Type of the operation.- Throws:
org.apache.hadoop.ipc.StandbyException- if a given type of operation is not supported in standby state
-
shouldPopulateReplQueues
public abstract boolean shouldPopulateReplQueues() -
toString
-