HBASE-18433 Convenience method for creating simple ColumnFamilyDescriptor

Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Mike Drob 2017-07-21 23:05:21 -05:00 committed by Chia-Ping Tsai
parent ec3cb19664
commit 317ce73963
13 changed files with 40 additions and 28 deletions

View File

@ -104,6 +104,7 @@ public class HColumnDescriptor implements ColumnFamilyDescriptor, Comparable<HCo
*
* @param familyName Column family name. Must be 'printable' -- digit or
* letter -- and may not contain a <code>:</code>
* @deprecated use {@link ColumnFamilyDescriptorBuilder#of(String)}
*/
public HColumnDescriptor(final String familyName) {
this(Bytes.toBytes(familyName));
@ -115,6 +116,7 @@ public class HColumnDescriptor implements ColumnFamilyDescriptor, Comparable<HCo
*
* @param familyName Column family name. Must be 'printable' -- digit or
* letter -- and may not contain a <code>:</code>
* @deprecated use {@link ColumnFamilyDescriptorBuilder#of(byte[])}
*/
public HColumnDescriptor(final byte [] familyName) {
this(new ModifyableColumnFamilyDescriptor(familyName));
@ -125,6 +127,7 @@ public class HColumnDescriptor implements ColumnFamilyDescriptor, Comparable<HCo
* Makes a deep copy of the supplied descriptor.
* Can make a modifiable descriptor from an UnmodifyableHColumnDescriptor.
* @param desc The descriptor.
* @deprecated use {@link ColumnFamilyDescriptorBuilder#copy(ColumnFamilyDescriptor)}
*/
public HColumnDescriptor(HColumnDescriptor desc) {
this(desc, true);

View File

@ -32,6 +32,8 @@ import org.apache.hadoop.hbase.util.Bytes;
* number of versions, compression settings, etc.
*
* It is used as input when creating a table or adding a column.
*
* To construct a new instance, use the {@link ColumnFamilyDescriptorBuilder} methods
*/
@InterfaceAudience.Public
public interface ColumnFamilyDescriptor {

View File

@ -376,6 +376,14 @@ public class ColumnFamilyDescriptorBuilder {
return new ModifyableColumnFamilyDescriptor(desc);
}
public static ColumnFamilyDescriptor of(String name) {
return of(Bytes.toBytes(name));
}
public static ColumnFamilyDescriptor of(byte[] name) {
return newBuilder(name).build();
}
private ColumnFamilyDescriptorBuilder(final byte[] name) {
this.desc = new ModifyableColumnFamilyDescriptor(name);
}

View File

@ -92,7 +92,7 @@ public class TestColumnFamilyDescriptorBuilder {
public void testHColumnDescriptorShouldThrowIAEWhenFamiliyNameEmpty()
throws Exception {
try {
ColumnFamilyDescriptorBuilder.newBuilder("".getBytes()).build();
ColumnFamilyDescriptorBuilder.of("");
} catch (IllegalArgumentException e) {
assertEquals("Column Family name can not be empty", e.getLocalizedMessage());
}

View File

@ -382,7 +382,7 @@ public class RegionSplitter {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
for (String cf : columnFamilies) {
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(cf)).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(cf));
}
try (Connection connection = ConnectionFactory.createConnection(conf)) {
Admin admin = connection.getAdmin();

View File

@ -133,7 +133,7 @@ public abstract class TestAsyncAdminBase {
byte[]... families) {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
for (byte[] family : families) {
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(family).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
}
admin.createTable(builder.build(), splitKeys).join();
}

View File

@ -284,7 +284,7 @@ public class TestAsyncClusterAdminApi extends TestAsyncAdminBase {
private void createAndLoadTable(TableName[] tables) {
for (TableName table : tables) {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(table);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY));
admin.createTable(builder.build(), Bytes.toBytes("aaaaa"), Bytes.toBytes("zzzzz"), 16).join();
RawAsyncTable asyncTable = ASYNC_CONN.getRawTable(table);
List<Put> puts = new ArrayList<>();

View File

@ -66,7 +66,7 @@ public class TestAsyncDrainAdminApi extends TestAsyncAdminBase {
// Try for 20 seconds to create table (new region). Will not complete because all RSs draining.
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY));
final Runnable createTable = new Thread() {
@Override
public void run() {

View File

@ -188,7 +188,7 @@ public class TestAsyncRegionAdminApi extends TestAsyncAdminBase {
throws IOException, InterruptedException, ExecutionException {
TableDescriptor desc =
TableDescriptorBuilder.newBuilder(tableName)
.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build()).build();
.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
admin.createTable(desc, Bytes.toBytes("A"), Bytes.toBytes("Z"), 5).get();
// wait till the table is assigned

View File

@ -133,7 +133,7 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
byte[][] families = { FAMILY, FAMILY_0, FAMILY_1 };
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
for (byte[] family : families) {
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(family).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
}
TableDescriptor desc = builder.build();
admin.createTable(desc).join();
@ -178,7 +178,7 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
final TableName tableName3 = TableName.valueOf(tableName.getNameAsString() + "_3");
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName3);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY));
admin.createTable(builder.build(), "a".getBytes(), "z".getBytes(), 3).join();
regionLocations =
AsyncMetaTableAccessor.getTableHRegionLocations(metaTable, Optional.of(tableName3)).get();
@ -186,7 +186,7 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
final TableName tableName4 = TableName.valueOf(tableName.getNameAsString() + "_4");
builder = TableDescriptorBuilder.newBuilder(tableName4);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY));
try {
admin.createTable(builder.build(), "a".getBytes(), "z".getBytes(), 2).join();
fail("Should not be able to create a table with only 2 regions using this API.");
@ -196,7 +196,7 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
final TableName tableName5 = TableName.valueOf(tableName.getNameAsString() + "_5");
builder = TableDescriptorBuilder.newBuilder(tableName5);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY));
admin.createTable(builder.build(), new byte[] { 1 }, new byte[] { 127 }, 16).join();
regionLocations =
AsyncMetaTableAccessor.getTableHRegionLocations(metaTable, Optional.of(tableName5)).get();
@ -269,7 +269,7 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
expectedRegions = 10;
final TableName tableName2 = TableName.valueOf(tableName.getNameAsString() + "_2");
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName2);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY));
admin.createTable(builder.build(), startKey, endKey, expectedRegions).join();
regions =
@ -319,7 +319,7 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
expectedRegions = 5;
final TableName tableName3 = TableName.valueOf(tableName.getNameAsString() + "_3");
builder = TableDescriptorBuilder.newBuilder(tableName3);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY));
admin.createTable(builder.build(), startKey, endKey, expectedRegions).join();
regions =
@ -614,14 +614,14 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
public void testAddColumnFamily() throws Exception {
// Create a table with two families
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_0).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY_0));
admin.createTable(builder.build()).join();
admin.disableTable(tableName).join();
// Verify the table descriptor
verifyTableDescriptor(tableName, FAMILY_0);
// Modify the table removing one family and verify the descriptor
admin.addColumnFamily(tableName, ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_1).build())
admin.addColumnFamily(tableName, ColumnFamilyDescriptorBuilder.of(FAMILY_1))
.join();
verifyTableDescriptor(tableName, FAMILY_0, FAMILY_1);
}
@ -630,21 +630,20 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
public void testAddSameColumnFamilyTwice() throws Exception {
// Create a table with one families
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_0).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY_0));
admin.createTable(builder.build()).join();
admin.disableTable(tableName).join();
// Verify the table descriptor
verifyTableDescriptor(tableName, FAMILY_0);
// Modify the table removing one family and verify the descriptor
admin.addColumnFamily(tableName, ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_1).build())
.join();
admin.addColumnFamily(tableName, ColumnFamilyDescriptorBuilder.of(FAMILY_1)).join();
verifyTableDescriptor(tableName, FAMILY_0, FAMILY_1);
try {
// Add same column family again - expect failure
this.admin.addColumnFamily(tableName,
ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_1).build()).join();
ColumnFamilyDescriptorBuilder.of(FAMILY_1)).join();
Assert.fail("Delete a non-exist column family should fail");
} catch (Exception e) {
// Expected.
@ -654,7 +653,7 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
@Test
public void testModifyColumnFamily() throws Exception {
TableDescriptorBuilder tdBuilder = TableDescriptorBuilder.newBuilder(tableName);
ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_0).build();
ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.of(FAMILY_0);
int blockSize = cfd.getBlocksize();
admin.createTable(tdBuilder.addColumnFamily(cfd).build()).join();
admin.disableTable(tableName).join();
@ -674,7 +673,7 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
@Test
public void testModifyNonExistingColumnFamily() throws Exception {
TableDescriptorBuilder tdBuilder = TableDescriptorBuilder.newBuilder(tableName);
ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_0).build();
ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.of(FAMILY_0);
int blockSize = cfd.getBlocksize();
admin.createTable(tdBuilder.addColumnFamily(cfd).build()).join();
admin.disableTable(tableName).join();
@ -697,8 +696,8 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
public void testDeleteColumnFamily() throws Exception {
// Create a table with two families
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_0).build())
.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_1).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY_0))
.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY_1));
admin.createTable(builder.build()).join();
admin.disableTable(tableName).join();
// Verify the table descriptor
@ -713,8 +712,8 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase {
public void testDeleteSameColumnFamilyTwice() throws Exception {
// Create a table with two families
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_0).build())
.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_1).build());
builder.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY_0))
.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY_1));
admin.createTable(builder.build()).join();
admin.disableTable(tableName).join();
// Verify the table descriptor

