HBASE-21733 SnapshotQuotaObserverChore should only fetch space quotas

Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
meiyi 2019-01-18 09:51:51 +08:00 committed by Guanghao Zhang
parent 16c7f5dac9
commit 5ddda1a1f6
3 changed files with 27 additions and 14 deletions

View File

@ -131,11 +131,12 @@ public class SnapshotQuotaObserverChore extends ScheduledChore {
try (Admin admin = conn.getAdmin()) {
// Pull all of the tables that have quotas (direct, or from namespace)
for (QuotaSettings qs : QuotaRetriever.open(conf, filter)) {
if (qs.getQuotaType() == QuotaType.SPACE) {
String ns = qs.getNamespace();
TableName tn = qs.getTableName();
if ((null == ns && null == tn) || (null != ns && null != tn)) {
throw new IllegalStateException(
"Expected only one of namespace and tablename to be null");
"Expected either one of namespace and tablename to be null but not both");
}
// Collect either the table name itself, or all of the tables in the namespace
if (null != ns) {
@ -144,6 +145,7 @@ public class SnapshotQuotaObserverChore extends ScheduledChore {
tablesToFetchSnapshotsFrom.add(tn);
}
}
}
// Fetch all snapshots that were created from these tables
return getSnapshotsFromTables(admin, tablesToFetchSnapshotsFrom);
}

View File

@ -135,13 +135,16 @@ public class SpaceQuotaHelperForTests {
for (QuotaSettings quotaSettings : scanner) {
final String namespace = quotaSettings.getNamespace();
final TableName tableName = quotaSettings.getTableName();
final String userName = quotaSettings.getUserName();
if (namespace != null) {
LOG.debug("Deleting quota for namespace: " + namespace);
QuotaUtil.deleteNamespaceQuota(conn, namespace);
} else {
assert tableName != null;
} else if (tableName != null) {
LOG.debug("Deleting quota for table: " + tableName);
QuotaUtil.deleteTableQuota(conn, tableName);
} else if (userName != null) {
LOG.debug("Deleting quota for user: " + userName);
QuotaUtil.deleteUserQuota(conn, userName);
}
}
} finally {

View File

@ -28,6 +28,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
@ -160,6 +161,13 @@ public class TestSnapshotQuotaObserverChore {
TableName tn2 = helper.createTableWithRegions(ns.getName(), 1);
TableName tn3 = helper.createTableWithRegions(1);
// Set a throttle quota on 'default' namespace
admin.setQuota(QuotaSettingsFactory.throttleNamespace(tn3.getNamespaceAsString(),
ThrottleType.WRITE_NUMBER, 100, TimeUnit.SECONDS));
// Set a user throttle quota
admin.setQuota(
QuotaSettingsFactory.throttleUser("user", ThrottleType.WRITE_NUMBER, 100, TimeUnit.MINUTES));
// Set a space quota on the namespace
admin.setQuota(QuotaSettingsFactory.limitNamespaceSpace(
ns.getName(), SpaceQuotaHelperForTests.ONE_GIGABYTE, SpaceViolationPolicy.NO_INSERTS));