From 22972f0879f3dc09404d97f2318ac06a2acf8d96 Mon Sep 17 00:00:00 2001 From: meiyi Date: Thu, 17 Jan 2019 17:48:30 +0800 Subject: [PATCH] HBASE-21733 SnapshotQuotaObserverChore should only fetch space quotas --- .../hbase/quotas/SnapshotQuotaObserverChore.java | 24 ++++++++++++---------- .../quotas/TestSnapshotQuotaObserverChore.java | 8 ++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) 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 9dd2ac0..7649360 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 @@ -131,17 +131,19 @@ public class SnapshotQuotaObserverChore extends ScheduledChore { try (Admin admin = conn.getAdmin()) { // Pull all of the tables that have quotas (direct, or from namespace) for (QuotaSettings qs : QuotaRetriever.open(conf, filter)) { - String ns = qs.getNamespace(); - TableName tn = qs.getTableName(); - if ((null == ns && null == tn) || (null != ns && null != tn)) { - throw new IllegalStateException( - "Expected only one of namespace and tablename to be null"); - } - // Collect either the table name itself, or all of the tables in the namespace - if (null != ns) { - tablesToFetchSnapshotsFrom.addAll(Arrays.asList(admin.listTableNamesByNamespace(ns))); - } else { - tablesToFetchSnapshotsFrom.add(tn); + if (qs.getQuotaType() == QuotaType.SPACE) { + String ns = qs.getNamespace(); + TableName tn = qs.getTableName(); + if ((null == ns && null == tn) || (null != ns && null != tn)) { + throw new IllegalStateException( + "Expected only one of namespace and tablename to be null"); + } + // Collect either the table name itself, or all of the tables in the namespace + if (null != ns) { + tablesToFetchSnapshotsFrom.addAll(Arrays.asList(admin.listTableNamesByNamespace(ns))); + } else { + tablesToFetchSnapshotsFrom.add(tn); + } } } // Fetch all snapshots that were created from these tables 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 097e646..ea7337d 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 @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -160,6 +161,13 @@ public class TestSnapshotQuotaObserverChore { TableName tn2 = helper.createTableWithRegions(ns.getName(), 1); TableName tn3 = helper.createTableWithRegions(1); + // Set a throttle quota on 'default' namespace + admin.setQuota(QuotaSettingsFactory.throttleNamespace(tn3.getNamespaceAsString(), + ThrottleType.WRITE_NUMBER, 99999, TimeUnit.SECONDS)); + // Set a user throttle quota + admin.setQuota( + QuotaSettingsFactory.throttleUser("user", ThrottleType.WRITE_NUMBER, 100, TimeUnit.MINUTES)); + // Set a space quota on the namespace admin.setQuota(QuotaSettingsFactory.limitNamespaceSpace( ns.getName(), SpaceQuotaHelperForTests.ONE_GIGABYTE, SpaceViolationPolicy.NO_INSERTS)); -- 2.7.4