View File

@ -305,7 +305,7 @@ public class TestReplicaWithCluster {
TableDescriptor td = TableDescriptorBuilder.newBuilder(TableName.valueOf("testChangeTable"))
.setRegionReplication(NB_SERVERS)
.addCoprocessor(SlowMeCopro.class.getName())
.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(f).build())
.addColumnFamily(ColumnFamilyDescriptorBuilder.of(f))
.build();
HTU.getAdmin().createTable(td);
Table table = HTU.getConnection().getTable(td.getTableName());
@ -321,7 +321,7 @@ public class TestReplicaWithCluster {
// Add a CF, it should work.
TableDescriptor bHdt = HTU.getAdmin().listTableDescriptor(td.getTableName());
td = TableDescriptorBuilder.newBuilder(td)
.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(row).build())
.addColumnFamily(ColumnFamilyDescriptorBuilder.of(row))
.build();
HTU.getAdmin().disableTable(td.getTableName());
HTU.getAdmin().modifyTable(td);

View File

@ -56,7 +56,7 @@ public class TestResultFromCoprocessor {
TEST_UTIL.startMiniCluster(3);
TableDescriptor desc = TableDescriptorBuilder.newBuilder(TABLE_NAME)
.addCoprocessor(MyObserver.class.getName())
.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build())
.addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY))
.build();
TEST_UTIL.getAdmin().createTable(desc);
}

View File

@ -284,7 +284,7 @@ public class TestSnapshotFromMaster {
// snapshot, the call after snapshot will be a no-op and checks will fail
UTIL.deleteTable(TABLE_NAME);
TableDescriptor td = TableDescriptorBuilder.newBuilder(TABLE_NAME)
.addColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(TEST_FAM).build())
.addColumnFamily(ColumnFamilyDescriptorBuilder.of(TEST_FAM))
.setCompactionEnabled(false)
.build();
UTIL.getAdmin().createTable(td);