use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestWALObserver method getBasic3FamilyHTableDescriptor.
private TableDescriptor getBasic3FamilyHTableDescriptor(TableName tableName) {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
Arrays.stream(TEST_FAMILY).map(ColumnFamilyDescriptorBuilder::of).forEachOrdered(builder::setColumnFamily);
return builder.build();
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestMasterObserverToModifyTableSchema method testMasterObserverToModifyTableSchema.
@Test
public void testMasterObserverToModifyTableSchema() throws IOException {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TABLENAME);
for (int i = 1; i <= 3; i++) {
builder.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf" + i)).setMaxVersions(i).build());
}
try (Admin admin = UTIL.getAdmin()) {
admin.createTable(builder.build());
assertOneVersion(admin.getDescriptor(TABLENAME));
builder.modifyColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf1")).setMaxVersions(Integer.MAX_VALUE).build());
admin.modifyTable(builder.build());
assertOneVersion(admin.getDescriptor(TABLENAME));
}
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestModifyTableProcedure method testConcurrentDeleteColumnFamily.
@Test
public void testConcurrentDeleteColumnFamily() throws IOException, InterruptedException {
final TableName tableName = TableName.valueOf(name.getMethodName());
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName);
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(column_Family1)).build();
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(column_Family2)).build();
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(column_Family3)).build();
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
UTIL.getAdmin().createTable(tableDescriptorBuilder.build());
class ConcurrentCreateDeleteTable extends Thread {
TableName tableName = null;
String columnFamily = null;
boolean exception;
public ConcurrentCreateDeleteTable(TableName tableName, String columnFamily) {
this.tableName = tableName;
this.columnFamily = columnFamily;
this.exception = false;
}
public void run() {
try {
UTIL.getAdmin().deleteColumnFamily(tableName, columnFamily.getBytes());
} catch (Exception e) {
if (e.getClass().equals(ConcurrentTableModificationException.class)) {
this.exception = true;
}
}
}
}
ConcurrentCreateDeleteTable t1 = new ConcurrentCreateDeleteTable(tableName, column_Family2);
ConcurrentCreateDeleteTable t2 = new ConcurrentCreateDeleteTable(tableName, column_Family3);
t1.start();
t2.start();
t1.join();
t2.join();
int noOfColumnFamilies = UTIL.getAdmin().getDescriptor(tableName).getColumnFamilies().length;
assertTrue("Expected ConcurrentTableModificationException.", ((t1.exception || t2.exception) && noOfColumnFamilies == 2) || noOfColumnFamilies == 1);
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestModifyTableProcedure method testRecoveryAndDoubleExecutionOnline.
@Test
public void testRecoveryAndDoubleExecutionOnline() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
final String cf2 = "cf2";
final String cf3 = "cf3";
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
// create the table
RegionInfo[] regions = MasterProcedureTestingUtility.createTable(procExec, tableName, null, "cf1", cf3);
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
// Modify multiple properties of the table.
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(UTIL.getAdmin().getDescriptor(tableName));
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(cf2)).build();
boolean newCompactionEnableOption = !tableDescriptorBuilder.build().isCompactionEnabled();
tableDescriptorBuilder.setCompactionEnabled(newCompactionEnableOption);
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
tableDescriptorBuilder.removeColumnFamily(Bytes.toBytes(cf3));
// Start the Modify procedure && kill the executor
long procId = procExec.submitProcedure(new ModifyTableProcedure(procExec.getEnvironment(), tableDescriptorBuilder.build()));
// Restart the executor and execute the step twice
MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);
// Validate descriptor
TableDescriptor currentHtd = UTIL.getAdmin().getDescriptor(tableName);
assertEquals(newCompactionEnableOption, currentHtd.isCompactionEnabled());
assertEquals(2, currentHtd.getColumnFamilyNames().size());
assertTrue(currentHtd.hasColumnFamily(Bytes.toBytes(cf2)));
assertFalse(currentHtd.hasColumnFamily(Bytes.toBytes(cf3)));
// cf2 should be added cf3 should be removed
MasterProcedureTestingUtility.validateTableCreation(UTIL.getHBaseCluster().getMaster(), tableName, regions, "cf1", cf2);
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestHRegionServerBulkLoad method setupTable.
/**
* Creates a table with given table name and specified number of column
* families if the table does not already exist.
*/
public void setupTable(TableName table, int cfs) throws IOException {
try {
LOG.info("Creating table " + table);
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(table);
tableDescriptorBuilder.setCoprocessor(MyObserver.class.getName());
MyObserver.sleepDuration = this.sleepDuration;
for (int i = 0; i < 10; i++) {
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family(i))).build();
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
}
UTIL.getAdmin().createTable(tableDescriptorBuilder.build());
} catch (TableExistsException tee) {
LOG.info("Table " + table + " already exists");
}
}
Aggregations