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);
}
}
}
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);
}
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;
}
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);
}
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);
}
Aggregations