use of co.cask.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder in project cdap by caskdata.
the class AbstractHBaseTableUtilTest method create.
private void create(TableId tableId) throws IOException {
HBaseTableUtil tableUtil = getTableUtil();
TableId htableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder("d", hAdmin.getConfiguration());
TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(htableId, cConf);
tdBuilder.addColumnFamily(cfdBuilder.build());
ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
}
use of co.cask.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder in project cdap by caskdata.
the class HBaseTableAdmin method create.
@Override
public void create() throws IOException {
String columnFamily = Bytes.toString(TableProperties.getColumnFamilyBytes(spec.getProperties()));
ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(columnFamily, hConf);
if (TableProperties.getReadlessIncrementSupport(spec.getProperties())) {
cfdBuilder.setMaxVersions(Integer.MAX_VALUE);
} else if (DatasetsUtil.isTransactional(spec.getProperties())) {
// NOTE: we cannot limit number of versions as there's no hard limit on # of excluded from read txs
cfdBuilder.setMaxVersions(Integer.MAX_VALUE);
} else {
cfdBuilder.setMaxVersions(1);
}
cfdBuilder.setBloomType(ColumnFamilyDescriptor.BloomType.ROW);
Long ttl = TableProperties.getTTL(spec.getProperties());
if (ttl != null) {
// convert ttl from seconds to milli-seconds
ttl = TimeUnit.SECONDS.toMillis(ttl);
cfdBuilder.addProperty(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
}
final TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf);
// if the dataset is configured for read-less increments, then set the table property to support upgrades
boolean supportsReadlessIncrements = TableProperties.getReadlessIncrementSupport(spec.getProperties());
if (supportsReadlessIncrements) {
tdBuilder.addProperty(Table.PROPERTY_READLESS_INCREMENT, "true");
}
// if the dataset is configured to be non-transactional, then set the table property to support upgrades
if (!DatasetsUtil.isTransactional(spec.getProperties())) {
tdBuilder.addProperty(Constants.Dataset.TABLE_TX_DISABLED, "true");
if (supportsReadlessIncrements) {
// read-less increments CPs by default assume that table is transactional
cfdBuilder.addProperty("dataset.table.readless.increment.transactional", "false");
}
}
tdBuilder.addColumnFamily(cfdBuilder.build());
CoprocessorJar coprocessorJar = createCoprocessorJar();
for (Class<? extends Coprocessor> coprocessor : coprocessorJar.getCoprocessors()) {
tdBuilder.addCoprocessor(coprocessorManager.getCoprocessorDescriptor(coprocessor, coprocessorJar.getPriority(coprocessor)));
}
byte[][] splits = null;
String splitsProperty = spec.getProperty(PROPERTY_SPLITS);
if (splitsProperty != null) {
splits = GSON.fromJson(splitsProperty, byte[][].class);
}
// Disable split policy
String splitsPolicy = spec.getProperty(SPLIT_POLICY);
if (!Strings.isNullOrEmpty(splitsPolicy)) {
tdBuilder.addProperty(HTableDescriptor.SPLIT_POLICY, splitsPolicy);
}
try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
ddlExecutor.createTableIfNotExists(tdBuilder.build(), splits);
try {
Map<String, String> permissions = TableProperties.getTablePermissions(spec.getProperties());
if (permissions != null && !permissions.isEmpty()) {
tableUtil.grantPermissions(ddlExecutor, tableId, permissions);
}
} catch (IOException | RuntimeException e) {
try {
drop();
} catch (Throwable t) {
e.addSuppressed(t);
}
throw e;
}
}
}
use of co.cask.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder 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