From 317ce739631495c056a8f82f580c46ccdab3f937 Mon Sep 17 00:00:00 2001 From: Mike Drob Date: Fri, 21 Jul 2017 23:05:21 -0500 Subject: [PATCH] HBASE-18433 Convenience method for creating simple ColumnFamilyDescriptor Signed-off-by: Chia-Ping Tsai --- .../hadoop/hbase/HColumnDescriptor.java | 3 ++ .../hbase/client/ColumnFamilyDescriptor.java | 2 ++ .../client/ColumnFamilyDescriptorBuilder.java | 8 +++++ .../TestColumnFamilyDescriptorBuilder.java | 2 +- .../hadoop/hbase/util/RegionSplitter.java | 2 +- .../hbase/client/TestAsyncAdminBase.java | 2 +- .../client/TestAsyncClusterAdminApi.java | 2 +- .../hbase/client/TestAsyncDrainAdminApi.java | 2 +- .../hbase/client/TestAsyncRegionAdminApi.java | 2 +- .../hbase/client/TestAsyncTableAdminApi.java | 35 +++++++++---------- .../hbase/client/TestReplicaWithCluster.java | 4 +-- .../client/TestResultFromCoprocessor.java | 2 +- .../cleaner/TestSnapshotFromMaster.java | 2 +- 13 files changed, 40 insertions(+), 28 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java index fb0b0ee8fe7..6764975a7c9 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java @@ -104,6 +104,7 @@ public class HColumnDescriptor implements ColumnFamilyDescriptor, Comparable: + * @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: + * @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 puts = new ArrayList<>(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncDrainAdminApi.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncDrainAdminApi.java index 88bda10b9b3..c31775ef9a2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncDrainAdminApi.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncDrainAdminApi.java @@ -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() { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java index 51e88162f92..5ec9ed8186b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java @@ -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 diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java index f2db2448138..e6fc2f36cd8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java @@ -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 diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java index 898f629437f..c2c6d283e1a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java @@ -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); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResultFromCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResultFromCoprocessor.java index ebbf47a3142..4425fb2a873 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResultFromCoprocessor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResultFromCoprocessor.java @@ -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); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java index 7118ab7d636..517940409fa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java @@ -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);