Search in sources :

Example 1 with TableStateManager

use of org.apache.hadoop.hbase.master.TableStateManager in project hbase by apache.

the class AbstractStateMachineTableProcedure method preflightChecks.

/**
 * Check that cluster is up and master is running. Check table is modifiable.
 * If <code>enabled</code>, check table is enabled else check it is disabled.
 * Call in Procedure constructor so can pass any exception to caller.
 * @param enabled If true, check table is enabled and throw exception if not. If false, do the
 *                inverse. If null, do no table checks.
 */
protected void preflightChecks(MasterProcedureEnv env, Boolean enabled) throws HBaseIOException {
    MasterServices master = env.getMasterServices();
    if (!master.isClusterUp()) {
        throw new HBaseIOException("Cluster not up!");
    }
    if (master.isStopping() || master.isStopped()) {
        throw new HBaseIOException("Master stopping=" + master.isStopping() + ", stopped=" + master.isStopped());
    }
    if (enabled == null) {
        // Don't do any table checks.
        return;
    }
    try {
        // Checks table exists and is modifiable.
        checkTableModifiable(env);
        TableName tn = getTableName();
        TableStateManager tsm = master.getTableStateManager();
        TableState ts = tsm.getTableState(tn);
        if (enabled) {
            if (!ts.isEnabledOrEnabling()) {
                throw new TableNotEnabledException(tn);
            }
        } else {
            if (!ts.isDisabledOrDisabling()) {
                throw new TableNotDisabledException(tn);
            }
        }
    } catch (IOException ioe) {
        if (ioe instanceof HBaseIOException) {
            throw (HBaseIOException) ioe;
        }
        throw new HBaseIOException(ioe);
    }
}
Also used : TableNotDisabledException(org.apache.hadoop.hbase.TableNotDisabledException) TableName(org.apache.hadoop.hbase.TableName) TableStateManager(org.apache.hadoop.hbase.master.TableStateManager) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) MasterServices(org.apache.hadoop.hbase.master.MasterServices) IOException(java.io.IOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) TableState(org.apache.hadoop.hbase.client.TableState) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException)

Example 2 with TableStateManager

use of org.apache.hadoop.hbase.master.TableStateManager in project hbase by apache.

the class EnableTableProcedure method prepareEnable.

/**
 * Action before any real action of enabling table. Set the exception in the procedure instead
 * of throwing it.  This approach is to deal with backward compatible with 1.0.
 * @param env MasterProcedureEnv
 * @return whether the table passes the necessary checks
 * @throws IOException
 */
private boolean prepareEnable(final MasterProcedureEnv env) throws IOException {
    boolean canTableBeEnabled = true;
    // Check whether table exists
    if (!env.getMasterServices().getTableDescriptors().exists(tableName)) {
        setFailure("master-enable-table", new TableNotFoundException(tableName));
        canTableBeEnabled = false;
    } else {
        // There could be multiple client requests trying to disable or enable
        // the table at the same time. Ensure only the first request is honored
        // After that, no other requests can be accepted until the table reaches
        // DISABLED or ENABLED.
        // 
        // Note: in 1.0 release, we called TableStateManager.setTableStateIfInStates() to set
        // the state to ENABLING from DISABLED. The implementation was done before table lock
        // was implemented. With table lock, there is no need to set the state here (it will
        // set the state later on). A quick state check should be enough for us to move forward.
        TableStateManager tsm = env.getMasterServices().getTableStateManager();
        TableState ts = tsm.getTableState(tableName);
        if (!ts.isDisabled()) {
            LOG.info("Not DISABLED tableState={}; skipping enable; {}", ts.getState(), this);
            setFailure("master-enable-table", new TableNotDisabledException(ts.toString()));
            canTableBeEnabled = false;
        }
    }
    // We are done the check. Future actions in this procedure could be done asynchronously.
    releaseSyncLatch();
    return canTableBeEnabled;
}
Also used : TableNotDisabledException(org.apache.hadoop.hbase.TableNotDisabledException) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TableStateManager(org.apache.hadoop.hbase.master.TableStateManager) EnableTableState(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.EnableTableState) TableState(org.apache.hadoop.hbase.client.TableState)

Example 3 with TableStateManager

use of org.apache.hadoop.hbase.master.TableStateManager in project hbase by apache.

the class AbstractPeerProcedure method setLastPushedSequenceIdForTable.

