java.lang.Object
org.apache.hadoop.hdfs.server.namenode.ha.HAState
Direct Known Subclasses:
ActiveState, BackupState, StandbyState

@Private public abstract class HAState extends Object
Namenode base state to implement state machine pattern.
  • 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 context
      s - 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 after prepareToExitState(HAContext) has been called for the previous state, but before exitState(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) since prepareToEnterState(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 context
      s - 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 context
      op - 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

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      String representation of the service state.