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 ClassesNested classes/interfaces inherited from class org.apache.hadoop.hbase.procedure2.StateMachineProcedure
StateMachineProcedure.FlowNested classes/interfaces inherited from class org.apache.hadoop.hbase.procedure2.Procedure
Procedure.LockStateNested classes/interfaces inherited from interface org.apache.hadoop.hbase.master.procedure.TableProcedureInterface
TableProcedureInterface.TableOperationType -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ServerNameprivate booleanprivate booleanprivate RetryCounterprivate longprivate CompletableFuture<Void>private org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionStateprivate booleanprivate org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionStateprivate static final org.slf4j.Loggerprivate RegionRemoteProcedureBaseprivate RetryCounterFields inherited from class org.apache.hadoop.hbase.procedure2.StateMachineProcedure
stateCountFields inherited from class org.apache.hadoop.hbase.procedure2.Procedure
NO_PROC_ID, NO_TIMEOUTFields inherited from interface org.apache.hadoop.hbase.master.procedure.TableProcedureInterface
DUMMY_NAMESPACE_TABLE_NAME -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTransitRegionStateProcedure(MasterProcedureEnv env, RegionInfo hri, ServerName assignCandidate, boolean forceNewPlan, TransitRegionStateProcedure.TransitionType type) protectedTransitRegionStateProcedure(MasterProcedureEnv env, RegionInfo hri, ServerName assignCandidate, boolean forceNewPlan, TransitRegionStateProcedure.TransitionType type, boolean isSplit) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCalled after we call the execute method of this procedure, and also after we initialize all the sub procedures and persist the the state if persistence is needed.static TransitRegionStateProcedureassign(MasterProcedureEnv env, RegionInfo region, boolean forceNewPlan, ServerName targetServer) static TransitRegionStateProcedureassign(MasterProcedureEnv env, RegionInfo region, ServerName targetServer) (package private) voidprotected voidCalled before we call the execute method of this procedure, but after we acquire the execution lock and procedure scheduler lock.private voidcheckAndWaitForOriginalServer(MasterProcedureEnv env, ServerName lastHost) private voidcloseRegion(MasterProcedureEnv env, RegionStateNode regionNode) private voidcloseRegionAfterUpdatingMeta(MasterProcedureEnv env, RegionStateNode regionNode) private StateMachineProcedure.FlowconfirmClosed(MasterProcedureEnv env, RegionStateNode regionNode) private StateMachineProcedure.FlowconfirmOpened(MasterProcedureEnv env, RegionStateNode regionNode) private static org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionTransitionTypeprivate static TransitRegionStateProcedure.TransitionTypeconvert(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionTransitionType type) protected voiddeserializeStateData(ProcedureStateSerializer serializer) Called on store load to allow the user to decode the previously serialized state.protected StateMachineProcedure.FlowexecuteFromState(MasterProcedureEnv env, org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState state) called to perform a single step of the specified 'state' of the procedureprivate CompletableFuture<Void>protected org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionStateReturn the initial state object that will be used for the first call to executeFromState().protected ProcedureMetricsOverride this method to provide procedure specific counters for submitted count, failed count and time histogram.private RegionStateNodeprotected org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionStategetState(int stateId) Convert an ordinal (or state id) to an Enum (or more descriptive) state object.protected intgetStateId(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 voidstatic TransitRegionStateProceduremove(MasterProcedureEnv env, RegionInfo region, ServerName targetServer) private voidopenRegion(MasterProcedureEnv env, RegionStateNode regionNode) private voidprivate voidqueueAssign(MasterProcedureEnv env, RegionStateNode regionNode) private voidregionFailedOpenAfterUpdatingMeta(MasterProcedureEnv env, RegionStateNode regionNode) static TransitRegionStateProcedurereopen(MasterProcedureEnv env, RegionInfo region) voidreportTransition(MasterProcedureEnv env, RegionStateNode regionNode, ServerName serverName, org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode code, long seqId, long procId) protected voidrollbackState(MasterProcedureEnv env, org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState state) called to perform the rollback of the specified stateprotected voidserializeStateData(ProcedureStateSerializer serializer) The user-level code of the procedure may have some state to persist (e.g.serverCrashed(MasterProcedureEnv env, RegionStateNode regionNode, ServerName serverName, boolean forceNewPlan) private voidprivate voidprivate static TransitRegionStateProcedureprotected booleanAt end of timeout, wake ourselves up so we run again.(package private) voidstateLoaded(AssignmentManager am, RegionStateNode regionNode) voidExtend the toString() information with the procedure details e.g.static TransitRegionStateProcedureunassign(MasterProcedureEnv env, RegionInfo region) static TransitRegionStateProcedureunassignSplitMerge(MasterProcedureEnv env, RegionInfo region) (package private) voidprotected booleanTheProcedure.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, setRegionMethods inherited from class org.apache.hadoop.hbase.master.procedure.AbstractStateMachineTableProcedure
checkOnline, checkTableModifiable, getUser, getWALRegionDir, isTableEnabled, isTableModificationInProgress, preflightChecks, releaseSyncLatch, setUserMethods inherited from class org.apache.hadoop.hbase.procedure2.StateMachineProcedure
abort, addChildProcedure, execute, failIfAborted, getCurrentState, getCurrentStateId, getCycles, isEofState, isRollbackSupported, isRollbackSupported, isYieldAfterExecutionStep, isYieldBeforeExecuteFromState, rollback, setNextState, toStringStateMethods 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
-
future
-
-
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:TableProcedureInterfaceGiven 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:
getTableOperationTypein interfaceTableProcedureInterface- Specified by:
getTableOperationTypein classAbstractStateMachineRegionProcedure<org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState>- Returns:
- the operation type that the procedure is executing.
-
waitInitialized
Description copied from class:ProcedureTheProcedure.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 theProcedureExecutorwill 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:
waitInitializedin 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
-
getFuture
-
setFuture
-
openRegionAfterUpdatingMeta
-
openRegion
private void openRegion(MasterProcedureEnv env, RegionStateNode regionNode) throws IOException, ProcedureSuspendedException -
regionFailedOpenAfterUpdatingMeta
-
confirmOpened
private StateMachineProcedure.Flow confirmOpened(MasterProcedureEnv env, RegionStateNode regionNode) throws IOException, ProcedureSuspendedException -
closeRegionAfterUpdatingMeta
-
closeRegion
private void closeRegion(MasterProcedureEnv env, RegionStateNode regionNode) throws IOException, ProcedureSuspendedException -
confirmClosed
private StateMachineProcedure.Flow confirmClosed(MasterProcedureEnv env, RegionStateNode regionNode) throws IOException - Throws:
IOException
-
beforeExec
Description copied from class:ProcedureCalled before we call the execute method of this procedure, but after we acquire the execution lock and procedure scheduler lock.- Overrides:
beforeExecin classProcedure<MasterProcedureEnv>- Throws:
ProcedureSuspendedException
-
afterExec
Description copied from class:ProcedureCalled after we call the execute method of this procedure, and also after we initialize all the sub procedures and persist the the state if persistence is needed.This is for doing some hooks after we initialize the sub procedures. See HBASE-29259 for more details on why we can not release the region lock inside the execute method.
- Overrides:
afterExecin classProcedure<MasterProcedureEnv>
-
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:StateMachineProcedurecalled to perform a single step of the specified 'state' of the procedure- Specified by:
executeFromStatein 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:
ProcedureSuspendedExceptionProcedureYieldExceptionInterruptedException
-
setTimeoutFailure
At end of timeout, wake ourselves up so we run again.- Overrides:
setTimeoutFailurein 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 CompletableFuture<Void> serverCrashed(MasterProcedureEnv env, RegionStateNode regionNode, ServerName serverName, boolean forceNewPlan) -
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:StateMachineProcedurecalled to perform the rollback of the specified state- Specified by:
rollbackStatein 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:StateMachineProcedureConvert an ordinal (or state id) to an Enum (or more descriptive) state object.- Specified by:
getStatein 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:StateMachineProcedureConvert the Enum (or more descriptive) state object to an ordinal (or state id).- Specified by:
getStateIdin 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:StateMachineProcedureReturn the initial state object that will be used for the first call to executeFromState().- Specified by:
getInitialStatein 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:ProcedureThe 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:
serializeStateDatain classAbstractStateMachineRegionProcedure<org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState>- Parameters:
serializer- stores the serializable state- Throws:
IOException
-
deserializeStateData
Description copied from class:ProcedureCalled on store load to allow the user to decode the previously serialized state.- Overrides:
deserializeStateDatain classAbstractStateMachineRegionProcedure<org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RegionStateTransitionState>- Parameters:
serializer- contains the serialized state- Throws:
IOException
-
getProcedureMetrics
Description copied from class:ProcedureOverride this method to provide procedure specific counters for submitted count, failed count and time histogram.- Overrides:
getProcedureMetricsin classProcedure<MasterProcedureEnv>- Parameters:
env- The environment passed to the procedure executor- Returns:
- Container object for procedure related metric
-
toStringClassDetails
Description copied from class:ProcedureExtend the toString() information with the procedure details e.g. className and parameters- Overrides:
toStringClassDetailsin 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)
-