java.lang.Object
org.apache.hadoop.ozone.container.common.statemachine.StateContext

public class StateContext extends Object
Current Context of State Machine.
  • Constructor Details

  • Method Details

    • getParent

      public DatanodeStateMachine getParent()
      Returns the DatanodeStateMachine class that holds this state.
      Returns:
      DatanodeStateMachine.
    • getState

      Returns the current state the machine is in.
      Returns:
      state.
    • setState

      public void setState(DatanodeStateMachine.DatanodeStates state)
      Sets the current state of the machine.
      Parameters:
      state - state.
    • getShutdownOnError

      public boolean getShutdownOnError()
      Get shutdownStateMachine.
      Returns:
      boolean
    • addIncrementalReport

      public void addIncrementalReport(com.google.protobuf.Message report)
      Adds the report to report queue.
      Parameters:
      report - report to be added
    • refreshFullReport

      public void refreshFullReport(com.google.protobuf.Message report)
      refresh Full report.
      Parameters:
      report - report to be refreshed
    • putBackReports

      public void putBackReports(List<com.google.protobuf.Message> reportsToPutBack, InetSocketAddress endpoint)
      Adds the reports which could not be sent by heartbeat back to the reports list.
      Parameters:
      reportsToPutBack - list of reports which failed to be sent by heartbeat.
    • getAllAvailableReports

      public List<com.google.protobuf.Message> getAllAvailableReports(InetSocketAddress endpoint)
      Returns all the available reports from the report queue, or empty list if the queue is empty.
      Returns:
      List of reports
    • getFullContainerReportDiscardPendingICR

      public org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReportsProto getFullContainerReportDiscardPendingICR() throws IOException
      Gets a point in time snapshot of all containers, any pending incremental container reports (ICR) for containers will be included in this report and this call will drop any pending ICRs.
      Returns:
      Full Container Report
      Throws:
      IOException
    • addContainerAction

      public void addContainerAction(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction containerAction)
      Adds the ContainerAction to ContainerAction queue.
      Parameters:
      containerAction - ContainerAction to be added
    • addContainerActionIfAbsent

      public void addContainerActionIfAbsent(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction containerAction)
      Add ContainerAction to ContainerAction queue if it's not present.
      Parameters:
      containerAction - ContainerAction to be added
    • getPendingContainerAction

      public List<org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction> getPendingContainerAction(InetSocketAddress endpoint, int maxLimit)
      Returns pending ContainerActions from the ContainerAction queue with a max limit on list size, or empty list if the queue is empty.
      Returns:
      List<ContainerAction>
    • addPipelineActionIfAbsent

      public boolean addPipelineActionIfAbsent(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.PipelineAction pipelineAction)
      Add PipelineAction to PipelineAction queue if it's not present.
      Parameters:
      pipelineAction - PipelineAction to be added
    • getPendingPipelineAction

      public List<org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.PipelineAction> getPendingPipelineAction(InetSocketAddress endpoint, int maxLimit)
      Returns pending PipelineActions from the PipelineAction queue with a max limit on list size, or empty list if the queue is empty.
      Returns:
      List<ContainerAction>
    • getTask

      Returns the next task to get executed by the datanode state machine.
      Returns:
      A callable that will be executed by the DatanodeStateMachine
    • isThreadPoolAvailable

      public boolean isThreadPoolAvailable(ExecutorService executor)
    • execute

      public void execute(ExecutorService service, long time, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
      Executes the required state function.
      Parameters:
      service - - Executor Service
      time - - seconds to wait
      unit - - Seconds.
      Throws:
      InterruptedException
      ExecutionException
      TimeoutException
    • updateTermOfLeaderSCM

      public void updateTermOfLeaderSCM(long newTerm)
    • setTermOfLeaderSCM

      public void setTermOfLeaderSCM(long term)
    • getTermOfLeaderSCM

      public OptionalLong getTermOfLeaderSCM()
    • getNextCommand

      public SCMCommand<?> getNextCommand()
      Returns the next command or null if it is empty.
      Returns:
      SCMCommand or Null.
    • addCommand

      public void addCommand(SCMCommand<?> command)
      Adds a command to the State Machine queue.
      Parameters:
      command - - SCMCommand.
    • getCommandQueueSummary

      public Map<org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto.Type,Integer> getCommandQueueSummary()
    • isPipelineCloseInProgress

      public boolean isPipelineCloseInProgress(UUID pipelineID)
    • getExecutionCount

      public long getExecutionCount()
      Returns the count of the Execution.
      Returns:
      long
    • getCmdStatus

      public CommandStatus getCmdStatus(Long key)
      Returns the next CommandStatus or null if it is empty.
      Returns:
      CommandStatus or Null.
    • addCmdStatus

      public void addCmdStatus(Long key, CommandStatus status)
      Adds a CommandStatus to the State Machine.
      Parameters:
      status - - CommandStatus.
    • addCmdStatus

      public void addCmdStatus(SCMCommand<?> cmd)
      Adds a CommandStatus to the State Machine for given SCMCommand.
      Parameters:
      cmd - - SCMCommand.
    • getCommandStatusMap

      public Map<Long,CommandStatus> getCommandStatusMap()
      Get map holding all CommandStatus objects.
    • updateCommandStatus

      public boolean updateCommandStatus(Long cmdId, Consumer<CommandStatus> cmdStatusUpdater)
      Updates the command status of a pending command.
      Parameters:
      cmdId - command id
      cmdStatusUpdater - Consumer to update command status.
      Returns:
      true if command status updated successfully else if the command associated with the command id does not exist in the context.
    • configureHeartbeatFrequency

      public void configureHeartbeatFrequency()
    • getHeartbeatFrequency

      public long getHeartbeatFrequency()
      Return current heartbeat frequency in ms.
    • addEndpoint

      public void addEndpoint(InetSocketAddress endpoint)
    • getContainerReports

      public com.google.protobuf.Message getContainerReports()
    • getNodeReport

      public com.google.protobuf.Message getNodeReport()
    • getPipelineReports

      public com.google.protobuf.Message getPipelineReports()
    • configureReconHeartbeatFrequency

      public void configureReconHeartbeatFrequency()
    • getReconHeartbeatFrequency

      public long getReconHeartbeatFrequency()
      Return current Datanode to Recon heartbeat frequency in ms.
    • getPipelineActionQueueSize

      public Map<InetSocketAddress,Integer> getPipelineActionQueueSize()
    • getContainerActionQueueSize

      public Map<InetSocketAddress,Integer> getContainerActionQueueSize()
    • getIncrementalReportQueueSize

      public Map<InetSocketAddress,Integer> getIncrementalReportQueueSize()
    • getQueueMetrics

      public DatanodeQueueMetrics getQueueMetrics()
    • getThreadNamePrefix

      public String getThreadNamePrefix()