Search in sources :

Example 6 with ConstraintException

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

the class TestCreateNamespaceProcedure method testCreateNamespaceWithInvalidTableCount.

@Test(timeout = 60000)
public void testCreateNamespaceWithInvalidTableCount() throws Exception {
    final NamespaceDescriptor nsd = NamespaceDescriptor.create("testCreateNamespaceWithInvalidTableCount").build();
    final String nsKey = "hbase.namespace.quota.maxtables";
    final String nsValue = "-1";
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    nsd.setConfiguration(nsKey, nsValue);
    long procId = procExec.submitProcedure(new CreateNamespaceProcedure(procExec.getEnvironment(), nsd));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId);
    ProcedureInfo result = procExec.getResult(procId);
    assertTrue(result.isFailed());
    LOG.debug("Create namespace failed with exception: " + result.getExceptionFullMessage());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException);
}
Also used : ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) Test(org.junit.Test)

Example 7 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 8 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 9 with ConstraintException

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

the class AbstractHBaseTableUtilTest method testTableSizeMetrics.

@Test
public void testTableSizeMetrics() throws Exception {
    HBaseTableUtil tableUtil = getTableUtil();
    // namespace should not exist
    if (namespacesSupported()) {
        Assert.assertFalse(tableUtil.hasNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId("namespace"))));
    }
    Assert.assertNull(getTableStats("namespace", "table1"));
    Assert.assertNull(getTableStats("namespace", "table2"));
    Assert.assertNull(getTableStats("namespace", "table3"));
    if (namespacesSupported()) {
        createNamespace("namespace");
        createNamespace("namespace2");
        Assert.assertTrue(tableUtil.hasNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId("namespace"))));
    }
    Futures.allAsList(createAsync(TableId.from("namespace", "table1")), createAsync(TableId.from("namespace2", "table1")), createAsync(TableId.from("namespace", "table2")), createAsync(TableId.from("namespace", "table3"))).get(60, TimeUnit.SECONDS);
    Assert.assertTrue(exists("namespace", "table1"));
    Assert.assertTrue(exists("namespace2", "table1"));
    Assert.assertTrue(exists("namespace", "table2"));
    Assert.assertTrue(exists("namespace", "table3"));
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                Assert.assertEquals(0, getTableStats("namespace", "table1").getTotalSizeMB());
                Assert.assertEquals(0, getTableStats("namespace2", "table1").getTotalSizeMB());
                Assert.assertEquals(0, getTableStats("namespace", "table2").getTotalSizeMB());
                Assert.assertEquals(0, getTableStats("namespace", "table3").getTotalSizeMB());
                return true;
            } catch (Throwable t) {
                return false;
            }
        }
    }, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
    writeSome("namespace2", "table1");
    writeSome("namespace", "table2");
    writeSome("namespace", "table3");
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                Assert.assertEquals(0, getTableStats("namespace", "table1").getTotalSizeMB());
                Assert.assertTrue(getTableStats("namespace2", "table1").getTotalSizeMB() > 0);
                Assert.assertTrue(getTableStats("namespace", "table2").getTotalSizeMB() > 0);
                Assert.assertTrue(getTableStats("namespace", "table3").getTotalSizeMB() > 0);
                return true;
            } catch (Throwable t) {
                return false;
            }
        }
    }, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
    drop("namespace", "table1");
    Assert.assertFalse(exists("namespace", "table1"));
    TableId hTableId = tableUtil.createHTableId(new NamespaceId("namespace"), "table2");
    //TODO: TestHBase methods should eventually accept namespace as a param, but will add them incrementally
    TEST_HBASE.forceRegionFlush(Bytes.toBytes(getTableNameAsString(hTableId)));
    truncate("namespace", "table3");
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                Assert.assertNull(getTableStats("namespace", "table1"));
                Assert.assertTrue(getTableStats("namespace", "table2").getTotalSizeMB() > 0);
                Assert.assertTrue(getTableStats("namespace", "table2").getStoreFileSizeMB() > 0);
                Assert.assertEquals(0, getTableStats("namespace", "table3").getTotalSizeMB());
                return true;
            } catch (Throwable t) {
                return false;
            }
        }
    }, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
    // modify
    HTableDescriptor desc = getTableDescriptor("namespace2", "table1");
    HTableDescriptorBuilder newDesc = getTableUtil().buildHTableDescriptor(desc);
    newDesc.setValue("mykey", "myvalue");
    disable("namespace2", "table1");
    getTableUtil().modifyTable(ddlExecutor, newDesc.build());
    desc = getTableDescriptor("namespace2", "table1");
    Assert.assertTrue(desc.getValue("mykey").equals("myvalue"));
    enable("namespace2", "table1");
    desc = getTableDescriptor("namespace", "table2");
    Assert.assertNull(desc.getValue("myKey"));
    if (namespacesSupported()) {
        try {
            deleteNamespace("namespace");
            Assert.fail("Should not be able to delete a non-empty namespace.");
        } catch (ConstraintException e) {
        // Expected exception
        }
    }
    Futures.allAsList(dropAsync(TableId.from("namespace2", "table1")), dropAsync(TableId.from("namespace", "table2")), dropAsync(TableId.from("namespace", "table3"))).get(60, TimeUnit.SECONDS);
    if (namespacesSupported()) {
        deleteNamespace("namespace");
        deleteNamespace("namespace2");
        Assert.assertFalse(tableUtil.hasNamespace(hAdmin, "namespace"));
        Assert.assertFalse(tableUtil.hasNamespace(hAdmin, "namespace2"));
    }
}
Also used : TableId(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) IOException(java.io.IOException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 10 with ConstraintException

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

the class TestAdmin2 method testDisableCatalogTable.

@Test(timeout = 300000)
public void testDisableCatalogTable() throws Exception {
    try {
        this.admin.disableTable(TableName.META_TABLE_NAME);
        fail("Expected to throw ConstraintException");
    } catch (ConstraintException e) {
    }
    // Before the fix for HBASE-6146, the below table creation was failing as the hbase:meta table
    // actually getting disabled by the disableTable() call.
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName().getBytes()));
    HColumnDescriptor hcd = new HColumnDescriptor("cf1".getBytes());
    htd.addFamily(hcd);
    TEST_UTIL.getHBaseAdmin().createTable(htd);
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) 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