Search in sources :

Example 51 with ColumnFamilyDescriptorBuilder

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

the class LoadTestTool method applyColumnFamilyOptions.

/**
 * Apply column family options such as Bloom filters, compression, and data
 * block encoding.
 */
protected void applyColumnFamilyOptions(TableName tableName, byte[][] columnFamilies) throws IOException {
    try (Connection conn = ConnectionFactory.createConnection(conf);
        Admin admin = conn.getAdmin()) {
        TableDescriptor tableDesc = admin.getDescriptor(tableName);
        LOG.info("Disabling table " + tableName);
        admin.disableTable(tableName);
        for (byte[] cf : columnFamilies) {
            ColumnFamilyDescriptor columnDesc = tableDesc.getColumnFamily(cf);
            boolean isNewCf = columnDesc == null;
            ColumnFamilyDescriptorBuilder columnDescBuilder = isNewCf ? ColumnFamilyDescriptorBuilder.newBuilder(cf) : ColumnFamilyDescriptorBuilder.newBuilder(columnDesc);
            if (bloomType != null) {
                columnDescBuilder.setBloomFilterType(bloomType);
            }
            if (compressAlgo != null) {
                columnDescBuilder.setCompressionType(compressAlgo);
            }
            if (dataBlockEncodingAlgo != null) {
                columnDescBuilder.setDataBlockEncoding(dataBlockEncodingAlgo);
            }
            if (inMemoryCF) {
                columnDescBuilder.setInMemory(inMemoryCF);
            }
            if (cipher != null) {
                byte[] keyBytes = new byte[cipher.getKeyLength()];
                new SecureRandom().nextBytes(keyBytes);
                columnDescBuilder.setEncryptionType(cipher.getName());
                columnDescBuilder.setEncryptionKey(EncryptionUtil.wrapKey(conf, User.getCurrent().getShortName(), new SecretKeySpec(keyBytes, cipher.getName())));
            }
            if (mobThreshold >= 0) {
                columnDescBuilder.setMobEnabled(true);
                columnDescBuilder.setMobThreshold(mobThreshold);
            }
            if (isNewCf) {
                admin.addColumnFamily(tableName, columnDescBuilder.build());
            } else {
                admin.modifyColumnFamily(tableName, columnDescBuilder.build());
            }
        }
        LOG.info("Enabling table " + tableName);
        admin.enableTable(tableName);
    }
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) Connection(org.apache.hadoop.hbase.client.Connection) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) SecureRandom(java.security.SecureRandom) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 52 with ColumnFamilyDescriptorBuilder

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

the class BackupSystemTable method getSystemTableForBulkLoadedDataDescriptor.

/**
 * Get backup system table descriptor
 * @return table's descriptor
 */
public static TableDescriptor getSystemTableForBulkLoadedDataDescriptor(Configuration conf) {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(getTableNameForBulkLoadedData(conf));
    ColumnFamilyDescriptorBuilder colBuilder = ColumnFamilyDescriptorBuilder.newBuilder(SESSIONS_FAMILY);
    colBuilder.setMaxVersions(1);
    Configuration config = HBaseConfiguration.create();
    int ttl = config.getInt(BackupRestoreConstants.BACKUP_SYSTEM_TTL_KEY, BackupRestoreConstants.BACKUP_SYSTEM_TTL_DEFAULT);
    colBuilder.setTimeToLive(ttl);
    ColumnFamilyDescriptor colSessionsDesc = colBuilder.build();
    builder.setColumnFamily(colSessionsDesc);
    colBuilder = ColumnFamilyDescriptorBuilder.newBuilder(META_FAMILY);
    colBuilder.setTimeToLive(ttl);
    builder.setColumnFamily(colBuilder.build());
    return builder.build();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)

Example 53 with ColumnFamilyDescriptorBuilder

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

the class BackupSystemTable method getSystemTableDescriptor.

/**
 * Get backup system table descriptor
 * @return table's descriptor
 */
public static TableDescriptor getSystemTableDescriptor(Configuration conf) {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(getTableName(conf));
    ColumnFamilyDescriptorBuilder colBuilder = ColumnFamilyDescriptorBuilder.newBuilder(SESSIONS_FAMILY);
    colBuilder.setMaxVersions(1);
    Configuration config = HBaseConfiguration.create();
    int ttl = config.getInt(BackupRestoreConstants.BACKUP_SYSTEM_TTL_KEY, BackupRestoreConstants.BACKUP_SYSTEM_TTL_DEFAULT);
    colBuilder.setTimeToLive(ttl);
    ColumnFamilyDescriptor colSessionsDesc = colBuilder.build();
    builder.setColumnFamily(colSessionsDesc);
    colBuilder = ColumnFamilyDescriptorBuilder.newBuilder(META_FAMILY);
    colBuilder.setTimeToLive(ttl);
    builder.setColumnFamily(colBuilder.build());
    return builder.build();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)

Example 54 with ColumnFamilyDescriptorBuilder

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

the class TestExpiredMobFileCleaner method modifyColumnExpiryDays.

private void modifyColumnExpiryDays(int expireDays) throws Exception {
    ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family)).setMobEnabled(true).setMobThreshold(3L);
    // change ttl as expire days to make some row expired
    int timeToLive = expireDays * secondsOfDay();
    columnFamilyDescriptorBuilder.setTimeToLive(timeToLive);
    admin.modifyColumnFamily(tableName, columnFamilyDescriptorBuilder.build());
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)

Example 55 with ColumnFamilyDescriptorBuilder

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

the class HBaseTestingUtility method createTable.

/**
 * Create a table.
 * @return A Table instance for the created table.
 */
public Table createTable(TableName tableName, byte[][] families, int[] numVersions) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    int i = 0;
    for (byte[] family : families) {
        ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family).setMaxVersions(numVersions[i]);
        if (isNewVersionBehaviorEnabled()) {
            cfBuilder.setNewVersionBehavior(true);
        }
        builder.setColumnFamily(cfBuilder.build());
        i++;
    }
    getAdmin().createTable(builder.build());
    // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are
    // assigned
    waitUntilAllRegionsAssigned(tableName);
    return getConnection().getTable(tableName);
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder)

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