Search in sources :

Example 1 with ConstraintException

use of org.apache.hadoop.hbase.constraint.ConstraintException in project hbase by apache.

the class RSGroupAdminServer method removeRSGroup.

@Override
public void removeRSGroup(String name) throws IOException {
    // another writer changing our state while we are working.
    synchronized (rsGroupInfoManager) {
        if (master.getMasterCoprocessorHost() != null) {
            master.getMasterCoprocessorHost().preRemoveRSGroup(name);
        }
        RSGroupInfo rsGroupInfo = rsGroupInfoManager.getRSGroup(name);
        if (rsGroupInfo == null) {
            throw new ConstraintException("RSGroup " + name + " does not exist");
        }
        int tableCount = rsGroupInfo.getTables().size();
        if (tableCount > 0) {
            throw new ConstraintException("RSGroup " + name + " has " + tableCount + " tables; you must remove these tables from the rsgroup before " + "the rsgroup can be removed.");
        }
        int serverCount = rsGroupInfo.getServers().size();
        if (serverCount > 0) {
            throw new ConstraintException("RSGroup " + name + " has " + serverCount + " servers; you must remove these servers from the RSGroup before" + "the RSGroup can be removed.");
        }
        for (NamespaceDescriptor ns : master.getClusterSchema().getNamespaces()) {
            String nsGroup = ns.getConfigurationValue(rsGroupInfo.NAMESPACE_DESC_PROP_GROUP);
            if (nsGroup != null && nsGroup.equals(name)) {
                throw new ConstraintException("RSGroup " + name + " is referenced by namespace: " + ns.getName());
            }
        }
        rsGroupInfoManager.removeRSGroup(name);
        if (master.getMasterCoprocessorHost() != null) {
            master.getMasterCoprocessorHost().postRemoveRSGroup(name);
        }
    }
}
Also used : NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException)

Example 2 with ConstraintException

use of org.apache.hadoop.hbase.constraint.ConstraintException in project hbase by apache.

the class DeleteNamespaceProcedure method prepareDelete.

/**
   * Action before any real action of deleting namespace.
   * @param env MasterProcedureEnv
   * @throws IOException
   */
private void prepareDelete(final MasterProcedureEnv env) throws IOException {
    if (getTableNamespaceManager(env).doesNamespaceExist(namespaceName) == false) {
        throw new NamespaceNotFoundException(namespaceName);
    }
    if (NamespaceDescriptor.RESERVED_NAMESPACES.contains(namespaceName)) {
        throw new ConstraintException("Reserved namespace " + namespaceName + " cannot be removed.");
    }
    int tableCount = 0;
    try {
        tableCount = env.getMasterServices().listTableDescriptorsByNamespace(namespaceName).size();
    } catch (FileNotFoundException fnfe) {
        throw new NamespaceNotFoundException(namespaceName);
    }
    if (tableCount > 0) {
        throw new ConstraintException("Only empty namespaces can be removed. " + "Namespace " + namespaceName + " has " + tableCount + " tables");
    }
    // This is used for rollback
    nsDescriptor = getTableNamespaceManager(env).get(namespaceName);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) NamespaceNotFoundException(org.apache.hadoop.hbase.NamespaceNotFoundException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException)

Example 3 with ConstraintException

use of org.apache.hadoop.hbase.constraint.ConstraintException 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
   * @throws IOException
   */
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 catalog table"));
        canTableBeDisabled = false;
    } else if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), 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.State state = tsm.getTableState(tableName);
        if (!state.equals(TableState.State.ENABLED)) {
            LOG.info("Table " + tableName + " isn't enabled;is " + state.name() + "; skipping disable");
            setFailure("master-disable-table", new TableNotEnabledException(tableName + " state is " + state.name()));
            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 4 with ConstraintException

use of org.apache.hadoop.hbase.constraint.ConstraintException in project hbase by apache.

the class TestDeleteNamespaceProcedure method testDeleteNonEmptyNamespace.

@Test(timeout = 60000)
public void testDeleteNonEmptyNamespace() throws Exception {
    final String namespaceName = "testDeleteNonExistNamespace";
    final TableName tableName = TableName.valueOf("testDeleteNonExistNamespace:" + name.getMethodName());
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    // create namespace
    createNamespaceForTesting(namespaceName);
    // create the table under the new namespace
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f1");
    long procId = procExec.submitProcedure(new DeleteNamespaceProcedure(procExec.getEnvironment(), namespaceName));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId);
    ProcedureInfo result = procExec.getResult(procId);
    assertTrue(result.isFailed());
    LOG.debug("Delete namespace failed with exception: " + result.getExceptionFullMessage());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) Test(org.junit.Test)

Example 5 with ConstraintException

use of org.apache.hadoop.hbase.constraint.ConstraintException in project hbase by apache.

the class TestDeleteNamespaceProcedure method testDeleteSystemNamespace.

@Test(timeout = 60000)
public void testDeleteSystemNamespace() throws Exception {
    final String namespaceName = NamespaceDescriptor.SYSTEM_NAMESPACE.getName();
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    long procId = procExec.submitProcedure(new DeleteNamespaceProcedure(procExec.getEnvironment(), namespaceName));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId);
    ProcedureInfo result = procExec.getResult(procId);
    assertTrue(result.isFailed());
    LOG.debug("Delete namespace failed with exception: " + result.getExceptionFullMessage());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException);
}
Also used : ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) Test(org.junit.Test)

Aggregations

ConstraintException (org.apache.hadoop.hbase.constraint.ConstraintException)15 Test (org.junit.Test)8 ProcedureInfo (org.apache.hadoop.hbase.ProcedureInfo)6 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)5 TableName (org.apache.hadoop.hbase.TableName)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)3 Address (org.apache.hadoop.hbase.net.Address)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 RegionPlan (org.apache.hadoop.hbase.master.RegionPlan)2 TableId (co.cask.cdap.data2.util.TableId)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1 FileNotFoundException (java.io.FileNotFoundException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1