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:
parent
3f75ba195c
commit
1d0295f4e2
|
@ -2247,7 +2247,7 @@ public class HMaster extends HRegionServer implements MasterServices {
|
||||||
// coprocessor.
|
// coprocessor.
|
||||||
MasterQuotaManager quotaManager = getMasterQuotaManager();
|
MasterQuotaManager quotaManager = getMasterQuotaManager();
|
||||||
if (quotaManager != null) {
|
if (quotaManager != null) {
|
||||||
if (quotaManager.isQuotaEnabled()) {
|
if (quotaManager.isQuotaInitialized()) {
|
||||||
Quotas quotaForTable = QuotaUtil.getTableQuota(getConnection(), tableName);
|
Quotas quotaForTable = QuotaUtil.getTableQuota(getConnection(), tableName);
|
||||||
if (quotaForTable != null && quotaForTable.hasSpace()) {
|
if (quotaForTable != null && quotaForTable.hasSpace()) {
|
||||||
SpaceViolationPolicy policy = quotaForTable.getSpace().getViolationPolicy();
|
SpaceViolationPolicy policy = quotaForTable.getSpace().getViolationPolicy();
|
||||||
|
|
|
@ -49,6 +49,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Throttle;
|
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.ThrottleRequest;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.TimedQuota;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.TimedQuota;
|
||||||
|
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ public class MasterQuotaManager implements RegionStateListener {
|
||||||
private NamedLock<String> namespaceLocks;
|
private NamedLock<String> namespaceLocks;
|
||||||
private NamedLock<TableName> tableLocks;
|
private NamedLock<TableName> tableLocks;
|
||||||
private NamedLock<String> userLocks;
|
private NamedLock<String> userLocks;
|
||||||
private boolean enabled = false;
|
private boolean initialized = false;
|
||||||
private NamespaceAuditor namespaceQuotaManager;
|
private NamespaceAuditor namespaceQuotaManager;
|
||||||
private ConcurrentHashMap<HRegionInfo, SizeSnapshotWithTimestamp> regionSizes;
|
private ConcurrentHashMap<HRegionInfo, SizeSnapshotWithTimestamp> regionSizes;
|
||||||
|
|
||||||
|
@ -101,14 +102,14 @@ public class MasterQuotaManager implements RegionStateListener {
|
||||||
|
|
||||||
namespaceQuotaManager = new NamespaceAuditor(masterServices);
|
namespaceQuotaManager = new NamespaceAuditor(masterServices);
|
||||||
namespaceQuotaManager.start();
|
namespaceQuotaManager.start();
|
||||||
enabled = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isQuotaEnabled() {
|
public boolean isQuotaInitialized() {
|
||||||
return enabled && namespaceQuotaManager.isInitialized();
|
return initialized && namespaceQuotaManager.isInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ==========================================================================
|
/* ==========================================================================
|
||||||
|
@ -284,13 +285,13 @@ public class MasterQuotaManager implements RegionStateListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNamespaceQuota(NamespaceDescriptor desc) throws IOException {
|
public void setNamespaceQuota(NamespaceDescriptor desc) throws IOException {
|
||||||
if (enabled) {
|
if (initialized) {
|
||||||
this.namespaceQuotaManager.addNamespace(desc);
|
this.namespaceQuotaManager.addNamespace(desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeNamespaceQuota(String namespace) throws IOException {
|
public void removeNamespaceQuota(String namespace) throws IOException {
|
||||||
if (enabled) {
|
if (initialized) {
|
||||||
this.namespaceQuotaManager.deleteNamespace(namespace);
|
this.namespaceQuotaManager.deleteNamespace(namespace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,13 +326,13 @@ public class MasterQuotaManager implements RegionStateListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkNamespaceTableAndRegionQuota(TableName tName, int regions) throws IOException {
|
public void checkNamespaceTableAndRegionQuota(TableName tName, int regions) throws IOException {
|
||||||
if (enabled) {
|
if (initialized) {
|
||||||
namespaceQuotaManager.checkQuotaToCreateTable(tName, regions);
|
namespaceQuotaManager.checkQuotaToCreateTable(tName, regions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkAndUpdateNamespaceRegionQuota(TableName tName, int regions) throws IOException {
|
public void checkAndUpdateNamespaceRegionQuota(TableName tName, int regions) throws IOException {
|
||||||
if (enabled) {
|
if (initialized) {
|
||||||
namespaceQuotaManager.checkQuotaToUpdateRegion(tName, regions);
|
namespaceQuotaManager.checkQuotaToUpdateRegion(tName, regions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,20 +341,20 @@ public class MasterQuotaManager implements RegionStateListener {
|
||||||
* @return cached region count, or -1 if quota manager is disabled or table status not found
|
* @return cached region count, or -1 if quota manager is disabled or table status not found
|
||||||
*/
|
*/
|
||||||
public int getRegionCountOfTable(TableName tName) throws IOException {
|
public int getRegionCountOfTable(TableName tName) throws IOException {
|
||||||
if (enabled) {
|
if (initialized) {
|
||||||
return namespaceQuotaManager.getRegionCountOfTable(tName);
|
return namespaceQuotaManager.getRegionCountOfTable(tName);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRegionMerged(HRegionInfo hri) throws IOException {
|
public void onRegionMerged(HRegionInfo hri) throws IOException {
|
||||||
if (enabled) {
|
if (initialized) {
|
||||||
namespaceQuotaManager.updateQuotaForRegionMerge(hri);
|
namespaceQuotaManager.updateQuotaForRegionMerge(hri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRegionSplit(HRegionInfo hri) throws IOException {
|
public void onRegionSplit(HRegionInfo hri) throws IOException {
|
||||||
if (enabled) {
|
if (initialized) {
|
||||||
namespaceQuotaManager.checkQuotaToSplitRegion(hri);
|
namespaceQuotaManager.checkQuotaToSplitRegion(hri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -365,7 +366,7 @@ public class MasterQuotaManager implements RegionStateListener {
|
||||||
* @throws IOException Signals that an I/O exception has occurred.
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
*/
|
*/
|
||||||
public void removeTableFromNamespaceQuota(TableName tName) throws IOException {
|
public void removeTableFromNamespaceQuota(TableName tName) throws IOException {
|
||||||
if (enabled) {
|
if (initialized) {
|
||||||
namespaceQuotaManager.removeFromNamespaceUsage(tName);
|
namespaceQuotaManager.removeFromNamespaceUsage(tName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,10 +500,26 @@ public class MasterQuotaManager implements RegionStateListener {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private void checkQuotaSupport() throws IOException {
|
private void checkQuotaSupport() throws IOException {
|
||||||
if (!enabled) {
|
if (!QuotaUtil.isQuotaEnabled(masterServices.getConfiguration())) {
|
||||||
throw new DoNotRetryIOException(
|
throw new DoNotRetryIOException(
|
||||||
new UnsupportedOperationException("quota support disabled"));
|
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 {
|
private void createQuotaTable() throws IOException {
|
||||||
|
@ -531,7 +548,7 @@ public class MasterQuotaManager implements RegionStateListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRegionSplitReverted(HRegionInfo hri) throws IOException {
|
public void onRegionSplitReverted(HRegionInfo hri) throws IOException {
|
||||||
if (enabled) {
|
if (initialized) {
|
||||||
this.namespaceQuotaManager.removeRegionFromNamespaceUsage(hri);
|
this.namespaceQuotaManager.removeRegionFromNamespaceUsage(hri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class TestSimpleRegionNormalizerOnCluster {
|
||||||
|
|
||||||
// Start a cluster of two regionservers.
|
// Start a cluster of two regionservers.
|
||||||
TEST_UTIL.startMiniCluster(1);
|
TEST_UTIL.startMiniCluster(1);
|
||||||
TestNamespaceAuditor.waitForQuotaEnabled(TEST_UTIL);
|
TestNamespaceAuditor.waitForQuotaInitialize(TEST_UTIL);
|
||||||
admin = TEST_UTIL.getAdmin();
|
admin = TEST_UTIL.getAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class TestNamespaceAuditor {
|
||||||
conf.setClass("hbase.coprocessor.regionserver.classes", CPRegionServerObserver.class,
|
conf.setClass("hbase.coprocessor.regionserver.classes", CPRegionServerObserver.class,
|
||||||
RegionServerObserver.class);
|
RegionServerObserver.class);
|
||||||
UTIL.startMiniCluster(1, 1);
|
UTIL.startMiniCluster(1, 1);
|
||||||
waitForQuotaEnabled(UTIL);
|
waitForQuotaInitialize(UTIL);
|
||||||
ADMIN = UTIL.getAdmin();
|
ADMIN = UTIL.getAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,8 +132,8 @@ public class TestNamespaceAuditor {
|
||||||
ADMIN.deleteNamespace(ns.getName());
|
ADMIN.deleteNamespace(ns.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue("Quota manager not enabled", UTIL.getHBaseCluster().getMaster()
|
assertTrue("Quota manager not initialized", UTIL.getHBaseCluster().getMaster()
|
||||||
.getMasterQuotaManager().isQuotaEnabled());
|
.getMasterQuotaManager().isQuotaInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -649,7 +649,7 @@ public class TestNamespaceAuditor {
|
||||||
.getTables().size(), after.getTables().size());
|
.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<Exception>() {
|
util.waitFor(60000, new Waiter.Predicate<Exception>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate() throws Exception {
|
public boolean evaluate() throws Exception {
|
||||||
|
@ -658,7 +658,7 @@ public class TestNamespaceAuditor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MasterQuotaManager quotaManager = master.getMasterQuotaManager();
|
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().getMaster(0).stop("Stopping to start again");
|
||||||
UTIL.getHBaseCluster().waitOnMaster(0);
|
UTIL.getHBaseCluster().waitOnMaster(0);
|
||||||
UTIL.getHBaseCluster().startMaster();
|
UTIL.getHBaseCluster().startMaster();
|
||||||
waitForQuotaEnabled(UTIL);
|
waitForQuotaInitialize(UTIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private NamespaceAuditor getQuotaManager() {
|
private NamespaceAuditor getQuotaManager() {
|
||||||
|
|
Loading…
Reference in New Issue