Search in sources :

Example 36 with ColumnFamilyDescriptorBuilder

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project janusgraph by JanusGraph.

the class HBaseStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(TableName tableName, String columnFamily, int ttlInSeconds) throws BackendException {
    Admin adm = null;
    try {
        adm = getAdminInterface();
        TableDescriptor desc = ensureTableExists(tableName, columnFamily, ttlInSeconds);
        Preconditions.checkNotNull(desc);
        ColumnFamilyDescriptor cf = desc.getColumnFamily(Bytes.toBytes(columnFamily));
        // Create our column family, if necessary
        if (cf == null) {
            try {
                if (!adm.isTableDisabled(tableName)) {
                    adm.disableTable(tableName);
                }
            } catch (TableNotEnabledException e) {
                logger.debug("Table {} already disabled", tableName);
            } catch (IOException e) {
                throw new TemporaryBackendException(e);
            }
            try {
                ColumnFamilyDescriptorBuilder columnDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(columnFamily));
                setCFOptions(columnDescriptor, ttlInSeconds);
                adm.addColumnFamily(tableName, columnDescriptor.build());
                try {
                    logger.debug("Added HBase ColumnFamily {}, waiting for 1 sec. to propagate.", columnFamily);
                    Thread.sleep(1000L);
                } catch (InterruptedException ie) {
                    throw new TemporaryBackendException(ie);
                }
                adm.enableTable(tableName);
            } catch (TableNotFoundException ee) {
                logger.error("TableNotFoundException", ee);
                throw new PermanentBackendException(ee);
            } catch (org.apache.hadoop.hbase.TableExistsException ee) {
                logger.debug("Swallowing exception", ee);
            } catch (IOException ee) {
                throw new TemporaryBackendException(ee);
            }
        }
    } finally {
        IOUtils.closeQuietly(adm);
    }
}
Also used : PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException)

Example 37 with ColumnFamilyDescriptorBuilder

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project janusgraph by JanusGraph.

the class HBaseStoreManager method createTable.

private TableDescriptor createTable(TableName tableName, String cfName, int ttlInSeconds, Admin adm) throws IOException {
    TableDescriptorBuilder desc = TableDescriptorBuilder.newBuilder(tableName);
    ColumnFamilyDescriptorBuilder columnDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(cfName));
    setCFOptions(columnDescriptor, ttlInSeconds);
    desc.setColumnFamily(columnDescriptor.build());
    TableDescriptor td = desc.build();
    // total regions to create
    int count;
    String src;
    if (MIN_REGION_COUNT <= (count = regionCount)) {
        src = "region count configuration";
    } else if (0 < regionsPerServer && MIN_REGION_COUNT <= (count = regionsPerServer * getEstimatedRegionServerCount(adm))) {
        src = "ClusterStatus server count";
    } else {
        count = -1;
        src = "default";
    }
    if (MIN_REGION_COUNT < count) {
        adm.createTable(td, getStartKey(count), getEndKey(count), count);
        logger.debug("Created table {} with region count {} from {}", tableName, count, src);
    } else {
        adm.createTable(td);
        logger.debug("Created table {} with default start key, end key, and region count", tableName);
    }
    return td;
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 38 with ColumnFamilyDescriptorBuilder

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.

the class IntegrationTestBackupRestore method createTable.

