Search in sources :

Example 81 with TableId

use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method exists.

private boolean exists(TableId tableId) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    return tableUtil.tableExists(hAdmin, hTableId);
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Example 82 with TableId

use of io.cdap.cdap.data2.util.TableId 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"));
    // Make sure that HBase version is added
    Assert.assertNotNull(desc.getValue(HBaseTableUtil.CDAP_HBASE_VERSION));
    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(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.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 83 with TableId

use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method getTableId.

private TableId getTableId(String namespace, String tableName) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    List<TableId> tableIds = tableUtil.listTablesInNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId(namespace)));
    for (TableId tId : tableIds) {
        if (tId.getTableName().endsWith(tableName)) {
            return tId;
        }
    }
    return null;
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Example 84 with TableId

use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method truncate.

private void truncate(String namespace, String tableName) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(namespace), tableName);
    tableUtil.truncateTable(ddlExecutor, hTableId);
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Example 85 with TableId

use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.

the class HBaseTableFactory method createMessageTable.

@Override
public MessageTable createMessageTable(TopicMetadata topicMetadata) throws IOException {
    TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, messageTableName);
    Class<? extends Coprocessor> tableCoprocessor = tableUtil.getMessageTableRegionObserverClassForVersion();
    HTableWithRowKeyDistributor tableWithRowKeyDistributor = createTable(tableId, cConf.getInt(Constants.MessagingSystem.MESSAGE_TABLE_HBASE_SPLITS), tableCoprocessor);
    return new HBaseMessageTable(tableUtil, tableWithRowKeyDistributor.getTable(), COLUMN_FAMILY, tableWithRowKeyDistributor.getRowKeyDistributor(), scanExecutor, cConf.getInt(Constants.MessagingSystem.HBASE_SCAN_CACHE_ROWS), createExceptionHandler(tableId));
}
Also used : TableId(io.cdap.cdap.data2.util.TableId)

Aggregations

TableId (co.cask.cdap.data2.util.TableId)102 Test (org.junit.Test)95 TableId (io.cdap.cdap.data2.util.TableId)78 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)60 Put (org.apache.hadoop.hbase.client.Put)57 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)55 Cell (org.apache.hadoop.hbase.Cell)42 Scan (org.apache.hadoop.hbase.client.Scan)40 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)32 NamespaceId (co.cask.cdap.proto.id.NamespaceId)26 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)19 IOException (java.io.IOException)17 HTableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder)16 Result (org.apache.hadoop.hbase.client.Result)16 Delete (org.apache.hadoop.hbase.client.Delete)15 Get (org.apache.hadoop.hbase.client.Get)14 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)14 HBaseTableUtil (io.cdap.cdap.data2.util.hbase.HBaseTableUtil)12 TableName (org.apache.hadoop.hbase.TableName)12 HTable (org.apache.hadoop.hbase.client.HTable)12