From aa92f6539aa606316bd75669b4566ae2b7c7ab7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E5=B8=AE?= Date: Tue, 26 Mar 2019 11:26:54 +0800 Subject: [PATCH] HBASE-21455 Update filesystem-space quota fail if there is a space quota for non-existing namespace --- .../hbase/quotas/QuotaObserverChore.java | 11 ++++++++-- .../quotas/SnapshotQuotaObserverChore.java | 10 ++++++++- ...TestQuotaObserverChoreWithMiniCluster.java | 22 +++++++++++++++++++ .../TestSnapshotQuotaObserverChore.java | 4 ++++ 4 files changed, 44 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..f0fc94d89e 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 @@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.NamespaceNotFoundException; import org.apache.hadoop.hbase.ScheduledChore; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.TableName; @@ -498,8 +499,14 @@ 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; + try { + tablesInNS = conn.getAdmin().listTableNamesByNamespace(namespace); + } catch (NamespaceNotFoundException e) { + LOG.warn("NameSpace " + namespace + " doesn't exist,skip it"); + 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/SnapshotQuotaObserverChore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/SnapshotQuotaObserverChore.java index f74bae0c51..32cf29b81b 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 @@ -29,6 +29,7 @@ import java.util.stream.Collectors; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.hbase.NamespaceNotFoundException; import org.apache.hadoop.hbase.ScheduledChore; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.TableName; @@ -140,7 +141,14 @@ 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; + try { + tablesInNS = conn.getAdmin().listTableNamesByNamespace(ns); + } catch (NamespaceNotFoundException e) { + LOG.warn("NameSpace " + ns + " doesn't exist,skip it"); + 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..7408331f0a 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,28 @@ 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..5a378084f3 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)