Search in sources :

Example 66 with TableDescriptorBuilder

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();
}
Also used : TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder)

Example 67 with TableDescriptorBuilder

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));
    }
}
Also used : TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Example 68 with TableDescriptorBuilder

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) InvalidFamilyOperationException(org.apache.hadoop.hbase.InvalidFamilyOperationException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) ConcurrentTableModificationException(org.apache.hadoop.hbase.ConcurrentTableModificationException) Test(org.junit.Test)

Example 69 with TableDescriptorBuilder

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 70 with TableDescriptorBuilder

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");
    }
}
Also used : TableExistsException(org.apache.hadoop.hbase.TableExistsException) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)

Aggregations

TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)190 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)76 Test (org.junit.Test)68 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)61 ColumnFamilyDescriptorBuilder (org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)47 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)39 TableName (org.apache.hadoop.hbase.TableName)34 Path (org.apache.hadoop.fs.Path)31 Admin (org.apache.hadoop.hbase.client.Admin)29 Put (org.apache.hadoop.hbase.client.Put)25 IOException (java.io.IOException)24 Configuration (org.apache.hadoop.conf.Configuration)20 Table (org.apache.hadoop.hbase.client.Table)18 ArrayList (java.util.ArrayList)17 FileSystem (org.apache.hadoop.fs.FileSystem)15 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)15 Before (org.junit.Before)12 Cell (org.apache.hadoop.hbase.Cell)11 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)10 HashMap (java.util.HashMap)9