diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java index b90600b47075..0b19d59bcbea 100644 --- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java +++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java @@ -271,7 +271,7 @@ private boolean hasMoreState() { return stateFlow != Flow.NO_MORE_STATE; } - protected TState getCurrentState() { + public TState getCurrentState() { return stateCount > 0 ? getState(states[stateCount - 1]) : getInitialState(); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java index a5c2a4122eae..7f280ee39e42 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java @@ -31,8 +31,11 @@ import org.apache.hadoop.hbase.master.MasterFileSystem; import org.apache.hadoop.hbase.master.TableStateManager; import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer; +import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException; +import org.apache.hadoop.hbase.procedure2.ProcedureUtil; import org.apache.hadoop.hbase.replication.ReplicationBarrierFamilyFormat; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; +import org.apache.hadoop.hbase.util.RetryCounter; import org.apache.hadoop.hbase.wal.WALSplitUtil; import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; @@ -41,6 +44,9 @@ import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.DisableTableState; +import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.ServerCrashState; +import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos; +import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState; @InterfaceAudience.Private public class DisableTableProcedure extends AbstractStateMachineTableProcedure { @@ -49,6 +55,8 @@ public class DisableTableProcedure extends AbstractStateMachineTableProcedure !p.isFailed()).filter(p -> p instanceof ServerCrashProcedure) + .map(p -> (ServerCrashProcedure) p).filter(this::mayHaveSkew).count(); + if (count > 0) { + if (retryCounter == null) { + retryCounter = ProcedureUtil.createRetryCounter(env.getMasterConfiguration()); + } + long backoff = retryCounter.getBackoffTimeAndIncrementAttempts(); + LOG.info("There are {} SCPs may conflict with {}, sleep {}ms", count, this, backoff); + throw suspend(Math.toIntExact(backoff), true); + } + } // We are done the check. Future actions in this procedure could be done asynchronously. releaseSyncLatch(); @@ -276,9 +337,12 @@ private boolean prepareDisable(final MasterProcedureEnv env) throws IOException * @param env MasterProcedureEnv * @param state the procedure state */ - protected void preDisable(final MasterProcedureEnv env, final DisableTableState state) + private void preDisable(final MasterProcedureEnv env, final DisableTableState state) throws IOException, InterruptedException { - runCoprocessorAction(env, state); + MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost(); + if (cpHost != null) { + cpHost.preDisableTableAction(tableName, getUser()); + } } /** @@ -310,30 +374,11 @@ protected static void setTableStateToDisabled(final MasterProcedureEnv env, * @param env MasterProcedureEnv * @param state the procedure state */ - protected void postDisable(final MasterProcedureEnv env, final DisableTableState state) - throws IOException, InterruptedException { - runCoprocessorAction(env, state); - } - - /** - * Coprocessor Action. - * @param env MasterProcedureEnv - * @param state the procedure state - */ - private void runCoprocessorAction(final MasterProcedureEnv env, final DisableTableState state) + private void postDisable(final MasterProcedureEnv env, final DisableTableState state) throws IOException, InterruptedException { - final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost(); + MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost(); if (cpHost != null) { - switch (state) { - case DISABLE_TABLE_PRE_OPERATION: - cpHost.preDisableTableAction(tableName, getUser()); - break; - case DISABLE_TABLE_POST_OPERATION: - cpHost.postCompletedDisableTableAction(tableName, getUser()); - break; - default: - throw new UnsupportedOperationException(this + " unhandled state=" + state); - } + cpHost.postCompletedDisableTableAction(tableName, getUser()); } } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/SwitchRpcThrottleProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/SwitchRpcThrottleProcedure.java index ece7d3dc45e6..d8b39b264704 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/SwitchRpcThrottleProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/SwitchRpcThrottleProcedure.java @@ -118,11 +118,6 @@ protected SwitchRpcThrottleState getInitialState() { return SwitchRpcThrottleState.UPDATE_SWITCH_RPC_THROTTLE_STORAGE; } - @Override - protected SwitchRpcThrottleState getCurrentState() { - return super.getCurrentState(); - } - @Override protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException { super.serializeStateData(serializer);