@Override
  protected Flow executeFromState(final MasterProcedureEnv env, final EnableTableState state)
    throws InterruptedException {
    LOG.trace("{} execute state={}", this, state);

    try {
      switch (state) {
        case ENABLE_TABLE_PREPARE:
          if (prepareEnable(env)) {
            setNextState(EnableTableState.ENABLE_TABLE_PRE_OPERATION);
          } else {
            assert isFailed() : "enable should have an exception here";
            return Flow.NO_MORE_STATE;
          }
          break;
        case ENABLE_TABLE_PRE_OPERATION:
          preEnable(env, state);
          setNextState(EnableTableState.ENABLE_TABLE_SET_ENABLING_TABLE_STATE);
          break;
        case ENABLE_TABLE_SET_ENABLING_TABLE_STATE:
          setTableStateToEnabling(env, tableName);
          setNextState(EnableTableState.ENABLE_TABLE_MARK_REGIONS_ONLINE);
          break;
        case ENABLE_TABLE_MARK_REGIONS_ONLINE:
          // Get the region replica count. If changed since disable, need to do
          // more work assigning.
          TableDescriptor tableDescriptor =
            env.getMasterServices().getTableDescriptors().get(tableName);
          int configuredReplicaCount = tableDescriptor.getRegionReplication();
          // Get regions for the table from memory
          List<RegionInfo> regionsOfTable =
            env.getAssignmentManager().getRegionStates().getRegionsOfTableForEnabling(tableName);

          // How many replicas do we currently have? Check regions returned from
          // in-memory state.
          int currentMaxReplica = getMaxReplicaId(regionsOfTable);
          if (currentMaxReplica == configuredReplicaCount - 1) {
            LOG.debug(
              "No change in number of region replicas (configuredReplicaCount={});" + " assigning.",
              configuredReplicaCount);
          } else if (currentMaxReplica > (configuredReplicaCount - 1)) {
            // We have additional regions as the replica count has been decreased. Delete
            // those regions because already the table is in the unassigned state
            LOG.warn(
              "The number of replicas {} is more than the region replica count {}"
                + ", usually this should not happen as we will delete them in ModifyTableProcedure",
              currentMaxReplica + 1, configuredReplicaCount);
            List<RegionInfo> copyOfRegions = new ArrayList<RegionInfo>(regionsOfTable);
            for (RegionInfo regionInfo : copyOfRegions) {
              if (regionInfo.getReplicaId() > (configuredReplicaCount - 1)) {
                // delete the region from the regionStates
                env.getAssignmentManager().getRegionStates().deleteRegion(regionInfo);
                // remove it from the list of regions of the table
                LOG.info("Removed replica={} of {}", regionInfo.getRegionId(), regionInfo);
                regionsOfTable.remove(regionInfo);
              }
            }
          } else if (currentMaxReplica < configuredReplicaCount - 1) {
            // the replicasFound is less than the regionReplication
            LOG.info(
              "Number of replicas has increased for {}. Assigning new region replicas."
                + "The previous replica count was {}. The current replica count is {}.",
              this.tableName, currentMaxReplica + 1, configuredReplicaCount);
            regionsOfTable = RegionReplicaUtil.addReplicas(regionsOfTable, currentMaxReplica + 1,
              configuredReplicaCount);
          }
          // Assign all the table regions. (including region replicas if added).
          // createAssignProcedure will try to retain old assignments if possible.
          addChildProcedure(env.getAssignmentManager().createAssignProcedures(regionsOfTable));
          setNextState(EnableTableState.ENABLE_TABLE_SET_ENABLED_TABLE_STATE);
          break;
        case ENABLE_TABLE_SET_ENABLED_TABLE_STATE:
          setTableStateToEnabled(env, tableName);
          setNextState(EnableTableState.ENABLE_TABLE_POST_OPERATION);
          break;
        case ENABLE_TABLE_POST_OPERATION:
          postEnable(env, state);
          return Flow.NO_MORE_STATE;
        default:
          throw new UnsupportedOperationException("unhandled state=" + state);
      }
    } catch (IOException e) {
      if (isRollbackSupported(state)) {
        setFailure("master-enable-table", e);
      } else {
        LOG.warn(
          "Retriable error trying to enable table=" + tableName + " (in state=" + state + ")", e);
      }
    }
    return Flow.HAS_MORE_STATE;
  }
Constructor
@param env       MasterProcedureEnv
@param tableName the table to operate on
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java