Search in sources :

Example 6 with TableExistsException

use of org.apache.hadoop.hbase.TableExistsException in project hbase by apache.

the class TestAsyncTableAdminApi method testCloneTableSchemaWithExistentDestinationTable.

@Test
public void testCloneTableSchemaWithExistentDestinationTable() throws Exception {
    final TableName newTableName = TableName.valueOf(tableName.getNameAsString() + "_new");
    byte[] FAMILY_0 = Bytes.toBytes("cf0");
    TEST_UTIL.createTable(tableName, FAMILY_0);
    TEST_UTIL.createTable(newTableName, FAMILY_0);
    // test for existent destination table
    try {
        admin.cloneTableSchema(tableName, newTableName, false).join();
        fail("Should have failed when destination table exists.");
    } catch (CompletionException e) {
        assertTrue(e.getCause() instanceof TableExistsException);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) CompletionException(java.util.concurrent.CompletionException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) Test(org.junit.Test)

Example 7 with TableExistsException

use of org.apache.hadoop.hbase.TableExistsException in project hbase by apache.

the class TestCloneSnapshotProcedure method testCloneSnapshotToSameTable.

@Test
public void testCloneSnapshotToSameTable() throws Exception {
    // take the snapshot
    SnapshotProtos.SnapshotDescription snapshotDesc = getSnapshot();
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    final TableName clonedTableName = TableName.valueOf(snapshotDesc.getTable());
    final TableDescriptor htd = createTableDescriptor(clonedTableName, CF);
    long procId = ProcedureTestingUtility.submitAndWait(procExec, new CloneSnapshotProcedure(procExec.getEnvironment(), htd, snapshotDesc));
    Procedure<?> result = procExec.getResult(procId);
    assertTrue(result.isFailed());
    LOG.debug("Clone snapshot failed with exception: " + result.getException());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof TableExistsException);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TableExistsException(org.apache.hadoop.hbase.TableExistsException) SnapshotProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 8 with TableExistsException

use of org.apache.hadoop.hbase.TableExistsException in project hbase by apache.

the class TestHRegionServerBulkLoad method setupTable.

/**
 * Creates a table with given table name and specified number of column
 * families if the table does not already exist.
 */
public void setupTable(TableName table, int cfs) throws IOException {
    try {
        LOG.info("Creating table " + table);
        TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(table);
        tableDescriptorBuilder.setCoprocessor(MyObserver.class.getName());
        MyObserver.sleepDuration = this.sleepDuration;
        for (int i = 0; i < 10; i++) {
            ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family(i))).build();
            tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
        }
        UTIL.getAdmin().createTable(tableDescriptorBuilder.build());
    } catch (TableExistsException tee) {
        LOG.info("Table " + table + " already exists");
    }
}
Also used : TableExistsException(org.apache.hadoop.hbase.TableExistsException) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)

Example 9 with TableExistsException

use of org.apache.hadoop.hbase.TableExistsException in project hbase by apache.

the class TestAdmin method testCloneTableSchemaWithExistentDestinationTable.

@Test
public void testCloneTableSchemaWithExistentDestinationTable() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final TableName newTableName = TableName.valueOf(tableName.getNameAsString() + "_new");
    byte[] FAMILY_0 = Bytes.toBytes("cf0");
    TEST_UTIL.createTable(tableName, FAMILY_0);
    TEST_UTIL.createTable(newTableName, FAMILY_0);
    // test for existent destination table
    try {
        ADMIN.cloneTableSchema(tableName, newTableName, false);
        fail("Should have failed to create a existent table.");
    } catch (TableExistsException ex) {
    // expected
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TableExistsException(org.apache.hadoop.hbase.TableExistsException) Test(org.junit.Test)

Example 10 with TableExistsException

use of org.apache.hadoop.hbase.TableExistsException in project hbase by apache.

the class TestClusterRestart method test.

@Test
public void test() throws Exception {
    UTIL.startMiniCluster(3);
    UTIL.waitFor(60000, () -> UTIL.getMiniHBaseCluster().getMaster().isInitialized());
    LOG.info("\n\nCreating tables");
    for (TableName TABLE : TABLES) {
        UTIL.createTable(TABLE, FAMILY);
    }
    for (TableName TABLE : TABLES) {
        UTIL.waitTableEnabled(TABLE);
    }
    List<RegionInfo> allRegions = MetaTableAccessor.getAllRegions(UTIL.getConnection(), false);
    assertEquals(NUM_REGIONS, allRegions.size());
    LOG.info("\n\nShutting down cluster");
    UTIL.shutdownMiniHBaseCluster();
    LOG.info("\n\nSleeping a bit");
    Thread.sleep(2000);
    LOG.info("\n\nStarting cluster the second time");
    UTIL.restartHBaseCluster(3);
    // Need to use a new 'Configuration' so we make a new Connection.
    // Otherwise we're reusing an Connection that has gone stale because
    // the shutdown of the cluster also called shut of the connection.
    allRegions = MetaTableAccessor.getAllRegions(UTIL.getConnection(), false);
    assertEquals(NUM_REGIONS, allRegions.size());
    LOG.info("\n\nWaiting for tables to be available");
    for (TableName TABLE : TABLES) {
        try {
            UTIL.createTable(TABLE, FAMILY);
            assertTrue("Able to create table that should already exist", false);
        } catch (TableExistsException tee) {
            LOG.info("Table already exists as expected");
        }
        UTIL.waitTableAvailable(TABLE);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TableExistsException(org.apache.hadoop.hbase.TableExistsException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Test(org.junit.Test)

Aggregations

TableExistsException (org.apache.hadoop.hbase.TableExistsException)22 TableName (org.apache.hadoop.hbase.TableName)9 IOException (java.io.IOException)7 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)7 Test (org.junit.Test)7 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)5 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)4 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)3 Map (java.util.Map)2 Admin (org.apache.hadoop.hbase.client.Admin)2 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)2 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)2 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1