From e10baacd3e3e0c46ad4a0473990b682ed834c5f5 Mon Sep 17 00:00:00 2001 From: anoopsamjohn Date: Mon, 5 Dec 2016 13:28:57 +0530 Subject: [PATCH] HBASE-17245 Replace HTableDescriptor#htd.getColumnFamilies().length with a low-cost implementation. (huaxiang sun) --- .../java/org/apache/hadoop/hbase/HTableDescriptor.java | 9 +++++++++ .../hadoop/hbase/IntegrationTestDDLMasterFailover.java | 2 +- .../java/org/apache/hadoop/hbase/master/HMaster.java | 2 +- .../hbase/master/procedure/CreateTableProcedure.java | 2 +- .../master/procedure/DeleteColumnFamilyProcedure.java | 2 +- .../hbase/master/procedure/ModifyTableProcedure.java | 2 +- .../hbase/master/procedure/RestoreSnapshotProcedure.java | 2 +- .../org/apache/hadoop/hbase/regionserver/HRegion.java | 2 +- .../hadoop/hbase/client/TestReplicaWithCluster.java | 4 ++-- .../TestDeleteColumnFamilyProcedureFromClient.java | 4 ++-- .../hadoop/hbase/wal/WALPerformanceEvaluation.java | 2 +- 11 files changed, 21 insertions(+), 12 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java index 3d8d7da50e3..be8e858886e 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java @@ -1197,6 +1197,15 @@ public class HTableDescriptor implements Comparable { return Collections.unmodifiableSet(this.families.keySet()); } + /** + * Returns the count of the column families of the table. + * + * @return Count of column families of the table + */ + public int getColumnFamilyCount() { + return families.size(); + } + /** * Returns an array all the {@link HColumnDescriptor} of the column families * of the table. diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java index 741c2d2b014..59cb8dded72 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java @@ -733,7 +733,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { Admin admin = connection.getAdmin(); try { - if (selected.getColumnFamilies().length < 2) { + if (selected.getColumnFamilyCount() < 2) { LOG.info("No enough column families to delete in table " + selected.getTableName()); return; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 710c48a65ba..af05c1613e6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -1694,7 +1694,7 @@ public class HMaster extends HRegionServer implements MasterServices { warnOrThrowExceptionForFailure(false, CONF_KEY, e.getMessage(), e); } // check that we have at least 1 CF - if (htd.getColumnFamilies().length == 0) { + if (htd.getColumnFamilyCount() == 0) { String message = "Table should have at least one column family."; warnOrThrowExceptionForFailure(logWarn, CONF_KEY, message, null); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java index 7e772e21acc..0d24f511039 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java @@ -231,7 +231,7 @@ public class CreateTableProcedure } // check that we have at least 1 CF - if (hTableDescriptor.getColumnFamilies().length == 0) { + if (hTableDescriptor.getColumnFamilyCount() == 0) { setFailure("master-create-table", new DoNotRetryIOException("Table " + getTableName().toString() + " should have at least one column family.")); return false; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java index 238ecf2db88..096172a780d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java @@ -242,7 +242,7 @@ public class DeleteColumnFamilyProcedure + "' does not exist, so it cannot be deleted"); } - if (unmodifiedHTableDescriptor.getColumnFamilies().length == 1) { + if (unmodifiedHTableDescriptor.getColumnFamilyCount() == 1) { throw new InvalidFamilyOperationException("Family '" + getColumnFamilyName() + "' is the only column family in the table, so it cannot be deleted"); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java index 052d4d85ed7..f1b411abcf2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/ModifyTableProcedure.java @@ -237,7 +237,7 @@ public class ModifyTableProcedure } // check that we have at least 1 CF - if (modifiedHTableDescriptor.getColumnFamilies().length == 0) { + if (modifiedHTableDescriptor.getColumnFamilyCount() == 0) { throw new DoNotRetryIOException("Table " + getTableName().toString() + " should have at least one column family."); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/RestoreSnapshotProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/RestoreSnapshotProcedure.java index be693fea59e..d99bd6b0ccb 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/RestoreSnapshotProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/RestoreSnapshotProcedure.java @@ -326,7 +326,7 @@ public class RestoreSnapshotProcedure env.getMasterServices().checkTableModifiable(tableName); // Check that we have at least 1 CF - if (modifiedHTableDescriptor.getColumnFamilies().length == 0) { + if (modifiedHTableDescriptor.getColumnFamilyCount() == 0) { throw new DoNotRetryIOException("Table " + getTableName().toString() + " should have at least one column family."); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 86da3489e56..ed8c5d22344 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -802,7 +802,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi private long initialize(final CancelableProgressable reporter) throws IOException { //Refuse to open the region if there is no column family in the table - if (htableDescriptor.getColumnFamilies().length == 0) { + if (htableDescriptor.getColumnFamilyCount() == 0) { throw new DoNotRetryIOException("Table " + htableDescriptor.getNameAsString() + " should have at least one column family."); } 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 1687a4d7849..9f9037f6bb7 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 @@ -246,7 +246,7 @@ public class TestReplicaWithCluster { HTU.getHBaseAdmin().enableTable(hdt.getTableName()); HTableDescriptor nHdt = HTU.getHBaseAdmin().getTableDescriptor(hdt.getTableName()); Assert.assertEquals("fams=" + Arrays.toString(nHdt.getColumnFamilies()), - bHdt.getColumnFamilies().length + 1, nHdt.getColumnFamilies().length); + bHdt.getColumnFamilyCount() + 1, nHdt.getColumnFamilyCount()); p = new Put(row); p.addColumn(row, row, row); @@ -270,7 +270,7 @@ public class TestReplicaWithCluster { Admin admin = HTU.getHBaseAdmin(); nHdt =admin.getTableDescriptor(hdt.getTableName()); Assert.assertEquals("fams=" + Arrays.toString(nHdt.getColumnFamilies()), - bHdt.getColumnFamilies().length + 1, nHdt.getColumnFamilies().length); + bHdt.getColumnFamilyCount() + 1, nHdt.getColumnFamilyCount()); admin.disableTable(hdt.getTableName()); admin.deleteTable(hdt.getTableName()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteColumnFamilyProcedureFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteColumnFamilyProcedureFromClient.java index 4524a3746a5..fd17f3058d9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteColumnFamilyProcedureFromClient.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteColumnFamilyProcedureFromClient.java @@ -107,7 +107,7 @@ public class TestDeleteColumnFamilyProcedureFromClient { assertTrue(admin.isTableAvailable(TABLENAME)); // 2 - Check if all three families exist in descriptor - assertEquals(3, beforehtd.getColumnFamilies().length); + assertEquals(3, beforehtd.getColumnFamilyCount()); HColumnDescriptor[] families = beforehtd.getColumnFamilies(); for (int i = 0; i < families.length; i++) { assertTrue(families[i].getNameAsString().equals("cf" + (i + 1))); @@ -147,7 +147,7 @@ public class TestDeleteColumnFamilyProcedureFromClient { // 5 - Check if only 2 column families exist in the descriptor HTableDescriptor afterhtd = admin.getTableDescriptor(TABLENAME); - assertEquals(2, afterhtd.getColumnFamilies().length); + assertEquals(2, afterhtd.getColumnFamilyCount()); HColumnDescriptor[] newFamilies = afterhtd.getColumnFamilies(); assertTrue(newFamilies[0].getNameAsString().equals("cf1")); assertTrue(newFamilies[1].getNameAsString().equals("cf3")); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/WALPerformanceEvaluation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/WALPerformanceEvaluation.java index 1b513b20897..7300ee49a25 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/WALPerformanceEvaluation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/WALPerformanceEvaluation.java @@ -138,7 +138,7 @@ public final class WALPerformanceEvaluation extends Configured implements Tool { this.numIterations = numIterations; this.noSync = noSync; this.syncInterval = syncInterval; - this.numFamilies = htd.getColumnFamilies().length; + this.numFamilies = htd.getColumnFamilyCount(); this.region = region; this.htd = htd; scopes = new TreeMap(