Class TransitRegionStateProcedure
java.lang.Object
org.apache.hadoop.hbase.procedure2.Procedure<TEnvironment>
org.apache.hadoop.hbase.procedure2.StateMachineProcedure<MasterProcedureEnv,TState>
org.apache.hadoop.hbase.master.procedure.AbstractStateMachineTableProcedure<TState>
org.apache.hadoop.hbase.master.procedure.AbstractStateMachineRegionProcedure<org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState>
org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure
- All Implemented Interfaces:
Comparable<Procedure<MasterProcedureEnv>>
,TableProcedureInterface
@Private
public class TransitRegionStateProcedure
extends AbstractStateMachineRegionProcedure<org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState>
The procedure to deal with the state transition of a region. A region with a TRSP in place is
called RIT, i.e, RegionInTransition.
It can be used to assign/unassign/reopen/move a region, and for
unassign(MasterProcedureEnv, RegionInfo)
and
reopen(MasterProcedureEnv, RegionInfo)
, you do not need to specify a target server, and
for assign(MasterProcedureEnv, RegionInfo, ServerName)
and
move(MasterProcedureEnv, RegionInfo, ServerName)
, if you want to you can provide a
target server. And for move(MasterProcedureEnv, RegionInfo, ServerName)
, if you do not
specify a targetServer, we will select one randomly.
The typical state transition for assigning a region is:
GET_ASSIGN_CANDIDATE ------> OPEN -----> CONFIRM_OPENEDNotice that, if there are failures we may go back to the
GET_ASSIGN_CANDIDATE
state to
try again.
The typical state transition for unassigning a region is:
CLOSE -----> CONFIRM_CLOSEDHere things go a bit different, if there are failures, especially that if there is a server crash, we will go to the
GET_ASSIGN_CANDIDATE
state to bring the region online first, and
then go through the normal way to unassign it.
The typical state transition for reopening/moving a region is:
CLOSE -----> CONFIRM_CLOSED -----> GET_ASSIGN_CANDIDATE ------> OPEN -----> CONFIRM_OPENEDThe retry logic is the same with the above assign/unassign. Notice that, although we allow specify a target server, it just acts as a candidate, we do not guarantee that the region will finally be on the target server. If this is important for you, you should check whether the region is on the target server after the procedure is finished. Altenatively, for trying retaining assignments, the hbase.master.scp.retain.assignment.force option can be used together with hbase.master.scp.retain.assignment. When you want to schedule a TRSP, please check whether there is still one for this region, and the check should be under the RegionStateNode lock. We will remove the TRSP from a RegionStateNode when we are done, see the code in
reportTransition
method below. There
could be at most one TRSP for a give region.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.hadoop.hbase.procedure2.StateMachineProcedure
StateMachineProcedure.Flow
Nested classes/interfaces inherited from class org.apache.hadoop.hbase.procedure2.Procedure
Procedure.LockState
Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.master.procedure.TableProcedureInterface
TableProcedureInterface.TableOperationType
-
Field Summary
Modifier and TypeFieldDescriptionprivate ServerName
private boolean
private boolean
private RetryCounter
private long
private org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState
private boolean
private org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState
private static final org.slf4j.Logger
private RegionRemoteProcedureBase
private RetryCounter
Fields inherited from class org.apache.hadoop.hbase.procedure2.StateMachineProcedure
stateCount
Fields inherited from class org.apache.hadoop.hbase.procedure2.Procedure
NO_PROC_ID, NO_TIMEOUT
-
Constructor Summary
ModifierConstructorDescriptionprotected
TransitRegionStateProcedure
(MasterProcedureEnv env, RegionInfo hri, ServerName assignCandidate, boolean forceNewPlan, TransitRegionStateProcedure.TransitionType type) protected
TransitRegionStateProcedure
(MasterProcedureEnv env, RegionInfo hri, ServerName assignCandidate, boolean forceNewPlan, TransitRegionStateProcedure.TransitionType type, boolean isSplit) -
Method Summary
Modifier and TypeMethodDescriptionstatic TransitRegionStateProcedure
assign
(MasterProcedureEnv env, RegionInfo region, boolean forceNewPlan, ServerName targetServer) static TransitRegionStateProcedure
assign
(MasterProcedureEnv env, RegionInfo region, ServerName targetServer) (package private) void
private void
checkAndWaitForOriginalServer
(MasterProcedureEnv env, ServerName lastHost) private void
closeRegion
(MasterProcedureEnv env, RegionStateNode regionNode) private StateMachineProcedure.Flow
confirmClosed
(MasterProcedureEnv env, RegionStateNode regionNode) private StateMachineProcedure.Flow
confirmOpened
(MasterProcedureEnv env, RegionStateNode regionNode) private static org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionTransitionType
private static TransitRegionStateProcedure.TransitionType
convert
(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionTransitionType type) protected void
deserializeStateData
(ProcedureStateSerializer serializer) Called on store load to allow the user to decode the previously serialized state.protected Procedure[]
The main code of the procedure.protected StateMachineProcedure.Flow
executeFromState
(MasterProcedureEnv env, org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState state) called to perform a single step of the specified 'state' of the procedureprotected org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState
Return the initial state object that will be used for the first call to executeFromState().protected ProcedureMetrics
Override this method to provide procedure specific counters for submitted count, failed count and time histogram.private RegionStateNode
protected org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState
getState
(int stateId) Convert an ordinal (or state id) to an Enum (or more descriptive) state object.protected int
getStateId
(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState state) Convert the Enum (or more descriptive) state object to an ordinal (or state id).Given an operation type we can take decisions about what to do with pending operations.private void
static TransitRegionStateProcedure
move
(MasterProcedureEnv env, RegionInfo region, ServerName targetServer) private void
openRegion
(MasterProcedureEnv env, RegionStateNode regionNode) private void
queueAssign
(MasterProcedureEnv env, RegionStateNode regionNode) static TransitRegionStateProcedure
reopen
(MasterProcedureEnv env, RegionInfo region) void
reportTransition
(MasterProcedureEnv env, RegionStateNode regionNode, ServerName serverName, org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode code, long seqId, long procId) protected void
rollbackState
(MasterProcedureEnv env, org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState state) called to perform the rollback of the specified stateprotected void
serializeStateData
(ProcedureStateSerializer serializer) The user-level code of the procedure may have some state to persist (e.g.void
serverCrashed
(MasterProcedureEnv env, RegionStateNode regionNode, ServerName serverName, boolean forceNewPlan) private void
private static TransitRegionStateProcedure
protected boolean
At end of timeout, wake ourselves up so we run again.(package private) void
stateLoaded
(AssignmentManager am, RegionStateNode regionNode) void
Extend the toString() information with the procedure details e.g.static TransitRegionStateProcedure
unassign
(MasterProcedureEnv env, RegionInfo region) static TransitRegionStateProcedure
unassignSplitMerge
(MasterProcedureEnv env, RegionInfo region) (package private) void
protected boolean
TheProcedure.doAcquireLock(Object, ProcedureStore)
will be split into two steps, first, it will call us to determine whether we need to wait for initialization, second, it will callProcedure.acquireLock(Object)
to actually handle the lock for this procedure.Methods inherited from class org.apache.hadoop.hbase.master.procedure.AbstractStateMachineRegionProcedure
acquireLock, getRegion, getTableName, holdLock, releaseLock, setFailure, setRegion
Methods inherited from class org.apache.hadoop.hbase.master.procedure.AbstractStateMachineTableProcedure
checkOnline, checkTableModifiable, getUser, getWALRegionDir, isTableEnabled, preflightChecks, releaseSyncLatch, setUser
Methods inherited from class org.apache.hadoop.hbase.procedure2.StateMachineProcedure
abort, addChildProcedure, failIfAborted, getCurrentState, getCurrentStateId, getCycles, isEofState, isRollbackSupported, isRollbackSupported, isYieldAfterExecutionStep, isYieldBeforeExecuteFromState, rollback, setNextState, toStringState
Methods inherited from class org.apache.hadoop.hbase.procedure2.Procedure
addStackIndex, afterReplay, beforeReplay, bypass, compareTo, completionCleanup, doExecute, doRollback, elapsedTime, getChildrenLatch, getException, getLastUpdate, getNonceKey, getOwner, getParentProcId, getProcId, getProcIdHashCode, getProcName, getResult, getRootProcedureId, getRootProcId, getStackIndexes, getState, getSubmittedTime, getTimeout, getTimeoutTimestamp, hasChildren, hasException, hasLock, hasOwner, hasParent, hasTimeout, haveSameParent, incChildrenLatch, isBypass, isFailed, isFinished, isInitializing, isLockedWhenLoading, isRunnable, isSuccess, isWaiting, removeStackIndex, setAbortFailure, setChildrenLatch, setExecuted, setFailure, setFailure, setLastUpdate, setNonceKey, setOwner, setOwner, setParentProcId, setProcId, setResult, setRootProcId, setStackIndexes, setState, setSubmittedTime, setTimeout, shouldWaitClientAck, skipPersistence, suspend, toString, toStringClass, toStringDetails, toStringSimpleSB, updateMetricsOnFinish, updateMetricsOnSubmit, updateTimestamp, wasExecuted
-
Field Details
-
LOG
-
type
-
initialState
private org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState initialState -
lastState
private org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState lastState -
assignCandidate
-
forceNewPlan
-
retryCounter
-
remoteProc
-
evictCache
-
isSplit
-
forceRetainmentRetryCounter
-
forceRetainmentTotalWait
-
-
Constructor Details
-
TransitRegionStateProcedure
public TransitRegionStateProcedure() -
TransitRegionStateProcedure
protected TransitRegionStateProcedure(MasterProcedureEnv env, RegionInfo hri, ServerName assignCandidate, boolean forceNewPlan, TransitRegionStateProcedure.TransitionType type) -
TransitRegionStateProcedure
protected TransitRegionStateProcedure(MasterProcedureEnv env, RegionInfo hri, ServerName assignCandidate, boolean forceNewPlan, TransitRegionStateProcedure.TransitionType type, boolean isSplit)
-
-
Method Details
-
setInitialAndLastState
-
initForceRetainmentRetryCounter
-
getTableOperationType
Description copied from interface:TableProcedureInterface
Given an operation type we can take decisions about what to do with pending operations. e.g. if we get a delete and we have some table operation pending (e.g. add column) we can abort those operations.- Specified by:
getTableOperationType
in interfaceTableProcedureInterface
- Specified by:
getTableOperationType
in classAbstractStateMachineRegionProcedure<org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState>
- Returns:
- the operation type that the procedure is executing.
-
waitInitialized
Description copied from class:Procedure
TheProcedure.doAcquireLock(Object, ProcedureStore)
will be split into two steps, first, it will call us to determine whether we need to wait for initialization, second, it will callProcedure.acquireLock(Object)
to actually handle the lock for this procedure. This is because that when master restarts, we need to restore the lock state for all the procedures to not break the semantic ifProcedure.holdLock(Object)
is true. But theProcedureExecutor
will be started before the master finish initialization(as it is part of the initialization!), so we need to split the code into two steps, and when restore, we just restore the lock part and ignore the waitInitialized part. Otherwise there will be dead lock.- Overrides:
waitInitialized
in classAbstractStateMachineTableProcedure<org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState>
- Returns:
- true means we need to wait until the environment has been initialized, otherwise true.
-
checkAndWaitForOriginalServer
private void checkAndWaitForOriginalServer(MasterProcedureEnv env, ServerName lastHost) throws ProcedureSuspendedException - Throws:
ProcedureSuspendedException
-
queueAssign
private void queueAssign(MasterProcedureEnv env, RegionStateNode regionNode) throws ProcedureSuspendedException - Throws:
ProcedureSuspendedException
-
openRegion
- Throws:
IOException
-
confirmOpened
private StateMachineProcedure.Flow confirmOpened(MasterProcedureEnv env, RegionStateNode regionNode) throws IOException - Throws:
IOException
-
closeRegion
- Throws:
IOException
-
confirmClosed
private StateMachineProcedure.Flow confirmClosed(MasterProcedureEnv env, RegionStateNode regionNode) throws IOException - Throws:
IOException
-
execute
protected Procedure[] execute(MasterProcedureEnv env) throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException Description copied from class:Procedure
The main code of the procedure. It must be idempotent since execute() may be called multiple times in case of machine failure in the middle of the execution.- Overrides:
execute
in classStateMachineProcedure<MasterProcedureEnv,
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState> - Parameters:
env
- the environment passed to the ProcedureExecutor- Returns:
- a set of sub-procedures to run or ourselves if there is more work to do or null if the procedure is done.
- Throws:
ProcedureSuspendedException
- Signal to the executor that Procedure has suspended itself and has set itself up waiting for an external event to wake it back up again.ProcedureYieldException
- the procedure will be added back to the queue and retried later.InterruptedException
- the procedure will be added back to the queue and retried later.
-
getRegionStateNode
-
executeFromState
protected StateMachineProcedure.Flow executeFromState(MasterProcedureEnv env, org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState state) throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException Description copied from class:StateMachineProcedure
called to perform a single step of the specified 'state' of the procedure- Specified by:
executeFromState
in classStateMachineProcedure<MasterProcedureEnv,
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState> state
- state to execute- Returns:
- Flow.NO_MORE_STATE if the procedure is completed, Flow.HAS_MORE_STATE if there is another step.
- Throws:
ProcedureSuspendedException
ProcedureYieldException
InterruptedException
-
setTimeoutFailure
At end of timeout, wake ourselves up so we run again.- Overrides:
setTimeoutFailure
in classProcedure<MasterProcedureEnv>
- Returns:
- true to let the framework handle the timeout as abort, false in case the procedure handled the timeout itself.
-
reportTransition
public void reportTransition(MasterProcedureEnv env, RegionStateNode regionNode, ServerName serverName, org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode code, long seqId, long procId) throws IOException - Throws:
IOException
-
serverCrashed
public void serverCrashed(MasterProcedureEnv env, RegionStateNode regionNode, ServerName serverName, boolean forceNewPlan) throws IOException - Throws:
IOException
-
attachRemoteProc
-
unattachRemoteProc
-
stateLoaded
-
rollbackState
protected void rollbackState(MasterProcedureEnv env, org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState state) throws IOException, InterruptedException Description copied from class:StateMachineProcedure
called to perform the rollback of the specified state- Specified by:
rollbackState
in classStateMachineProcedure<MasterProcedureEnv,
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState> state
- state to rollback- Throws:
IOException
- temporary failure, the rollback will retry laterInterruptedException
-
getState
protected org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState getState(int stateId) Description copied from class:StateMachineProcedure
Convert an ordinal (or state id) to an Enum (or more descriptive) state object.- Specified by:
getState
in classStateMachineProcedure<MasterProcedureEnv,
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState> - Parameters:
stateId
- the ordinal() of the state enum (or state id)- Returns:
- the state enum object
-
getStateId
protected int getStateId(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState state) Description copied from class:StateMachineProcedure
Convert the Enum (or more descriptive) state object to an ordinal (or state id).- Specified by:
getStateId
in classStateMachineProcedure<MasterProcedureEnv,
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState> - Parameters:
state
- the state enum object- Returns:
- stateId the ordinal() of the state enum (or state id)
-
getInitialState
protected org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState getInitialState()Description copied from class:StateMachineProcedure
Return the initial state object that will be used for the first call to executeFromState().- Specified by:
getInitialState
in classStateMachineProcedure<MasterProcedureEnv,
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState> - Returns:
- the initial state enum object
-
convert
private static TransitRegionStateProcedure.TransitionType convert(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionTransitionType type) -
convert
private static org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionTransitionType convert(TransitRegionStateProcedure.TransitionType type) -
serializeStateData
Description copied from class:Procedure
The user-level code of the procedure may have some state to persist (e.g. input arguments or current position in the processing state) to be able to resume on failure.- Overrides:
serializeStateData
in classAbstractStateMachineRegionProcedure<org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState>
- Parameters:
serializer
- stores the serializable state- Throws:
IOException
-
deserializeStateData
Description copied from class:Procedure
Called on store load to allow the user to decode the previously serialized state.- Overrides:
deserializeStateData
in classAbstractStateMachineRegionProcedure<org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState>
- Parameters:
serializer
- contains the serialized state- Throws:
IOException
-
getProcedureMetrics
Description copied from class:Procedure
Override this method to provide procedure specific counters for submitted count, failed count and time histogram.- Overrides:
getProcedureMetrics
in classProcedure<MasterProcedureEnv>
- Parameters:
env
- The environment passed to the procedure executor- Returns:
- Container object for procedure related metric
-
toStringClassDetails
Description copied from class:Procedure
Extend the toString() information with the procedure details e.g. className and parameters- Overrides:
toStringClassDetails
in classAbstractStateMachineRegionProcedure<org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState>
- Parameters:
sb
- the string builder to use to append the proc specific information
-
setOwner
private static TransitRegionStateProcedure setOwner(MasterProcedureEnv env, TransitRegionStateProcedure proc) -
assign
public static TransitRegionStateProcedure assign(MasterProcedureEnv env, RegionInfo region, @Nullable ServerName targetServer) -
assign
public static TransitRegionStateProcedure assign(MasterProcedureEnv env, RegionInfo region, boolean forceNewPlan, @Nullable ServerName targetServer) -
unassign
-
unassignSplitMerge
public static TransitRegionStateProcedure unassignSplitMerge(MasterProcedureEnv env, RegionInfo region) -
reopen
-
move
public static TransitRegionStateProcedure move(MasterProcedureEnv env, RegionInfo region, @Nullable ServerName targetServer)
-