From e02209440065fe9b1fbb42f4223c9102177ca954 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Sun, 30 Aug 2020 17:31:26 +0800 Subject: [PATCH] HBASE-24964 Remove MetaTableAccessor.tableExists (#2330) Signed-off-by: Viraj Jasani --- .../hadoop/hbase/MetaTableAccessor.java | 15 ------ .../hadoop/hbase/client/HBaseAdmin.java | 4 +- .../apache/hadoop/hbase/TableDescriptors.java | 8 ++++ .../apache/hadoop/hbase/master/HMaster.java | 4 +- .../hbase/master/TableNamespaceManager.java | 13 +++-- .../AbstractStateMachineRegionProcedure.java | 15 ------ .../AbstractStateMachineTableProcedure.java | 4 +- .../procedure/CloneSnapshotProcedure.java | 6 +-- .../procedure/CreateTableProcedure.java | 2 +- .../procedure/DisableTableProcedure.java | 2 +- .../procedure/EnableTableProcedure.java | 3 +- .../procedure/ModifyTableProcedure.java | 2 +- .../procedure/RestoreSnapshotProcedure.java | 4 +- .../master/slowlog/SlowLogMasterService.java | 2 +- .../master/snapshot/SnapshotManager.java | 3 +- .../hbase/namespace/NamespaceAuditor.java | 2 +- .../hbase/quotas/MasterQuotaManager.java | 5 +- .../quotas/SpaceQuotaRefresherChore.java | 13 ++--- .../access/SnapshotScannerHDFSAclCleaner.java | 2 +- .../visibility/VisibilityController.java | 48 +++++++++---------- .../hadoop/hbase/TestMetaTableAccessor.java | 22 +-------- .../MasterProcedureTestingUtility.java | 11 ++++- .../hbase/namequeues/TestSlowLogAccessor.java | 18 +++---- .../TestQuotaObserverChoreRegionReports.java | 16 +++---- .../quotas/TestSpaceQuotasWithSnapshots.java | 7 ++- .../TestSplitTransactionOnCluster.java | 7 +-- 26 files changed, 94 insertions(+), 144 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java index b571ecf67322..0e89689ec22d 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java @@ -446,21 +446,6 @@ private static boolean isMergeQualifierPrefix(Cell cell) { PrivateCellUtil.qualifierStartsWith(cell, HConstants.MERGE_QUALIFIER_PREFIX); } - /** - * Checks if the specified table exists. Looks at the hbase:meta table hosted on - * the specified server. - * @param connection connection we're using - * @param tableName table to check - * @return true if the table exists in meta, false if not - */ - public static boolean tableExists(Connection connection, - final TableName tableName) - throws IOException { - // Catalog tables always exist. - return tableName.equals(TableName.META_TABLE_NAME) || - getTableState(connection, tableName) != null; - } - /** * Lists all of the regions currently in META. * diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 137572e8a2f2..03ada1713b39 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -464,7 +464,7 @@ public boolean tableExists(final TableName tableName) throws IOException { return executeCallable(new RpcRetryingCallable() { @Override protected Boolean rpcCall(int callTimeout) throws Exception { - return MetaTableAccessor.tableExists(connection, tableName); + return MetaTableAccessor.getTableState(getConnection(), tableName) != null; } }); } @@ -2026,7 +2026,7 @@ private TableName checkTableExists(final TableName tableName) return executeCallable(new RpcRetryingCallable() { @Override protected TableName rpcCall(int callTimeout) throws Exception { - if (!MetaTableAccessor.tableExists(connection, tableName)) { + if (MetaTableAccessor.getTableState(getConnection(), tableName) == null) { throw new TableNotFoundException(tableName); } return tableName; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java index e82082cff3e7..f7e07045f4c5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java @@ -28,6 +28,14 @@ */ @InterfaceAudience.Private public interface TableDescriptors { + + /** + * Test whether a given table exists, i.e, has a table descriptor. + */ + default boolean exists(TableName tableName) throws IOException { + return get(tableName) != null; + } + /** * @return TableDescriptor for tablename */ 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 16deecd6445a..d4f604b988b7 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 @@ -2576,8 +2576,8 @@ protected String getDescription() { } private void checkTableExists(final TableName tableName) - throws IOException, TableNotFoundException { - if (!MetaTableAccessor.tableExists(getConnection(), tableName)) { + throws IOException, TableNotFoundException { + if (!tableDescriptors.exists(tableName)) { throw new TableNotFoundException(tableName); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/TableNamespaceManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/TableNamespaceManager.java index aefeebe09895..79e7207c8a90 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/TableNamespaceManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/TableNamespaceManager.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.util.NavigableSet; - import org.apache.commons.lang3.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; @@ -30,7 +29,6 @@ import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.TableName; @@ -48,9 +46,6 @@ import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; import org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch; import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; -import org.apache.hbase.thirdparty.com.google.common.collect.Sets; -import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; -import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.Threads; @@ -58,6 +53,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hbase.thirdparty.com.google.common.collect.Sets; + +import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; + /** * This is a helper class used internally to manage the namespace metadata that is stored in * TableName.NAMESPACE_TABLE_NAME. It also mirrors updates to the ZK store by forwarding updates to @@ -91,8 +91,7 @@ public class TableNamespaceManager implements Stoppable { } public void start() throws IOException { - if (!MetaTableAccessor.tableExists(masterServices.getConnection(), - TableName.NAMESPACE_TABLE_NAME)) { + if (!masterServices.getTableDescriptors().exists(TableName.NAMESPACE_TABLE_NAME)) { LOG.info("Namespace table not found. Creating..."); createNamespaceTable(masterServices); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineRegionProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineRegionProcedure.java index cf4818ce287a..4558110a3035 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineRegionProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineRegionProcedure.java @@ -19,8 +19,6 @@ package org.apache.hadoop.hbase.master.procedure; import java.io.IOException; - -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.client.RegionInfo; @@ -78,19 +76,6 @@ public void toStringClassDetails(final StringBuilder sb) { sb.append(", region=").append(getRegion().getShortNameToLog()); } - /** - * Check whether a table is modifiable - exists and either offline or online with config set - * @param env MasterProcedureEnv - * @throws IOException - */ - @Override - protected void checkTableModifiable(final MasterProcedureEnv env) throws IOException { - // Checks whether the table exists - if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), getTableName())) { - throw new TableNotFoundException(getTableName()); - } - } - @Override protected boolean holdLock(MasterProcedureEnv env) { return true; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineTableProcedure.java index 3b907f5e1bdb..1edfc74179ae 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AbstractStateMachineTableProcedure.java @@ -20,7 +20,6 @@ import java.io.IOException; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseIOException; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotDisabledException; import org.apache.hadoop.hbase.TableNotEnabledException; @@ -120,11 +119,10 @@ protected void releaseSyncLatch() { /** * Check whether a table is modifiable - exists and either offline or online with config set * @param env MasterProcedureEnv - * @throws IOException */ protected void checkTableModifiable(final MasterProcedureEnv env) throws IOException { // Checks whether the table exists - if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), getTableName())) { + if (!env.getMasterServices().getTableDescriptors().exists(getTableName())) { throw new TableNotFoundException(getTableName()); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CloneSnapshotProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CloneSnapshotProcedure.java index 3b483e6aeb2b..dae7b94134fe 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CloneSnapshotProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CloneSnapshotProcedure.java @@ -27,7 +27,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.TableExistsException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.RegionInfo; @@ -330,12 +329,11 @@ protected void deserializeStateData(ProcedureStateSerializer serializer) /** * Action before any real action of cloning from snapshot. * @param env MasterProcedureEnv - * @throws IOException */ private void prepareClone(final MasterProcedureEnv env) throws IOException { final TableName tableName = getTableName(); - if (MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { - throw new TableExistsException(getTableName()); + if (env.getMasterServices().getTableDescriptors().exists(tableName)) { + throw new TableExistsException(tableName); } } 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 00a127704649..8bef7d1389ed 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 @@ -240,7 +240,7 @@ protected boolean waitInitialized(MasterProcedureEnv env) { private boolean prepareCreate(final MasterProcedureEnv env) throws IOException { final TableName tableName = getTableName(); - if (MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { + if (env.getMasterServices().getTableDescriptors().exists(tableName)) { setFailure("master-create-table", new TableExistsException(getTableName())); return false; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java index a8a2a974bde8..e67327eee2be 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DisableTableProcedure.java @@ -246,7 +246,7 @@ private boolean prepareDisable(final MasterProcedureEnv env) throws IOException setFailure("master-disable-table", new ConstraintException("Cannot disable " + this.tableName)); canTableBeDisabled = false; - } else if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { + } else if (!env.getMasterServices().getTableDescriptors().exists(tableName)) { setFailure("master-disable-table", new TableNotFoundException(tableName)); canTableBeDisabled = false; } else if (!skipTableStateCheck) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java index bcfa33ec47aa..99d5a2749290 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java @@ -281,9 +281,8 @@ public TableOperationType getTableOperationType() { */ private boolean prepareEnable(final MasterProcedureEnv env) throws IOException { boolean canTableBeEnabled = true; - // Check whether table exists - if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { + if (!env.getMasterServices().getTableDescriptors().exists(tableName)) { setFailure("master-enable-table", new TableNotFoundException(tableName)); canTableBeEnabled = false; } else { 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 f90e06b2c200..049fa8a4b3f9 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 @@ -275,7 +275,7 @@ public TableOperationType getTableOperationType() { */ private void prepareModify(final MasterProcedureEnv env) throws IOException { // Checks whether the table exists - if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), getTableName())) { + if (!env.getMasterServices().getTableDescriptors().exists(getTableName())) { throw new TableNotFoundException(getTableName()); } 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 4f6b1a1baed9..06564a99e80a 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 @@ -24,7 +24,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; - import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.DoNotRetryIOException; @@ -54,6 +53,7 @@ import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos; @@ -330,7 +330,7 @@ protected void deserializeStateData(ProcedureStateSerializer serializer) private void prepareRestore(final MasterProcedureEnv env) throws IOException { final TableName tableName = getTableName(); // Checks whether the table exists - if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { + if (!env.getMasterServices().getTableDescriptors().exists(tableName)) { throw new TableNotFoundException(tableName); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/slowlog/SlowLogMasterService.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/slowlog/SlowLogMasterService.java index 554ed88adcca..2a7e5b486081 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/slowlog/SlowLogMasterService.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/slowlog/SlowLogMasterService.java @@ -63,7 +63,7 @@ public void init() throws IOException { LOG.info("Slow/Large requests logging to system table hbase:slowlog is disabled. Quitting."); return; } - if (!MetaTableAccessor.tableExists(masterServices.getConnection(), + if (!masterServices.getTableDescriptors().exists( SlowLogTableAccessor.SLOW_LOG_TABLE_NAME)) { LOG.info("slowlog table not found. Creating."); this.masterServices.createSystemTable(TABLE_DESCRIPTOR_BUILDER.build()); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java index f713718c84ab..46eab4bbd058 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java @@ -42,7 +42,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.TableDescriptor; @@ -851,7 +850,7 @@ public long restoreOrCloneSnapshot(final SnapshotDescription reqSnapshot, final // Execute the restore/clone operation long procId; - if (MetaTableAccessor.tableExists(master.getConnection(), tableName)) { + if (master.getTableDescriptors().exists(tableName)) { procId = restoreSnapshot(reqSnapshot, tableName, snapshot, snapshotTableDesc, nonceKey, restoreAcl); } else { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/namespace/NamespaceAuditor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/namespace/NamespaceAuditor.java index 0a74b093a8d2..a6b13e6b7adb 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/namespace/NamespaceAuditor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/namespace/NamespaceAuditor.java @@ -66,7 +66,7 @@ public void start() throws IOException { public void checkQuotaToCreateTable(TableName tName, int regions) throws IOException { if (stateManager.isInitialized()) { // We do this check to fail fast. - if (MetaTableAccessor.tableExists(this.masterServices.getConnection(), tName)) { + if (masterServices.getTableDescriptors().exists(tName)) { throw new TableExistsException(tName); } stateManager.checkAndUpdateNamespaceTableCount(tName, regions); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java index 28d5053d649b..8d8cf569eddf 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java @@ -28,12 +28,10 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; - import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.DoNotRetryIOException; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.RegionStateListener; import org.apache.hadoop.hbase.TableName; @@ -105,8 +103,7 @@ public void start() throws IOException { } // Create the quota table if missing - if (!MetaTableAccessor.tableExists(masterServices.getConnection(), - QuotaUtil.QUOTA_TABLE_NAME)) { + if (!masterServices.getTableDescriptors().exists(QuotaUtil.QUOTA_TABLE_NAME)) { LOG.info("Quota table not found. Creating..."); createQuotaTable(); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/SpaceQuotaRefresherChore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/SpaceQuotaRefresherChore.java index 94f1bdada02b..e03b48f0a208 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/SpaceQuotaRefresherChore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/SpaceQuotaRefresherChore.java @@ -21,19 +21,18 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; - import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.ScheduledChore; import org.apache.hadoop.hbase.TableName; -import org.apache.yetus.audience.InterfaceAudience; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A {@link ScheduledChore} which periodically updates the {@link RegionServerSpaceQuotaManager} @@ -160,7 +159,9 @@ protected void chore() { * @throws IOException throws IOException */ boolean checkQuotaTableExists() throws IOException { - return MetaTableAccessor.tableExists(getConnection(), QuotaUtil.QUOTA_TABLE_NAME); + try (Admin admin = getConnection().getAdmin()) { + return admin.tableExists(QuotaUtil.QUOTA_TABLE_NAME); + } } /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/SnapshotScannerHDFSAclCleaner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/SnapshotScannerHDFSAclCleaner.java index 6bf4c1fdee3d..8ce4266748c4 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/SnapshotScannerHDFSAclCleaner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/SnapshotScannerHDFSAclCleaner.java @@ -122,6 +122,6 @@ private boolean namespaceExists(String namespace) throws IOException { } private boolean tableExists(TableName tableName) throws IOException { - return master != null && MetaTableAccessor.tableExists(master.getConnection(), tableName); + return master != null && master.getTableDescriptors().exists(tableName); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java index 2a18551ffcd9..01f36348662a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java @@ -18,16 +18,15 @@ package org.apache.hadoop.hbase.security.visibility; -import com.google.protobuf.ByteString; -import com.google.protobuf.RpcCallback; -import com.google.protobuf.RpcController; -import com.google.protobuf.Service; - import static org.apache.hadoop.hbase.HConstants.OperationStatusCode.SANITY_CHECK_FAILURE; import static org.apache.hadoop.hbase.HConstants.OperationStatusCode.SUCCESS; import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_FAMILY; import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_NAME; +import com.google.protobuf.ByteString; +import com.google.protobuf.RpcCallback; +import com.google.protobuf.RpcController; +import com.google.protobuf.Service; import java.io.IOException; import java.net.InetAddress; import java.util.ArrayList; @@ -38,7 +37,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.AuthUtil; import org.apache.hadoop.hbase.Cell; @@ -46,15 +44,13 @@ import org.apache.hadoop.hbase.CoprocessorEnvironment; import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HBaseInterfaceAudience; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.PrivateCellUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.TagType; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Append; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Increment; @@ -64,6 +60,7 @@ import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.TableDescriptor; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.constraint.ConstraintException; import org.apache.hadoop.hbase.coprocessor.CoprocessorException; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; @@ -108,8 +105,6 @@ import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.security.access.AccessChecker; import org.apache.hadoop.hbase.security.access.AccessController; -import org.apache.hbase.thirdparty.com.google.common.collect.Lists; -import org.apache.hbase.thirdparty.com.google.common.collect.MapMaker; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.util.StringUtils; @@ -117,6 +112,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hbase.thirdparty.com.google.common.collect.Lists; +import org.apache.hbase.thirdparty.com.google.common.collect.MapMaker; + /** * Coprocessor that has both the MasterObserver and RegionObserver implemented that supports in * visibility labels @@ -207,21 +205,21 @@ public Iterable getServices() { /********************************* Master related hooks **********************************/ @Override - public void postStartMaster(ObserverContext ctx) throws IOException { + public void postStartMaster(ObserverContext ctx) + throws IOException { // Need to create the new system table for labels here - if (!MetaTableAccessor.tableExists(ctx.getEnvironment().getConnection(), LABELS_TABLE_NAME)) { - HTableDescriptor labelsTable = new HTableDescriptor(LABELS_TABLE_NAME); - HColumnDescriptor labelsColumn = new HColumnDescriptor(LABELS_TABLE_FAMILY); - labelsColumn.setBloomFilterType(BloomType.NONE); - labelsColumn.setBlockCacheEnabled(false); // We will cache all the labels. No need of normal - // table block cache. - labelsTable.addFamily(labelsColumn); - // Let the "labels" table having only one region always. We are not expecting too many labels in - // the system. - labelsTable.setValue(HTableDescriptor.SPLIT_POLICY, - DisabledRegionSplitPolicy.class.getName()); - try (Admin admin = ctx.getEnvironment().getConnection().getAdmin()) { - admin.createTable(labelsTable); + try (Admin admin = ctx.getEnvironment().getConnection().getAdmin()) { + if (!admin.tableExists(LABELS_TABLE_NAME)) { + // We will cache all the labels. No need of normal table block cache. + // Let the "labels" table having only one region always. We are not expecting too many + // labels in the system. + TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(LABELS_TABLE_NAME) + .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(LABELS_TABLE_FAMILY) + .setBloomFilterType(BloomType.NONE).setBlockCacheEnabled(false).build()) + .setValue(TableDescriptorBuilder.SPLIT_POLICY, DisabledRegionSplitPolicy.class.getName()) + .build(); + + admin.createTable(tableDescriptor); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java index d6782faf3603..20e0edd4ebbb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java @@ -19,7 +19,6 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -328,25 +327,8 @@ public void testGetRegionsFromMetaTable() throws IOException, InterruptedExcepti MetaTableLocator.getMetaRegionsAndLocations(UTIL.getZooKeeperWatcher()).size() >= 1); } - @Test public void testTableExists() throws IOException { - final TableName tableName = TableName.valueOf(name.getMethodName()); - assertFalse(MetaTableAccessor.tableExists(connection, tableName)); - UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); - assertTrue(MetaTableAccessor.tableExists(connection, tableName)); - Admin admin = UTIL.getAdmin(); - admin.disableTable(tableName); - admin.deleteTable(tableName); - assertFalse(MetaTableAccessor.tableExists(connection, tableName)); - assertTrue(MetaTableAccessor.tableExists(connection, - TableName.META_TABLE_NAME)); - UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); - assertTrue(MetaTableAccessor.tableExists(connection, tableName)); - admin.disableTable(tableName); - admin.deleteTable(tableName); - assertFalse(MetaTableAccessor.tableExists(connection, tableName)); - } - - @Test public void testGetRegion() throws IOException, InterruptedException { + @Test + public void testGetRegion() throws IOException, InterruptedException { final String name = this.name.getMethodName(); LOG.info("Started " + name); // Test get on non-existent region. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureTestingUtility.java index c60a60459015..21989ef9037e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureTestingUtility.java @@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.RegionLocations; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.BufferedMutator; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -211,7 +212,7 @@ public static void validateTableCreation(final HMaster master, final TableName t LOG.debug("Table directory layout is as expected."); // check meta - assertTrue(MetaTableAccessor.tableExists(master.getConnection(), tableName)); + assertTrue(tableExists(master.getConnection(), tableName)); assertEquals(regions.length, countMetaRegions(master, tableName)); // check htd @@ -232,7 +233,7 @@ public static void validateTableDeletion( assertFalse(fs.exists(tableDir)); // check meta - assertFalse(MetaTableAccessor.tableExists(master.getConnection(), tableName)); + assertFalse(tableExists(master.getConnection(), tableName)); assertEquals(0, countMetaRegions(master, tableName)); // check htd @@ -577,6 +578,12 @@ public static void testRestartWithAbort(ProcedureExecutor pr } } + public static boolean tableExists(Connection conn, TableName tableName) throws IOException { + try (Admin admin = conn.getAdmin()) { + return admin.tableExists(tableName); + } + } + public static class InjectAbortOnLoadListener implements ProcedureExecutor.ProcedureExecutorListener { private final ProcedureExecutor procExec; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/namequeues/TestSlowLogAccessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/namequeues/TestSlowLogAccessor.java index a91479659795..4ebf2a5aed3b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/namequeues/TestSlowLogAccessor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/namequeues/TestSlowLogAccessor.java @@ -28,7 +28,6 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; @@ -37,12 +36,9 @@ import org.apache.hadoop.hbase.namequeues.request.NamedQueueGetRequest; import org.apache.hadoop.hbase.namequeues.response.NamedQueueGetResponse; import org.apache.hadoop.hbase.regionserver.HRegionServer; -import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos; -import org.apache.hadoop.hbase.shaded.protobuf.generated.TooSlowLog; import org.apache.hadoop.hbase.slowlog.SlowLogTableAccessor; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.apache.hbase.thirdparty.com.google.common.util.concurrent.Uninterruptibles; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -53,6 +49,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hbase.thirdparty.com.google.common.util.concurrent.Uninterruptibles; + +import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos; +import org.apache.hadoop.hbase.shaded.protobuf.generated.TooSlowLog; + /** * Tests for SlowLog System Table */ @@ -167,17 +168,16 @@ private int getTableCount(Connection connection) { } } - private Connection waitForSlowLogTableCreation() { - Connection connection = - HBASE_TESTING_UTILITY.getMiniHBaseCluster().getRegionServer(0).getConnection(); + private Connection waitForSlowLogTableCreation() throws IOException { Assert.assertNotEquals(-1, HBASE_TESTING_UTILITY.waitFor(2000, () -> { try { - return MetaTableAccessor.tableExists(connection, SlowLogTableAccessor.SLOW_LOG_TABLE_NAME); + return HBASE_TESTING_UTILITY.getAdmin() + .tableExists(SlowLogTableAccessor.SLOW_LOG_TABLE_NAME); } catch (IOException e) { return false; } })); - return connection; + return HBASE_TESTING_UTILITY.getConnection(); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaObserverChoreRegionReports.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaObserverChoreRegionReports.java index 0e143ef55213..4ca6e1458e58 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaObserverChoreRegionReports.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaObserverChoreRegionReports.java @@ -19,17 +19,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; + import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.concurrent.TimeUnit; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.Admin; @@ -43,7 +42,6 @@ import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.master.HMaster; -import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.util.Bytes; import org.junit.After; @@ -96,9 +94,9 @@ public void testReportExpiration() throws Exception { TEST_UTIL.startMiniCluster(1); // Wait till quota table onlined. TEST_UTIL.waitFor(10000, new Waiter.Predicate() { - @Override public boolean evaluate() throws Exception { - return MetaTableAccessor.tableExists(TEST_UTIL.getConnection(), - QuotaTableUtil.QUOTA_TABLE_NAME); + @Override + public boolean evaluate() throws Exception { + return TEST_UTIL.getAdmin().tableExists(QuotaTableUtil.QUOTA_TABLE_NAME); } }); @@ -155,9 +153,9 @@ public void testMissingReportsRemovesQuota() throws Exception { TEST_UTIL.startMiniCluster(1); // Wait till quota table onlined. TEST_UTIL.waitFor(10000, new Waiter.Predicate() { - @Override public boolean evaluate() throws Exception { - return MetaTableAccessor.tableExists(TEST_UTIL.getConnection(), - QuotaTableUtil.QUOTA_TABLE_NAME); + @Override + public boolean evaluate() throws Exception { + return TEST_UTIL.getAdmin().tableExists(QuotaTableUtil.QUOTA_TABLE_NAME); } }); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotasWithSnapshots.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotasWithSnapshots.java index 22e98c7b1c8d..d681d2d01870 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotasWithSnapshots.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotasWithSnapshots.java @@ -30,7 +30,6 @@ import org.apache.hadoop.hbase.CellScanner; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.Waiter.Predicate; @@ -88,9 +87,9 @@ public static void setUp() throws Exception { TEST_UTIL.startMiniCluster(1); // Wait till quota table onlined. TEST_UTIL.waitFor(10000, new Waiter.Predicate() { - @Override public boolean evaluate() throws Exception { - return MetaTableAccessor.tableExists(TEST_UTIL.getConnection(), - QuotaTableUtil.QUOTA_TABLE_NAME); + @Override + public boolean evaluate() throws Exception { + return TEST_UTIL.getAdmin().tableExists(QuotaTableUtil.QUOTA_TABLE_NAME); } }); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java index b6f86fa7f785..ff99cda4d6bb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java @@ -50,7 +50,6 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.MasterNotRunningException; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.StartMiniClusterOption; @@ -670,8 +669,7 @@ public void testSplitWithRegionReplicas() throws Exception { admin.balancerSwitch(false, true); // Turn off the meta scanner so it don't remove parent on us. cluster.getMaster().setCatalogJanitorEnabled(false); - boolean tableExists = MetaTableAccessor.tableExists(regionServer.getConnection(), - tableName); + boolean tableExists = TESTING_UTIL.getAdmin().tableExists(tableName); assertEquals("The specified table should be present.", true, tableExists); final HRegion region = findSplittableRegion(oldRegions); regionServerIndex = cluster.getServerWith(region.getRegionInfo().getRegionName()); @@ -691,8 +689,7 @@ public void testSplitWithRegionReplicas() throws Exception { Thread.sleep(1000); } while ((newRegions.contains(oldRegions.get(0)) || newRegions.contains(oldRegions.get(1))) || newRegions.size() != 4); - tableExists = MetaTableAccessor.tableExists(regionServer.getConnection(), - tableName); + tableExists = TESTING_UTIL.getAdmin().tableExists(tableName); assertEquals("The specified table should be present.", true, tableExists); // exists works on stale and we see the put after the flush byte[] b1 = "row1".getBytes();