java.lang.Object
org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgress

@Private public class StartupProgress extends Object
StartupProgress is used in various parts of the namenode codebase to indicate startup progress. Its methods provide ways to indicate begin and end of a Phase or Step within a phase. Additional methods provide ways to associate a step or phase with optional information, such as a file name or file size. It also provides counters, which can be incremented by the caller to indicate progress through a long-running task. This class is thread-safe. Any number of threads may call any methods, even for the same phase or step, without risk of corrupting internal state. For all begin/end methods and set methods, the last one in wins, overwriting any prior writes. Instances of StartupProgress.Counter provide an atomic increment operation to prevent lost updates. After startup completes, the tracked data is frozen. Any subsequent updates or counter increments are no-ops. For read access, call createView() to create a consistent view with a clone of the data.
  • Constructor Details

    • StartupProgress

      public StartupProgress()
      Creates a new StartupProgress by initializing internal data structure for tracking progress of all defined phases.
  • Method Details

    • beginPhase

      public void beginPhase(Phase phase)
      Begins execution of the specified phase.
      Parameters:
      phase - Phase to begin
    • beginStep

      public void beginStep(Phase phase, Step step)
      Begins execution of the specified step within the specified phase. This is a no-op if the phase is already completed.
      Parameters:
      phase - Phase within which the step should be started
      step - Step to begin
    • endPhase

      public void endPhase(Phase phase)
      Ends execution of the specified phase.
      Parameters:
      phase - Phase to end
    • endStep

      public void endStep(Phase phase, Step step)
      Ends execution of the specified step within the specified phase. This is a no-op if the phase is already completed.
      Parameters:
      phase - Phase within which the step should be ended
      step - Step to end
    • getStatus

      public Status getStatus(Phase phase)
      Returns the current run status of the specified phase.
      Parameters:
      phase - Phase to get
      Returns:
      Status run status of phase
    • getCounter

      public StartupProgress.Counter getCounter(Phase phase, Step step)
      Returns a counter associated with the specified phase and step. Typical usage is to increment a counter within a tight loop. Callers may use this method to obtain a counter once and then increment that instance repeatedly within a loop. This prevents redundant lookup operations and object creation within the tight loop. Incrementing the counter is an atomic operation, so there is no risk of lost updates even if multiple threads increment the same counter.
      Parameters:
      phase - Phase to get
      step - Step to get
      Returns:
      Counter associated with phase and step
    • setCount

      public void setCount(Phase phase, Step step, long count)
      Sets counter to the specified value.
      Parameters:
      phase - Phase to set
      step - Step to set
      count - long to set
    • setFile

      public void setFile(Phase phase, String file)
      Sets the optional file name associated with the specified phase. For example, this can be used while loading fsimage to indicate the full path to the fsimage file.
      Parameters:
      phase - Phase to set
      file - String file name to set
    • setSize

      public void setSize(Phase phase, long size)
      Sets the optional size in bytes associated with the specified phase. For example, this can be used while loading fsimage to indicate the size of the fsimage file.
      Parameters:
      phase - Phase to set
      size - long to set
    • setTotal

      public void setTotal(Phase phase, Step step, long total)
      Sets the total associated with the specified phase and step. For example, this can be used while loading edits to indicate the number of operations to be applied.
      Parameters:
      phase - Phase to set
      step - Step to set
      total - long to set
    • createView

      public StartupProgressView createView()
      Creates a StartupProgressView containing data cloned from this StartupProgress. Subsequent updates to this StartupProgress will not be shown in the view. This gives a consistent, unchanging view for callers that need to perform multiple related read operations. Calculations that require aggregation, such as overall percent complete, will not be impacted by mutations performed in other threads mid-way through the calculation.
      Returns:
      StartupProgressView containing cloned data