diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java index 5dab2e3..4038761 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java @@ -40,6 +40,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas; import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Throttle; import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.ThrottleRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.TimedQuota; +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; /** * Master Quota Manager. @@ -58,7 +59,7 @@ public class MasterQuotaManager implements RegionStateListener { private NamedLock namespaceLocks; private NamedLock tableLocks; private NamedLock userLocks; - private boolean enabled = false; + private boolean initalized = false; private NamespaceAuditor namespaceQuotaManager; public MasterQuotaManager(final MasterServices masterServices) { @@ -86,14 +87,14 @@ public class MasterQuotaManager implements RegionStateListener { namespaceQuotaManager = new NamespaceAuditor(masterServices); namespaceQuotaManager.start(); - enabled = true; + initalized = true; } public void stop() { } - public boolean isQuotaEnabled() { - return enabled && namespaceQuotaManager.isInitialized(); + public boolean isQuotaInitialized() { + return initalized && namespaceQuotaManager.isInitialized(); } /* ========================================================================== @@ -269,13 +270,13 @@ public class MasterQuotaManager implements RegionStateListener { } public void setNamespaceQuota(NamespaceDescriptor desc) throws IOException { - if (enabled) { + if (initalized) { this.namespaceQuotaManager.addNamespace(desc); } } public void removeNamespaceQuota(String namespace) throws IOException { - if (enabled) { + if (initalized) { this.namespaceQuotaManager.deleteNamespace(namespace); } } @@ -308,13 +309,13 @@ public class MasterQuotaManager implements RegionStateListener { } public void checkNamespaceTableAndRegionQuota(TableName tName, int regions) throws IOException { - if (enabled) { + if (initalized) { namespaceQuotaManager.checkQuotaToCreateTable(tName, regions); } } public void checkAndUpdateNamespaceRegionQuota(TableName tName, int regions) throws IOException { - if (enabled) { + if (initalized) { namespaceQuotaManager.checkQuotaToUpdateRegion(tName, regions); } } @@ -323,20 +324,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 (initalized) { return namespaceQuotaManager.getRegionCountOfTable(tName); } return -1; } public void onRegionMerged(HRegionInfo hri) throws IOException { - if (enabled) { + if (initalized) { namespaceQuotaManager.updateQuotaForRegionMerge(hri); } } public void onRegionSplit(HRegionInfo hri) throws IOException { - if (enabled) { + if (initalized) { namespaceQuotaManager.checkQuotaToSplitRegion(hri); } } @@ -348,7 +349,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 (initalized) { namespaceQuotaManager.removeFromNamespaceUsage(tName); } } @@ -449,10 +450,26 @@ 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 (!initalized) { + 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 (!initalized && (EnvironmentEdgeManager.currentTime() - startTime) < maxWaitTime); + if (!initalized) { + throw new IOException("Quota manager is uninitalized, please retry later."); + } + } } private void createQuotaTable() throws IOException { @@ -481,7 +498,7 @@ public class MasterQuotaManager implements RegionStateListener { @Override public void onRegionSplitReverted(HRegionInfo hri) throws IOException { - if (enabled) { + if (initalized) { this.namespaceQuotaManager.removeRegionFromNamespaceUsage(hri); } } diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java index 70a78de..586f93e 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java @@ -76,7 +76,7 @@ public class TestSimpleRegionNormalizerOnCluster { // Start a cluster of two regionservers. TEST_UTIL.startMiniCluster(1); - TestNamespaceAuditor.waitForQuotaEnabled(TEST_UTIL); + TestNamespaceAuditor.waitForQuotaInitialize(TEST_UTIL); admin = TEST_UTIL.getAdmin(); } diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java index cc79915..2fb4741 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java @@ -112,7 +112,7 @@ public class TestNamespaceAuditor { conf.setClass("hbase.coprocessor.regionserver.classes", CPRegionServerObserver.class, RegionServerObserver.class); UTIL.startMiniCluster(1, 1); - waitForQuotaEnabled(UTIL); + waitForQuotaInitialize(UTIL); ADMIN = UTIL.getAdmin(); } @@ -132,8 +132,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 @@ -649,7 +649,7 @@ public class TestNamespaceAuditor { .getTables().size(), after.getTables().size()); } - public static void waitForQuotaEnabled(final HBaseTestingUtility util) throws Exception { + public static void waitForQuotaInitialize(final HBaseTestingUtility util) throws Exception { util.waitFor(60000, new Waiter.Predicate() { @Override public boolean evaluate() throws Exception { @@ -658,7 +658,7 @@ public class TestNamespaceAuditor { return false; } MasterQuotaManager quotaManager = master.getMasterQuotaManager(); - return quotaManager != null && quotaManager.isQuotaEnabled(); + return quotaManager != null && quotaManager.isQuotaInitialized(); } }); } @@ -667,7 +667,7 @@ public class TestNamespaceAuditor { UTIL.getHBaseCluster().getMaster(0).stop("Stopping to start again"); UTIL.getHBaseCluster().waitOnMaster(0); UTIL.getHBaseCluster().startMaster(); - waitForQuotaEnabled(UTIL); + waitForQuotaInitialize(UTIL); } private NamespaceAuditor getQuotaManager() {