Class StartupProgress
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgress
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAllows a caller to increment a counter for tracking progress. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new StartupProgress by initializing internal data structure for tracking progress of all defined phases. -
Method Summary
Modifier and TypeMethodDescriptionvoidbeginPhase(Phase phase) Begins execution of the specified phase.voidBegins execution of the specified step within the specified phase.Creates aStartupProgressViewcontaining data cloned from this StartupProgress.voidEnds execution of the specified phase.voidEnds execution of the specified step within the specified phase.getCounter(Phase phase, Step step) Returns a counter associated with the specified phase and step.Returns the current run status of the specified phase.voidSets counter to the specified value.voidSets the optional file name associated with the specified phase.voidSets the optional size in bytes associated with the specified phase.voidSets the total associated with the specified phase and step.
-
Constructor Details
-
StartupProgress
public StartupProgress()Creates a new StartupProgress by initializing internal data structure for tracking progress of all defined phases.
-
-
Method Details
-
beginPhase
Begins execution of the specified phase.- Parameters:
phase- Phase to begin
-
beginStep
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 startedstep- Step to begin
-
endPhase
Ends execution of the specified phase.- Parameters:
phase- Phase to end
-
endStep
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 endedstep- Step to end
-
getStatus
Returns the current run status of the specified phase.- Parameters:
phase- Phase to get- Returns:
- Status run status of phase
-
getCounter
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 getstep- Step to get- Returns:
- Counter associated with phase and step
-
setCount
Sets counter to the specified value.- Parameters:
phase- Phase to setstep- Step to setcount- long to set
-
setFile
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 setfile- String file name to set
-
setSize
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 setsize- long to set
-
setTotal
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 setstep- Step to settotal- long to set
-
createView
Creates aStartupProgressViewcontaining 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
-