use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.
the class MetricHBaseTableUtilTest method testGetVersion.
@Test
public void testGetVersion() throws Exception {
// Verify new metric datasets are properly recognized as 2.8+ version from now on
HBaseMetricsTableDefinition definition = new HBaseMetricsTableDefinition("foo", TEST_HBASE.getConfiguration(), () -> hBaseTableUtil, new FileContextLocationFactory(TEST_HBASE.getConfiguration()), cConf);
DatasetSpecification spec = definition.configure("metricV2.8", DatasetProperties.EMPTY);
DatasetAdmin admin = definition.getAdmin(DatasetContext.from(NamespaceId.SYSTEM.getNamespace()), spec, null);
admin.create();
MetricHBaseTableUtil util = new MetricHBaseTableUtil(hBaseTableUtil);
HBaseAdmin hAdmin = TEST_HBASE.getHBaseAdmin();
TableId hTableId = hBaseTableUtil.createHTableId(NamespaceId.SYSTEM, spec.getName());
HTableDescriptor desc = hBaseTableUtil.getHTableDescriptor(hAdmin, hTableId);
desc.addFamily(new HColumnDescriptor("c"));
Assert.assertEquals(MetricHBaseTableUtil.Version.VERSION_2_8_OR_HIGHER, util.getVersion(desc));
// Verify HBase table without coprocessor is properly recognized as 2.6- version
TableName table26 = TableName.valueOf("metricV2.6");
hAdmin.createTable(new HTableDescriptor(table26).addFamily(new HColumnDescriptor("c")));
desc = hAdmin.getTableDescriptor(table26);
Assert.assertEquals(MetricHBaseTableUtil.Version.VERSION_2_6_OR_LOWER, util.getVersion(desc));
// Verify HBase table with IncrementHandler coprocessor but without cdap.version on it is properly recognized as
// 2.7 version
TableName table27 = TableName.valueOf("metricV2.7");
desc = new HTableDescriptor(table27).addFamily(new HColumnDescriptor("c"));
desc.addCoprocessor(hBaseTableUtil.getIncrementHandlerClassForVersion().getName());
hAdmin.createTable(desc);
desc = hAdmin.getTableDescriptor(table27);
Assert.assertEquals(MetricHBaseTableUtil.Version.VERSION_2_7, util.getVersion(desc));
}
use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.
the class HBase12CDH570TableUtil method listTables.
@Override
public List<TableId> listTables(HBaseAdmin admin) throws IOException {
List<TableId> tableIds = Lists.newArrayList();
HTableDescriptor[] hTableDescriptors = admin.listTables();
for (HTableDescriptor hTableDescriptor : hTableDescriptors) {
if (isCDAPTable(hTableDescriptor)) {
tableIds.add(HTableNameConverter.from(hTableDescriptor));
}
}
return tableIds;
}
use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.
the class IncrementSummingScannerTest method testFlushAndCompact.
@Test
public void testFlushAndCompact() throws Exception {
TableId tableId = TableId.from(NamespaceId.DEFAULT.getNamespace(), "TestFlushAndCompact");
byte[] familyBytes = Bytes.toBytes("f");
byte[] columnBytes = Bytes.toBytes("c");
HRegion region = createRegion(tableId, familyBytes);
try {
region.initialize();
// load an initial set of increments
long ts = System.currentTimeMillis();
byte[] row1 = Bytes.toBytes("row1");
for (int i = 0; i < 50; i++) {
Put p = new Put(row1);
p.add(familyBytes, columnBytes, ts, Bytes.toBytes(1L));
p.setAttribute(HBaseTable.DELTA_WRITE, TRUE);
ts++;
region.put(p);
}
byte[] row2 = Bytes.toBytes("row2");
ts = System.currentTimeMillis();
// start with a full put
Put row2P = new Put(row2);
row2P.add(familyBytes, columnBytes, ts++, Bytes.toBytes(10L));
region.put(row2P);
for (int i = 0; i < 10; i++) {
Put p = new Put(row2);
p.add(familyBytes, columnBytes, ts++, Bytes.toBytes(1L));
p.setAttribute(HBaseTable.DELTA_WRITE, TRUE);
region.put(p);
}
// force a region flush
region.flushcache(true, false);
region.waitForFlushesAndCompactions();
Result r1 = region.get(new Get(row1));
assertNotNull(r1);
assertFalse(r1.isEmpty());
// row1 should have a full put aggregating all 50 incrments
Cell r1Cell = r1.getColumnLatestCell(familyBytes, columnBytes);
assertNotNull(r1Cell);
assertEquals(50L, Bytes.toLong(r1Cell.getValue()));
Result r2 = region.get(new Get(row2));
assertNotNull(r2);
assertFalse(r2.isEmpty());
// row2 should have a full put aggregating prior put + 10 increments
Cell r2Cell = r2.getColumnLatestCell(familyBytes, columnBytes);
assertNotNull(r2Cell);
assertEquals(20L, Bytes.toLong(r2Cell.getValue()));
// add 30 more increments to row2
for (int i = 0; i < 30; i++) {
Put p = new Put(row2);
p.add(familyBytes, columnBytes, ts++, Bytes.toBytes(1L));
p.setAttribute(HBaseTable.DELTA_WRITE, TRUE);
region.put(p);
}
// row2 should now have a full put aggregating prior 20 value + 30 increments
r2 = region.get(new Get(row2));
assertNotNull(r2);
assertFalse(r2.isEmpty());
r2Cell = r2.getColumnLatestCell(familyBytes, columnBytes);
assertNotNull(r2Cell);
assertEquals(50L, Bytes.toLong(r2Cell.getValue()));
// force another region flush
region.flushcache(true, false);
region.waitForFlushesAndCompactions();
// add 100 more increments to row2
for (int i = 0; i < 100; i++) {
Put p = new Put(row2);
p.add(familyBytes, columnBytes, ts++, Bytes.toBytes(1L));
p.setAttribute(HBaseTable.DELTA_WRITE, TRUE);
region.put(p);
}
// row2 should now have a full put aggregating prior 50 value + 100 increments
r2 = region.get(new Get(row2));
assertNotNull(r2);
assertFalse(r2.isEmpty());
r2Cell = r2.getColumnLatestCell(familyBytes, columnBytes);
assertNotNull(r2Cell);
assertEquals(150L, Bytes.toLong(r2Cell.getValue()));
} finally {
region.close();
}
}
use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.
the class IncrementHandlerTest method createTable.
@Override
public Table createTable(TableId tableId) throws Exception {
HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
HTableDescriptorBuilder tableDesc = tableUtil.buildHTableDescriptor(tableId);
HColumnDescriptor columnDesc = new HColumnDescriptor(FAMILY);
columnDesc.setMaxVersions(Integer.MAX_VALUE);
columnDesc.setValue(IncrementHandlerState.PROPERTY_TRANSACTIONAL, "false");
tableDesc.addFamily(columnDesc);
tableDesc.addCoprocessor(IncrementHandler.class.getName());
HTableDescriptor htd = tableDesc.build();
TEST_HBASE.getHBaseAdmin().createTable(htd);
TEST_HBASE.waitUntilTableAvailable(htd.getName(), 5000);
return tableUtil.createTable(conf, tableId);
}
use of io.cdap.cdap.data2.util.TableId in project cdap by caskdata.
the class ConfigurationWriter method createTableIfNecessary.
/**
* Creates the configuration HBase table if it does not exist.
*/
@VisibleForTesting
void createTableIfNecessary() throws IOException {
try (HBaseDDLExecutor ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get()) {
HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, TABLE_NAME);
ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(FAMILY), hConf);
TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build());
ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
}
}
Aggregations