From ffbf8503eaf171e4614f32f9d9a3c575e5edb85f Mon Sep 17 00:00:00 2001 From: shardul-cr7 Date: Thu, 29 Aug 2019 11:41:04 +0530 Subject: [PATCH] HBASE-22944 Check for hbase:quota table existence in SpaceQuotaRefresherChore During startup, it's possible that quotas are enabled but the Master has not yet created the hbase:quotas table. Closes #559 Signed-off-by: stack Signed-off-by: Josh Elser --- .../quotas/SpaceQuotaRefresherChore.java | 19 +++++++++++++++++++ ...aceQuotaViolationPolicyRefresherChore.java | 1 + 2 files changed, 20 insertions(+) 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 7ae7240f3c4..94f1bdada02 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 @@ -23,6 +23,7 @@ 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; @@ -60,6 +61,7 @@ public class SpaceQuotaRefresherChore extends ScheduledChore { private final RegionServerSpaceQuotaManager manager; private final Connection conn; + private boolean quotaTablePresent = false; public SpaceQuotaRefresherChore(RegionServerSpaceQuotaManager manager, Connection conn) { super(SpaceQuotaRefresherChore.class.getSimpleName(), @@ -74,6 +76,13 @@ public class SpaceQuotaRefresherChore extends ScheduledChore { @Override protected void chore() { try { + // check whether quotaTable is present or not. + if (!quotaTablePresent && !checkQuotaTableExists()) { + LOG.info("Quota table not found, skipping quota manager cache refresh."); + return; + } + // since quotaTable is present so setting the flag as true. + quotaTablePresent = true; if (LOG.isTraceEnabled()) { LOG.trace("Reading current quota snapshots from hbase:quota."); } @@ -144,6 +153,16 @@ public class SpaceQuotaRefresherChore extends ScheduledChore { } } + /** + * Checks if hbase:quota exists in hbase:meta + * + * @return true if hbase:quota table is in meta, else returns false. + * @throws IOException throws IOException + */ + boolean checkQuotaTableExists() throws IOException { + return MetaTableAccessor.tableExists(getConnection(), QuotaUtil.QUOTA_TABLE_NAME); + } + /** * Checks if the given snapshot is in violation, allowing the snapshot to be null. * If the snapshot is null, this is interpreted as no snapshot which implies not in violation. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotaViolationPolicyRefresherChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotaViolationPolicyRefresherChore.java index 58270c344d3..aa871f12394 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotaViolationPolicyRefresherChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotaViolationPolicyRefresherChore.java @@ -82,6 +82,7 @@ public class TestSpaceQuotaViolationPolicyRefresherChore { chore = mock(SpaceQuotaRefresherChore.class); when(chore.getConnection()).thenReturn(conn); when(chore.getManager()).thenReturn(manager); + when(chore.checkQuotaTableExists()).thenReturn(true); doCallRealMethod().when(chore).chore(); when(chore.isInViolation(any())).thenCallRealMethod(); doCallRealMethod().when(chore).extractQuotaSnapshot(any(), any());