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)

This commit is contained in:
Stephen Yuan Jiang 2017-05-23 13:10:07 -07:00
parent 8c313d5be4
commit 50708d9524
3 changed files with 37 additions and 20 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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();
}
});
}