From a82ec6562a7be8458c70f411a6fd97011dd37f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E5=B8=AE?= Date: Wed, 27 Mar 2019 17:47:49 +0800 Subject: [PATCH] HBASE-21455 Update filesystem-space quota fail if there is a space quota for non-existing namespace --- .../hbase/quotas/QuotaObserverChore.java | 7 ++++-- .../apache/hadoop/hbase/quotas/QuotaUtil.java | 19 +++++++++++++++ .../quotas/SnapshotQuotaObserverChore.java | 6 ++++- ...TestQuotaObserverChoreWithMiniCluster.java | 24 +++++++++++++++++++ .../TestSnapshotQuotaObserverChore.java | 4 ++++ 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaObserverChore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaObserverChore.java index 92a149c070..d421c8d8fd 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaObserverChore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaObserverChore.java @@ -498,8 +498,11 @@ public class QuotaObserverChore extends ScheduledChore { if (namespace != null) { assert tableName == null; - // Collect all of the tables in the namespace - TableName[] tablesInNS = conn.getAdmin().listTableNamesByNamespace(namespace); + // Collect all of the tables in the namespace,if this namespace doesn't exist,skip it + TableName[] tablesInNS = QuotaUtil.listTableNamesByNamespace(conn, namespace); + if(null == tablesInNS){ + continue; + } for (TableName tableUnderNs : tablesInNS) { if (LOG.isTraceEnabled()) { LOG.trace("Adding " + tableUnderNs + " under " + namespace diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaUtil.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaUtil.java index 9053405b13..01a56ae3a6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaUtil.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaUtil.java @@ -30,6 +30,7 @@ import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.NamespaceNotFoundException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotDisabledException; import org.apache.hadoop.hbase.TableNotEnabledException; @@ -534,4 +535,22 @@ public class QuotaUtil extends QuotaTableUtil { // ignore } } + + /** + * Method to list all of the table names in the namespace + * {@link NamespaceNotFoundException},skip non-exist namespace + * @param conn connection to re-use + * @param namespace name of namespace + */ + public static TableName[] listTableNamesByNamespace(Connection conn, String namespace) + throws IOException { + TableName[] tablesInNS = null; + try { + tablesInNS = conn.getAdmin().listTableNamesByNamespace(namespace); + } catch (NamespaceNotFoundException e) { + LOG.warn("NameSpace " + namespace + " doesn't exist,skip it"); + } + return tablesInNS; + } + } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/SnapshotQuotaObserverChore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/SnapshotQuotaObserverChore.java index f74bae0c51..76101bae6d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/SnapshotQuotaObserverChore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/SnapshotQuotaObserverChore.java @@ -140,7 +140,11 @@ public class SnapshotQuotaObserverChore extends ScheduledChore { } // Collect either the table name itself, or all of the tables in the namespace if (null != ns) { - tablesToFetchSnapshotsFrom.addAll(Arrays.asList(admin.listTableNamesByNamespace(ns))); + TableName[] tablesInNS = QuotaUtil.listTableNamesByNamespace(conn, ns); + if(null == tablesInNS){ + continue; + } + tablesToFetchSnapshotsFrom.addAll(Arrays.asList(tablesInNS)); } else { tablesToFetchSnapshotsFrom.add(tn); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaObserverChoreWithMiniCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaObserverChoreWithMiniCluster.java index 708ac965f5..3a44621416 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaObserverChoreWithMiniCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaObserverChoreWithMiniCluster.java @@ -349,6 +349,30 @@ public class TestQuotaObserverChoreWithMiniCluster { assertEquals("Found tables: " + tables, namespaceTablesWithQuotas, tables.getNamespaceQuotaTables()); } + @Test + public void testGetAllTablesWithQuotasWithNonExistNamepsace() throws Exception { + final Multimap quotas = helper.createTablesWithSpaceQuotas(); + Set tablesWithQuotas = new HashSet<>(); + Set namespaceTablesWithQuotas = new HashSet<>(); + // Partition the tables with quotas by table and ns quota + helper.partitionTablesByQuotaTarget(quotas, tablesWithQuotas, namespaceTablesWithQuotas); + + //test with an namespace not exist + final String namespace = testName.getMethodName(); + final Admin admin = TEST_UTIL.getAdmin(); + final long namespaceSizeLimit = 3L * SpaceQuotaHelperForTests.ONE_MEGABYTE; + final SpaceViolationPolicy namespaceViolationPolicy = SpaceViolationPolicy.DISABLE; + QuotaSettings namespaceSettings = QuotaSettingsFactory.limitNamespaceSpace(namespace, + namespaceSizeLimit, namespaceViolationPolicy); + admin.setQuota(namespaceSettings); + + TablesWithQuotas tables = chore.fetchAllTablesWithQuotasDefined(); + assertEquals("Found tables: " + + tables, tablesWithQuotas, tables.getTableQuotaTables()); + assertEquals("Found tables: " + + tables, namespaceTablesWithQuotas, tables.getNamespaceQuotaTables()); + } + @Test public void testRpcQuotaTablesAreFiltered() throws Exception { final Multimap quotas = helper.createTablesWithSpaceQuotas(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSnapshotQuotaObserverChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSnapshotQuotaObserverChore.java index bddfe261a1..7ac129013c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSnapshotQuotaObserverChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSnapshotQuotaObserverChore.java @@ -173,6 +173,10 @@ public class TestSnapshotQuotaObserverChore { admin.setQuota(QuotaSettingsFactory.limitNamespaceSpace( ns.getName(), SpaceQuotaHelperForTests.ONE_GIGABYTE, SpaceViolationPolicy.NO_INSERTS)); + //Set a space quota on non-exist namespace + admin.setQuota(QuotaSettingsFactory.limitNamespaceSpace(testName.getMethodName(), + SpaceQuotaHelperForTests.ONE_GIGABYTE, SpaceViolationPolicy.NO_INSERTS)); + // Create snapshots on each table (we didn't write any data, so just skipflush) admin.snapshot(new SnapshotDescription( tn1.getQualifierAsString() + "snapshot", tn1, SnapshotType.SKIPFLUSH)); -- 2.17.2 (Apple Git-113)