// Will put the encodedRegionName->lastPushedSeqId pair into the map passed in, if the map is
// large enough we will call queueStorage.setLastSequenceIds and clear the map. So the caller
// should not forget to check whether the map is empty at last, if not you should call
// queueStorage.setLastSequenceIds to write out the remaining entries in the map.
protected final void setLastPushedSequenceIdForTable(MasterProcedureEnv env, TableName tableName, Map<String, Long> lastSeqIds) throws IOException, ReplicationException {
    TableStateManager tsm = env.getMasterServices().getTableStateManager();
    ReplicationQueueStorage queueStorage = env.getReplicationPeerManager().getQueueStorage();
    Connection conn = env.getMasterServices().getConnection();
    if (!needSetLastPushedSequenceId(tsm, tableName)) {
        LOG.debug("Skip settting last pushed sequence id for {}", tableName);
        return;
    }
    for (Pair<String, Long> name2Barrier : ReplicationBarrierFamilyFormat.getTableEncodedRegionNameAndLastBarrier(conn, tableName)) {
        LOG.trace("Update last pushed sequence id for {}, {}", tableName, name2Barrier);
        addToMap(lastSeqIds, name2Barrier.getFirst(), name2Barrier.getSecond().longValue() - 1, queueStorage);
    }
}
Also used : TableStateManager(org.apache.hadoop.hbase.master.TableStateManager) Connection(org.apache.hadoop.hbase.client.Connection) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage)

Example 4 with TableStateManager

use of org.apache.hadoop.hbase.master.TableStateManager in project hbase by apache.

the class DisableTableProcedure method prepareDisable.

/**
 * Action before any real action of disabling table. Set the exception in the procedure instead
 * of throwing it.  This approach is to deal with backward compatible with 1.0.
 * @param env MasterProcedureEnv
 */
private boolean prepareDisable(final MasterProcedureEnv env) throws IOException {
    boolean canTableBeDisabled = true;
    if (tableName.equals(TableName.META_TABLE_NAME)) {
        setFailure("master-disable-table", new ConstraintException("Cannot disable " + this.tableName));
        canTableBeDisabled = false;
    } else if (!env.getMasterServices().getTableDescriptors().exists(tableName)) {
        setFailure("master-disable-table", new TableNotFoundException(tableName));
        canTableBeDisabled = false;
    } else if (!skipTableStateCheck) {
        // There could be multiple client requests trying to disable or enable
        // the table at the same time. Ensure only the first request is honored
        // After that, no other requests can be accepted until the table reaches
        // DISABLED or ENABLED.
        // 
        // Note: in 1.0 release, we called TableStateManager.setTableStateIfInStates() to set
        // the state to DISABLING from ENABLED. The implementation was done before table lock
        // was implemented. With table lock, there is no need to set the state here (it will
        // set the state later on). A quick state check should be enough for us to move forward.
        TableStateManager tsm = env.getMasterServices().getTableStateManager();
        TableState ts = tsm.getTableState(tableName);
        if (!ts.isEnabled()) {
            LOG.info("Not ENABLED, state={}, skipping disable; {}", ts.getState(), this);
            setFailure("master-disable-table", new TableNotEnabledException(ts.toString()));
            canTableBeDisabled = false;
        }
    }
    // We are done the check. Future actions in this procedure could be done asynchronously.
    releaseSyncLatch();
    return canTableBeDisabled;
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TableStateManager(org.apache.hadoop.hbase.master.TableStateManager) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) TableState(org.apache.hadoop.hbase.client.TableState) DisableTableState(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.DisableTableState) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException)

Example 5 with TableStateManager

use of org.apache.hadoop.hbase.master.TableStateManager in project hbase by apache.

the class ModifyPeerProcedure method reopenRegions.

// will be override in test to simulate error
protected void reopenRegions(MasterProcedureEnv env) throws IOException {
    ReplicationPeerConfig peerConfig = getNewPeerConfig();
    ReplicationPeerConfig oldPeerConfig = getOldPeerConfig();
    TableStateManager tsm = env.getMasterServices().getTableStateManager();
    for (TableDescriptor td : env.getMasterServices().getTableDescriptors().getAll().values()) {
        if (!td.hasGlobalReplicationScope()) {
            continue;
        }
        TableName tn = td.getTableName();
        if (!peerConfig.needToReplicate(tn)) {
            continue;
        }
        if (oldPeerConfig != null && oldPeerConfig.isSerial() && oldPeerConfig.needToReplicate(tn)) {
            continue;
        }
        if (needReopen(tsm, tn)) {
            addChildProcedure(new ReopenTableRegionsProcedure(tn));
        }
    }
}
Also used : TableStateManager(org.apache.hadoop.hbase.master.TableStateManager) TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ReopenTableRegionsProcedure(org.apache.hadoop.hbase.master.procedure.ReopenTableRegionsProcedure) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Aggregations

TableStateManager (org.apache.hadoop.hbase.master.TableStateManager)11 TableName (org.apache.hadoop.hbase.TableName)6 IOException (java.io.IOException)4 Put (org.apache.hadoop.hbase.client.Put)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 TableState (org.apache.hadoop.hbase.client.TableState)3 Test (org.junit.Test)3 List (java.util.List)2 ServerName (org.apache.hadoop.hbase.ServerName)2 TableNotDisabledException (org.apache.hadoop.hbase.TableNotDisabledException)2 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)2 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2 Table (org.apache.hadoop.hbase.client.Table)2 Pair (org.apache.hadoop.hbase.util.Pair)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1