use of io.cdap.cdap.spi.hbase.HBaseDDLExecutor in project cdap by cdapio.
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);
}
}
use of io.cdap.cdap.spi.hbase.HBaseDDLExecutor in project cdap by cdapio.
the class HBaseTableFactory method createMetadataTable.
@Override
public MetadataTable createMetadataTable() throws IOException {
TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, metadataTableName);
Table table = null;
// If the table descriptor is in the cache, we assume the table exists.
if (!tableDescriptors.containsKey(tableId)) {
synchronized (this) {
if (!tableDescriptors.containsKey(tableId)) {
try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(COLUMN_FAMILY), hConf);
TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build());
ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
table = tableUtil.createTable(hConf, tableId);
tableDescriptors.put(tableId, table.getTableDescriptor());
}
}
}
}
if (table == null) {
table = tableUtil.createTable(hConf, tableId);
}
return new HBaseMetadataTable(tableUtil, table, COLUMN_FAMILY, cConf.getInt(Constants.MessagingSystem.HBASE_SCAN_CACHE_ROWS), createExceptionHandler(tableId));
}
Aggregations