Search in sources :

Example 71 with TableId

use of co.cask.cdap.data2.util.TableId in project cdap by caskdata.

the class HBaseQueueTest method forceEviction.

@Override
protected void forceEviction(QueueName queueName, int numGroups) throws Exception {
    TableId tableId = ((HBaseQueueAdmin) queueAdmin).getDataTableId(queueName);
    byte[] tableName = tableUtil.getHTableDescriptor(hbaseAdmin, tableId).getName();
    // make sure consumer config cache is updated with the latest tx snapshot
    takeTxSnapshot();
    final Class coprocessorClass = tableUtil.getQueueRegionObserverClassForVersion();
    TEST_HBASE.forEachRegion(tableName, new Function<HRegion, Object>() {

        public Object apply(HRegion region) {
            try {
                Coprocessor cp = region.getCoprocessorHost().findCoprocessor(coprocessorClass.getName());
                // calling cp.updateCache(), NOTE: cannot do normal cast and stuff because cp is loaded
                // by different classloader (corresponds to a cp's jar)
                LOG.info("forcing update of transaction state cache for HBaseQueueRegionObserver of region: {}", region);
                Method getTxStateCache = cp.getClass().getDeclaredMethod("getTxStateCache");
                getTxStateCache.setAccessible(true);
                Object txStateCache = getTxStateCache.invoke(cp);
                // the one returned is of type DefaultTransactionStateCache.
                // The refreshState method is a private method of its parent, TransactionStateCache
                Method refreshState = txStateCache.getClass().getSuperclass().getDeclaredMethod("refreshState");
                refreshState.setAccessible(true);
                refreshState.invoke(txStateCache);
                LOG.info("forcing update cache for HBaseQueueRegionObserver of region: {}", region);
                Method updateCache = cp.getClass().getDeclaredMethod("updateCache");
                updateCache.setAccessible(true);
                updateCache.invoke(cp);
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
            return null;
        }
    });
    // Force a table flush to trigger eviction
    TEST_HBASE.forceRegionFlush(tableName);
    TEST_HBASE.forceRegionCompact(tableName, true);
}
Also used : TableId(co.cask.cdap.data2.util.TableId) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Coprocessor(org.apache.hadoop.hbase.Coprocessor) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Method(java.lang.reflect.Method) IOException(java.io.IOException) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException)

Example 72 with TableId

use of co.cask.cdap.data2.util.TableId in project cdap by caskdata.

the class HBaseQueueTest method getConsumerConfigCache.

private ConsumerConfigCache getConsumerConfigCache(QueueName queueName) throws Exception {
    String tableName = HBaseQueueAdmin.getConfigTableName();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(queueName.getFirstComponent()), tableName);
    try (HTable hTable = tableUtil.createHTable(hConf, hTableId)) {
        HTableDescriptor htd = hTable.getTableDescriptor();
        final TableName configTableName = htd.getTableName();
        String prefix = htd.getValue(Constants.Dataset.TABLE_PREFIX);
        CConfigurationReader cConfReader = new CConfigurationReader(hConf, HTableNameConverter.getSysConfigTablePrefix(prefix));
        return TableNameAwareCacheSupplier.getSupplier(configTableName, cConfReader, new Supplier<TransactionVisibilityState>() {

            @Override
            public TransactionVisibilityState get() {
                try {
                    return getTransactionManager().getSnapshot();
                } catch (IOException e) {
                    throw Throwables.propagate(e);
                }
            }
        }, new InputSupplier<HTableInterface>() {

            @Override
            public HTableInterface getInput() throws IOException {
                return new HTable(hConf, configTableName);
            }
        }).get();
    }
}
Also used : TableId(co.cask.cdap.data2.util.TableId) TableName(org.apache.hadoop.hbase.TableName) CConfigurationReader(co.cask.cdap.data2.transaction.queue.hbase.coprocessor.CConfigurationReader) InputSupplier(com.google.common.io.InputSupplier) Supplier(com.google.common.base.Supplier) TableNameAwareCacheSupplier(co.cask.cdap.data2.transaction.queue.hbase.coprocessor.TableNameAwareCacheSupplier) NamespaceId(co.cask.cdap.proto.id.NamespaceId) IOException(java.io.IOException) HTable(org.apache.hadoop.hbase.client.HTable) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) InputSupplier(com.google.common.io.InputSupplier)

Example 73 with TableId

use of co.cask.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method disable.

private void disable(String namespace, String tableName) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(namespace), tableName);
    TableName name = HTableNameConverter.toTableName(getPrefix(), hTableId);
    ddlExecutor.disableTableIfEnabled(name.getNamespaceAsString(), name.getQualifierAsString());
}
Also used : TableId(co.cask.cdap.data2.util.TableId) TableName(org.apache.hadoop.hbase.TableName) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 74 with TableId

use of co.cask.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method getTableDescriptor.

private HTableDescriptor getTableDescriptor(String namespace, String name) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(namespace), name);
    return getTableUtil().getHTableDescriptor(hAdmin, hTableId);
}
Also used : TableId(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 75 with TableId

use of co.cask.cdap.data2.util.TableId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method testHTableDescriptor.

@Test
public void testHTableDescriptor() throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId tableId = TableId.from("default", "test.dataset");
    create(tableId);
    HTableDescriptor tableDescriptor = tableUtil.getHTableDescriptor(hAdmin, tableId);
    Assert.assertEquals(ProjectInfo.getVersion().toString(), tableDescriptor.getValue(HBaseTableUtil.CDAP_VERSION));
    Assert.assertEquals(getPrefix(), tableDescriptor.getValue(Constants.Dataset.TABLE_PREFIX));
    TableName tableName = HTableNameConverter.toTableName(getPrefix(), tableId);
    ddlExecutor.disableTableIfEnabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString());
    tableUtil.deleteTable(ddlExecutor, tableId);
}
Also used : TableId(co.cask.cdap.data2.util.TableId) TableName(org.apache.hadoop.hbase.TableName) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Aggregations

TableId (co.cask.cdap.data2.util.TableId)100 Test (org.junit.Test)49 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)40 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)39 Put (org.apache.hadoop.hbase.client.Put)34 NamespaceId (co.cask.cdap.proto.id.NamespaceId)26 Cell (org.apache.hadoop.hbase.Cell)24 Scan (org.apache.hadoop.hbase.client.Scan)24 HTableDescriptorBuilder (co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder)18 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)17 HBaseTableUtil (co.cask.cdap.data2.util.hbase.HBaseTableUtil)15 HBaseTableUtilFactory (co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory)15 IOException (java.io.IOException)13 HTable (org.apache.hadoop.hbase.client.HTable)11 Delete (org.apache.hadoop.hbase.client.Delete)9 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)9 HBaseDDLExecutor (co.cask.cdap.spi.hbase.HBaseDDLExecutor)8 Path (org.apache.hadoop.fs.Path)8 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)8 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)8