private void createTable(TableName tableName) throws Exception {
    long startTime, endTime;
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    TableDescriptor desc = builder.build();
    ColumnFamilyDescriptorBuilder cbuilder = ColumnFamilyDescriptorBuilder.newBuilder(COLUMN_NAME.getBytes(Charset.defaultCharset()));
    ColumnFamilyDescriptor[] columns = new ColumnFamilyDescriptor[] { cbuilder.build() };
    LOG.info("Creating table {} with {} splits.", tableName, regionsCountPerServer * regionServerCount);
    startTime = EnvironmentEdgeManager.currentTime();
    HBaseTestingUtil.createPreSplitLoadTestTable(util.getConfiguration(), desc, columns, regionsCountPerServer);
    util.waitTableAvailable(tableName);
    endTime = EnvironmentEdgeManager.currentTime();
    LOG.info("Pre-split table created successfully in {}ms.", (endTime - startTime));
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 39 with ColumnFamilyDescriptorBuilder

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.

the class Action method modifyAllTableColumns.

/**
 * Apply a transform to all columns in a given table. If there are no columns in a table
 * or if the context is stopping does nothing.
 * @param tableName the table to modify
 * @param transform the modification to perform. Callers will have the
 *                  column name as a string and a column family builder available to them
 */
protected void modifyAllTableColumns(TableName tableName, BiConsumer<String, ColumnFamilyDescriptorBuilder> transform) throws IOException {
    HBaseTestingUtil util = this.context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getAdmin();
    TableDescriptor tableDescriptor = admin.getDescriptor(tableName);
    ColumnFamilyDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();
    if (columnDescriptors == null || columnDescriptors.length == 0) {
        return;
    }
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
    for (ColumnFamilyDescriptor descriptor : columnDescriptors) {
        ColumnFamilyDescriptorBuilder cfd = ColumnFamilyDescriptorBuilder.newBuilder(descriptor);
        transform.accept(descriptor.getNameAsString(), cfd);
        builder.modifyColumnFamily(cfd.build());
    }
    // Don't try the modify if we're stopping
    if (this.context.isStopping()) {
        return;
    }
    admin.modifyTable(builder.build());
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 40 with ColumnFamilyDescriptorBuilder

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.

the class TestCopyTable method doCopyTableTestWithMob.

private void doCopyTableTestWithMob(boolean bulkload) throws Exception {
    final TableName tableName1 = TableName.valueOf(name.getMethodName() + "1");
    final TableName tableName2 = TableName.valueOf(name.getMethodName() + "2");
    final byte[] FAMILY = Bytes.toBytes("mob");
    final byte[] COLUMN1 = Bytes.toBytes("c1");
    ColumnFamilyDescriptorBuilder cfd = ColumnFamilyDescriptorBuilder.newBuilder(FAMILY);
    cfd.setMobEnabled(true);
    cfd.setMobThreshold(5);
    TableDescriptor desc1 = TableDescriptorBuilder.newBuilder(tableName1).setColumnFamily(cfd.build()).build();
    TableDescriptor desc2 = TableDescriptorBuilder.newBuilder(tableName2).setColumnFamily(cfd.build()).build();
    try (Table t1 = TEST_UTIL.createTable(desc1, null);
        Table t2 = TEST_UTIL.createTable(desc2, null)) {
        // put rows into the first table
        for (int i = 0; i < 10; i++) {
            Put p = new Put(Bytes.toBytes("row" + i));
            p.addColumn(FAMILY, COLUMN1, COLUMN1);
            t1.put(p);
        }
        CopyTable copy = new CopyTable();
        int code;
        if (bulkload) {
            code = ToolRunner.run(new Configuration(TEST_UTIL.getConfiguration()), copy, new String[] { "--new.name=" + tableName2.getNameAsString(), "--bulkload", tableName1.getNameAsString() });
        } else {
            code = ToolRunner.run(new Configuration(TEST_UTIL.getConfiguration()), copy, new String[] { "--new.name=" + tableName2.getNameAsString(), tableName1.getNameAsString() });
        }
        assertEquals("copy job failed", 0, code);
        // verify the data was copied into table 2
        for (int i = 0; i < 10; i++) {
            Get g = new Get(Bytes.toBytes("row" + i));
            Result r = t2.get(g);
            assertEquals(1, r.size());
            assertTrue(CellUtil.matchingQualifier(r.rawCells()[0], COLUMN1));
            assertEquals("compare row values between two tables", t1.getDescriptor().getValue("row" + i), t2.getDescriptor().getValue("row" + i));
        }
        assertEquals("compare count of mob rows after table copy", MobTestUtil.countMobRows(t1), MobTestUtil.countMobRows(t2));
        assertEquals("compare count of mob row values between two tables", t1.getDescriptor().getValues().size(), t2.getDescriptor().getValues().size());
        assertTrue("The mob row count is 0 but should be > 0", MobTestUtil.countMobRows(t2) > 0);
    } finally {
        TEST_UTIL.deleteTable(tableName1);
        TEST_UTIL.deleteTable(tableName2);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) Configuration(org.apache.hadoop.conf.Configuration) Get(org.apache.hadoop.hbase.client.Get) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

ColumnFamilyDescriptorBuilder (org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)61 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)43 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)19 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)16 Test (org.junit.Test)9 Table (org.apache.hadoop.hbase.client.Table)7 Admin (org.apache.hadoop.hbase.client.Admin)6 Put (org.apache.hadoop.hbase.client.Put)6 IOException (java.io.IOException)5 Configuration (org.apache.hadoop.conf.Configuration)5 Path (org.apache.hadoop.fs.Path)5 TableName (org.apache.hadoop.hbase.TableName)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 QName (javax.xml.namespace.QName)3 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)3 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 FileStatus (org.apache.hadoop.fs.FileStatus)2 FileSystem (org.apache.hadoop.fs.FileSystem)2