hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From syuanji...@apache.org
Subject hbase git commit: 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)
Date Tue, 23 May 2017 20:10:18 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 8c313d5be -> 50708d952


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)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/50708d95
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/50708d95
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/50708d95

Branch: refs/heads/branch-1
Commit: 50708d9524c7575324bf277c8ca0d3d711eb46be
Parents: 8c313d5
Author: Stephen Yuan Jiang <syuanjiangdev@gmail.com>
Authored: Tue May 23 13:10:07 2017 -0700
Committer: Stephen Yuan Jiang <syuanjiangdev@gmail.com>
Committed: Tue May 23 13:10:07 2017 -0700

----------------------------------------------------------------------
 .../hbase/master/snapshot/SnapshotManager.java  |  6 +--
 .../hadoop/hbase/quotas/MasterQuotaManager.java | 45 ++++++++++++++------
 .../hbase/namespace/TestNamespaceAuditor.java   |  6 +--
 3 files changed, 37 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/50708d95/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java
----------------------------------------------------------------------
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 9c50571..4e0181f 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;

http://git-wip-us.apache.org/repos/asf/hbase/blob/50708d95/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java
----------------------------------------------------------------------
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 5237393..9bfa8db 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<String> namespaceLocks;
   private NamedLock<TableName> tableLocks;
   private NamedLock<String> 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);
     }
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/50708d95/hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java
----------------------------------------------------------------------
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 a840685..f5efa34 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();
       }
     });
   }


Mime
View raw message