From 50708d9524c7575324bf277c8ca0d3d711eb46be Mon Sep 17 00:00:00 2001 From: Stephen Yuan Jiang Date: Tue, 23 May 2017 13:10:07 -0700 Subject: [PATCH] HBASE-18093 Overloading the meaning of 'enabled' in Quota Manager to indicate either quota disabled or quota manager not ready is not good (Stephen Yuan Jiang) --- .../master/snapshot/SnapshotManager.java | 6 +-- .../hbase/quotas/MasterQuotaManager.java | 45 +++++++++++++------ .../hbase/namespace/TestNamespaceAuditor.java | 6 +-- 3 files changed, 37 insertions(+), 20 deletions(-) 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 9c5057119a6..4e0181f7663 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 @@ -795,7 +795,7 @@ public class SnapshotManager extends MasterProcedureManager implements Stoppable private void checkAndUpdateNamespaceQuota(SnapshotManifest manifest, TableName tableName) throws IOException { - if (this.master.getMasterQuotaManager().isQuotaEnabled()) { + if (this.master.getMasterQuotaManager().isQuotaInitialized()) { this.master.getMasterQuotaManager().checkNamespaceTableAndRegionQuota(tableName, manifest.getRegionManifestsMap().size()); } @@ -803,7 +803,7 @@ public class SnapshotManager extends MasterProcedureManager implements Stoppable private void checkAndUpdateNamespaceRegionQuota(int updatedRegionCount, TableName tableName) throws IOException { - if (this.master.getMasterQuotaManager().isQuotaEnabled()) { + if (this.master.getMasterQuotaManager().isQuotaInitialized()) { this.master.getMasterQuotaManager().checkAndUpdateNamespaceRegionQuota(tableName, updatedRegionCount); } @@ -813,7 +813,7 @@ public class SnapshotManager extends MasterProcedureManager implements Stoppable * @return cached region count, or -1 if quota manager is disabled or table status not found */ private int getRegionCountOfTable(TableName tableName) throws IOException { - if (this.master.getMasterQuotaManager().isQuotaEnabled()) { + if (this.master.getMasterQuotaManager().isQuotaInitialized()) { return this.master.getMasterQuotaManager().getRegionCountOfTable(tableName); } return -1; 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 5237393188e..9bfa8dbf520 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 @@ -34,6 +34,7 @@ import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.Quotas; import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.Throttle; import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.ThrottleRequest; import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.TimedQuota; +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; /** * Master Quota Manager. It is responsible for initialize the quota table on the first-run and @@ -50,7 +51,7 @@ public class MasterQuotaManager implements RegionStateListener { private NamedLock namespaceLocks; private NamedLock tableLocks; private NamedLock userLocks; - private boolean enabled = false; + private boolean initialized = false; private NamespaceAuditor namespaceQuotaManager; public MasterQuotaManager(final MasterServices masterServices) { @@ -78,14 +79,14 @@ public class MasterQuotaManager implements RegionStateListener { namespaceQuotaManager = new NamespaceAuditor(masterServices); namespaceQuotaManager.start(); - enabled = true; + initialized = true; } public void stop() { } - public boolean isQuotaEnabled() { - return enabled && namespaceQuotaManager.isInitialized(); + public boolean isQuotaInitialized() { + return initialized && namespaceQuotaManager.isInitialized(); } /* @@ -283,13 +284,13 @@ public class MasterQuotaManager implements RegionStateListener { } public void setNamespaceQuota(NamespaceDescriptor desc) throws IOException { - if (enabled) { + if (initialized) { this.namespaceQuotaManager.addNamespace(desc); } } public void removeNamespaceQuota(String namespace) throws IOException { - if (enabled) { + if (initialized) { this.namespaceQuotaManager.deleteNamespace(namespace); } } @@ -322,13 +323,13 @@ public class MasterQuotaManager implements RegionStateListener { } public void checkNamespaceTableAndRegionQuota(TableName tName, int regions) throws IOException { - if (enabled) { + if (initialized) { namespaceQuotaManager.checkQuotaToCreateTable(tName, regions); } } public void checkAndUpdateNamespaceRegionQuota(TableName tName, int regions) throws IOException { - if (enabled) { + if (initialized) { namespaceQuotaManager.checkQuotaToUpdateRegion(tName, regions); } } @@ -337,20 +338,20 @@ public class MasterQuotaManager implements RegionStateListener { * @return cached region count, or -1 if quota manager is disabled or table status not found */ public int getRegionCountOfTable(TableName tName) throws IOException { - if (enabled) { + if (initialized) { return namespaceQuotaManager.getRegionCountOfTable(tName); } return -1; } public void onRegionMerged(HRegionInfo hri) throws IOException { - if (enabled) { + if (initialized) { namespaceQuotaManager.updateQuotaForRegionMerge(hri); } } public void onRegionSplit(HRegionInfo hri) throws IOException { - if (enabled) { + if (initialized) { namespaceQuotaManager.checkQuotaToSplitRegion(hri); } } @@ -361,7 +362,7 @@ public class MasterQuotaManager implements RegionStateListener { * @throws IOException Signals that an I/O exception has occurred. */ public void removeTableFromNamespaceQuota(TableName tName) throws IOException { - if (enabled) { + if (initialized) { namespaceQuotaManager.removeFromNamespaceUsage(tName); } } @@ -471,9 +472,25 @@ public class MasterQuotaManager implements RegionStateListener { */ private void checkQuotaSupport() throws IOException { - if (!enabled) { + if (!QuotaUtil.isQuotaEnabled(masterServices.getConfiguration())) { throw new DoNotRetryIOException(new UnsupportedOperationException("quota support disabled")); } + if (!initialized) { + long maxWaitTime = masterServices.getConfiguration().getLong( + "hbase.master.wait.for.quota.manager.init", 30000); // default is 30 seconds. + long startTime = EnvironmentEdgeManager.currentTime(); + do { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + LOG.warn("Interrupted while waiting for Quota Manager to be initialized."); + break; + } + } while (!initialized && (EnvironmentEdgeManager.currentTime() - startTime) < maxWaitTime); + if (!initialized) { + throw new IOException("Quota manager is uninitialized, please retry later."); + } + } } private void createQuotaTable() throws IOException { @@ -502,7 +519,7 @@ public class MasterQuotaManager implements RegionStateListener { @Override public void onRegionSplitReverted(HRegionInfo hri) throws IOException { - if (enabled) { + if (initialized) { this.namespaceQuotaManager.removeRegionFromNamespaceUsage(hri); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java index a8406856fdf..f5efa3455bd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java @@ -130,8 +130,8 @@ public class TestNamespaceAuditor { ADMIN.deleteNamespace(ns.getName()); } } - assertTrue("Quota manager not enabled", UTIL.getHBaseCluster().getMaster() - .getMasterQuotaManager().isQuotaEnabled()); + assertTrue("Quota manager not initialized", UTIL.getHBaseCluster().getMaster() + .getMasterQuotaManager().isQuotaInitialized()); } @Test @@ -632,7 +632,7 @@ public class TestNamespaceAuditor { return false; } MasterQuotaManager quotaManager = master.getMasterQuotaManager(); - return quotaManager != null && quotaManager.isQuotaEnabled(); + return quotaManager != null && quotaManager.isQuotaInitialized(); } }); }