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