本文整理了Java中org.apache.hadoop.hbase.client.Admin.setQuota()
方法的一些代码示例,展示了Admin.setQuota()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Admin.setQuota()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Admin
类名称:Admin
方法名:setQuota
[英]Apply the new quota settings.
[中]应用新的配额设置。
代码示例来源:origin: apache/hbase
private void removeQuotaFromtable(final TableName tn) throws Exception {
QuotaSettings removeQuota = QuotaSettingsFactory.removeTableSpaceLimit(tn);
TEST_UTIL.getAdmin().setQuota(removeQuota);
LOG.debug("Space quota settings removed from the table ", tn);
}
代码示例来源:origin: apache/hbase
private void setQuotaLimit(final TableName tn, SpaceViolationPolicy policy, long sizeInMBs)
throws Exception {
final long sizeLimit = sizeInMBs * SpaceQuotaHelperForTests.ONE_MEGABYTE;
QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tn, sizeLimit, policy);
TEST_UTIL.getAdmin().setQuota(settings);
LOG.debug("Quota limit set for table = {}, limit = {}", tn, sizeLimit);
}
代码示例来源:origin: apache/hbase
@Test
public void testTableQuotaOverridesNamespaceQuota() throws Exception {
final SpaceViolationPolicy policy = SpaceViolationPolicy.NO_INSERTS;
final TableName tn = helper.createTableWithRegions(10);
// 2MB limit on the table, 1GB limit on the namespace
final long tableLimit = 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE;
final long namespaceLimit = 1024L * SpaceQuotaHelperForTests.ONE_MEGABYTE;
TEST_UTIL.getAdmin().setQuota(QuotaSettingsFactory.limitTableSpace(tn, tableLimit, policy));
TEST_UTIL.getAdmin().setQuota(QuotaSettingsFactory.limitNamespaceSpace(
tn.getNamespaceAsString(), namespaceLimit, policy));
// Write more data than should be allowed and flush it to disk
helper.writeData(tn, 3L * SpaceQuotaHelperForTests.ONE_MEGABYTE);
// This should be sufficient time for the chores to run and see the change.
Thread.sleep(5000);
// The write should be rejected because the table quota takes priority over the namespace
Put p = new Put(Bytes.toBytes("to_reject"));
p.addColumn(
Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), Bytes.toBytes("reject"));
verifyViolation(policy, tn, p);
}
代码示例来源:origin: apache/hbase
@Override
public Void call() throws Exception {
try (Connection conn = getConnection()) {
final Admin admin = conn.getAdmin();
QuotaSettings qs = QuotaSettingsFactory.removeTableSpaceLimit(tn);
try {
admin.setQuota(qs);
fail("Expected that an unprivileged user should not be allowed to remove a quota");
} catch (Exception e) {
// pass
}
return null;
}
}
});
代码示例来源:origin: apache/hbase
@Test
public void testTableExistsGetThrottle() throws Exception {
final Admin admin = TEST_UTIL.getAdmin();
// Add throttle quota
admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0],
ThrottleType.REQUEST_NUMBER, 100, TimeUnit.MINUTES));
triggerTableCacheRefresh(false, TABLE_NAMES[0]);
Table table = TEST_UTIL.getConnection().getTable(TABLE_NAMES[0]);
// An exists call when having throttle quota
table.exists(new Get(Bytes.toBytes("abc")));
admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
triggerTableCacheRefresh(true, TABLE_NAMES[0]);
}
代码示例来源:origin: apache/hbase
private void testSetGetRemoveRPCQuota(ThrottleType throttleType) throws Exception {
Admin admin = TEST_UTIL.getAdmin();
final TableName tn = TableName.valueOf("sq_table1");
QuotaSettings settings =
QuotaSettingsFactory.throttleTable(tn, throttleType, 2L, TimeUnit.HOURS);
admin.setQuota(settings);
// Verify the Quota in the table
verifyRecordPresentInQuotaTable(throttleType, 2L, TimeUnit.HOURS);
// Verify we can retrieve it via the QuotaRetriever API
verifyFetchableViaAPI(admin, throttleType, 2L, TimeUnit.HOURS);
// Now, remove the quota
QuotaSettings removeQuota = QuotaSettingsFactory.unthrottleTable(tn);
admin.setQuota(removeQuota);
// Verify that the record doesn't exist in the table
verifyRecordNotPresentInQuotaTable();
// Verify that we can also not fetch it via the API
verifyNotFetchableViaAPI(admin);
}
代码示例来源:origin: apache/hbase
@Test
public void testRegionServerThrottle() throws Exception {
final Admin admin = TEST_UTIL.getAdmin();
admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], ThrottleType.WRITE_NUMBER, 5,
TimeUnit.MINUTES));
// requests are throttled by table quota
admin.setQuota(QuotaSettingsFactory.throttleRegionServer(
QuotaTableUtil.QUOTA_REGION_SERVER_ROW_KEY, ThrottleType.WRITE_NUMBER, 7, TimeUnit.MINUTES));
triggerCacheRefresh(false, false, true, false, true, TABLE_NAMES[0]);
assertEquals(5, doPuts(10, tables[0]));
// requests are throttled by region server quota
admin.setQuota(QuotaSettingsFactory.throttleRegionServer(
QuotaTableUtil.QUOTA_REGION_SERVER_ROW_KEY, ThrottleType.WRITE_NUMBER, 4, TimeUnit.MINUTES));
triggerCacheRefresh(false, false, false, false, true, TABLE_NAMES[0]);
assertEquals(4, doPuts(10, tables[0]));
// unthrottle
admin.setQuota(
QuotaSettingsFactory.unthrottleRegionServer(QuotaTableUtil.QUOTA_REGION_SERVER_ROW_KEY));
admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
triggerCacheRefresh(true, false, true, false, true, TABLE_NAMES[0]);
}
代码示例来源:origin: apache/hbase
@Override
public Void call() throws Exception {
try (Connection conn = getConnection()) {
final Admin admin = conn.getAdmin();
QuotaSettings qs = QuotaSettingsFactory.removeTableSpaceLimit(tn);
admin.setQuota(qs);
assertNull(helper.getTableSpaceQuota(conn, tn));
return null;
}
}
});
代码示例来源:origin: apache/hbase
@Test
public void testTableWriteCapacityUnitThrottle() throws Exception {
final Admin admin = TEST_UTIL.getAdmin();
// Add 6CU/min limit
admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0],
ThrottleType.WRITE_CAPACITY_UNIT, 6, TimeUnit.MINUTES));
triggerTableCacheRefresh(false, TABLE_NAMES[0]);
// should execute at max 6 capacity units because each put size is 1 capacity unit
assertEquals(6, doPuts(20, 10, tables[0]));
// wait a minute and you should execute at max 3 capacity units because each put size is 2
// capacity unit
waitMinuteQuota();
assertEquals(3, doPuts(20, 1025, tables[0]));
admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
triggerTableCacheRefresh(true, TABLE_NAMES[0]);
}
代码示例来源:origin: apache/hbase
@Test
public void testRpcQuotaTablesAreFiltered() throws Exception {
final Multimap<TableName, QuotaSettings> quotas = helper.createTablesWithSpaceQuotas();
Set<TableName> tablesWithQuotas = new HashSet<>();
Set<TableName> namespaceTablesWithQuotas = new HashSet<>();
// Partition the tables with quotas by table and ns quota
helper.partitionTablesByQuotaTarget(quotas, tablesWithQuotas, namespaceTablesWithQuotas);
TableName rpcQuotaTable = helper.createTable();
TEST_UTIL.getAdmin().setQuota(QuotaSettingsFactory
.throttleTable(rpcQuotaTable, ThrottleType.READ_NUMBER, 6, TimeUnit.MINUTES));
// The `rpcQuotaTable` should not be included in this Set
TablesWithQuotas tables = chore.fetchAllTablesWithQuotasDefined();
assertEquals("Found tables: " + tables, tablesWithQuotas, tables.getTableQuotaTables());
assertEquals("Found tables: " + tables, namespaceTablesWithQuotas, tables.getNamespaceQuotaTables());
}
代码示例来源:origin: apache/hbase
@Test
public void testNamespaceGlobalThrottle() throws Exception {
final Admin admin = TEST_UTIL.getAdmin();
final String NAMESPACE = "default";
// Add 6req/min limit
admin.setQuota(QuotaSettingsFactory
.throttleNamespace(NAMESPACE, ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
triggerNamespaceCacheRefresh(false, TABLE_NAMES[0]);
// should execute at max 6 requests
assertEquals(6, doPuts(100, tables[0]));
// wait a minute and you should get other 6 requests executed
waitMinuteQuota();
assertEquals(6, doPuts(100, tables[1]));
admin.setQuota(QuotaSettingsFactory.unthrottleNamespace(NAMESPACE));
triggerNamespaceCacheRefresh(true, TABLE_NAMES[0]);
assertEquals(40, doPuts(40, tables[0]));
}
代码示例来源:origin: apache/hbase
@Test
public void testFlushes() throws Exception {
TableName tn = helper.createTableWithRegions(1);
// Set a quota
QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(
tn, SpaceQuotaHelperForTests.ONE_GIGABYTE, SpaceViolationPolicy.NO_INSERTS);
admin.setQuota(settings);
// Write some data
final long initialSize = 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE;
helper.writeData(tn, initialSize);
// Make sure a flush happened
admin.flush(tn);
// We should be able to observe the system recording an increase in size (even
// though we know the filesystem scanning did not happen).
TEST_UTIL.waitFor(30 * 1000, 500, new SpaceQuotaSnapshotPredicate(conn, tn) {
@Override boolean evaluate(SpaceQuotaSnapshot snapshot) throws Exception {
return snapshot.getUsage() >= initialSize;
}
});
}
代码示例来源:origin: apache/hbase
@Test
public void testTableReadCapacityUnitThrottle() throws Exception {
final Admin admin = TEST_UTIL.getAdmin();
// Add 6CU/min limit
admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0],
ThrottleType.READ_CAPACITY_UNIT, 6, TimeUnit.MINUTES));
triggerTableCacheRefresh(false, TABLE_NAMES[0]);
assertEquals(20, doPuts(20, 10, tables[0]));
// should execute at max 6 capacity units because each get size is 1 capacity unit
assertEquals(6, doGets(20, tables[0]));
assertEquals(20, doPuts(20, 2015, tables[0]));
// wait a minute and you should execute at max 3 capacity units because each get size is 2
// capacity unit on tables[0]
waitMinuteQuota();
assertEquals(3, doGets(20, tables[0]));
admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
triggerTableCacheRefresh(true, TABLE_NAMES[0]);
}
代码示例来源:origin: apache/hbase
@Test
public void testTableGlobalThrottle() throws Exception {
final Admin admin = TEST_UTIL.getAdmin();
// Add 6req/min limit
admin.setQuota(QuotaSettingsFactory
.throttleTable(TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
triggerTableCacheRefresh(false, TABLE_NAMES[0]);
// should execute at max 6 requests
assertEquals(6, doPuts(100, tables[0]));
// should have no limits
assertEquals(30, doPuts(30, tables[1]));
// wait a minute and you should get other 6 requests executed
waitMinuteQuota();
assertEquals(6, doPuts(100, tables[0]));
// Remove all the limits
admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
triggerTableCacheRefresh(true, TABLE_NAMES[0]);
assertEquals(80, doGets(80, tables[0], tables[1]));
}
代码示例来源:origin: apache/hbase
@Test
public void testUserNamespaceThrottle() throws Exception {
final Admin admin = TEST_UTIL.getAdmin();
final String userName = User.getCurrent().getShortName();
final String NAMESPACE = "default";
// Add 6req/min limit
admin.setQuota(QuotaSettingsFactory
.throttleUser(userName, NAMESPACE, ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
triggerUserCacheRefresh(false, TABLE_NAMES[0]);
// should execute at max 6 requests on tables[0] and have no limit on tables[1]
assertEquals(6, doPuts(100, tables[0]));
// wait a minute and you should get other 6 requests executed
waitMinuteQuota();
assertEquals(6, doPuts(100, tables[1]));
// Remove all the limits
admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, NAMESPACE));
triggerUserCacheRefresh(true, TABLE_NAMES);
assertEquals(60, doPuts(60, tables));
assertEquals(60, doGets(60, tables));
}
代码示例来源:origin: apache/hbase
@Test
public void testUserGlobalThrottle() throws Exception {
final Admin admin = TEST_UTIL.getAdmin();
final String userName = User.getCurrent().getShortName();
// Add 6req/min limit
admin.setQuota(QuotaSettingsFactory
.throttleUser(userName, ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
triggerUserCacheRefresh(false, TABLE_NAMES);
// should execute at max 6 requests
assertEquals(6, doPuts(100, tables));
// wait a minute and you should get other 6 requests executed
waitMinuteQuota();
assertEquals(6, doPuts(100, tables));
// Remove all the limits
admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName));
triggerUserCacheRefresh(true, TABLE_NAMES);
assertEquals(60, doPuts(60, tables));
assertEquals(60, doGets(60, tables));
}
代码示例来源:origin: apache/hbase
@Test
public void testUserTableThrottle() throws Exception {
final Admin admin = TEST_UTIL.getAdmin();
final String userName = User.getCurrent().getShortName();
// Add 6req/min limit
admin.setQuota(QuotaSettingsFactory
.throttleUser(userName, TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
triggerUserCacheRefresh(false, TABLE_NAMES[0]);
// should execute at max 6 requests on tables[0] and have no limit on tables[1]
assertEquals(6, doPuts(100, tables[0]));
assertEquals(30, doPuts(30, tables[1]));
// wait a minute and you should get other 6 requests executed
waitMinuteQuota();
assertEquals(6, doPuts(100, tables[0]));
// Remove all the limits
admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, TABLE_NAMES[0]));
triggerUserCacheRefresh(true, TABLE_NAMES);
assertEquals(60, doPuts(60, tables));
assertEquals(60, doGets(60, tables));
}
代码示例来源:origin: apache/hbase
@Test
public void testTableSpaceQuotaRemoved() throws Exception {
final Connection conn = TEST_UTIL.getConnection();
final Admin admin = conn.getAdmin();
final TableName tn = TableName.valueOf(testName.getMethodName());
// Drop the table if it somehow exists
if (admin.tableExists(tn)) {
dropTable(admin, tn);
}
createTable(admin, tn);
assertEquals(0, getNumSpaceQuotas());
// Set space quota
QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(
tn, 1024L, SpaceViolationPolicy.NO_INSERTS);
admin.setQuota(settings);
assertEquals(1, getNumSpaceQuotas());
// Drop the table and observe the Space quota being automatically deleted as well
dropTable(admin, tn);
assertEquals(0, getNumSpaceQuotas());
}
代码示例来源:origin: apache/hbase
@Test
public void testTableRPCQuotaRemoved() throws Exception {
final Connection conn = TEST_UTIL.getConnection();
final Admin admin = conn.getAdmin();
final TableName tn = TableName.valueOf(testName.getMethodName());
// Drop the table if it somehow exists
if (admin.tableExists(tn)) {
dropTable(admin, tn);
}
createTable(admin, tn);
assertEquals(0, getThrottleQuotas());
// Set RPC quota
QuotaSettings settings =
QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS);
admin.setQuota(settings);
assertEquals(1, getThrottleQuotas());
// Delete the table and observe the RPC quota being automatically deleted as well
dropTable(admin, tn);
assertEquals(0, getThrottleQuotas());
}
代码示例来源:origin: apache/hbase
@Test
public void testNamespaceSpaceQuotaRemoved() throws Exception {
final Connection conn = TEST_UTIL.getConnection();
final Admin admin = conn.getAdmin();
final String ns = testName.getMethodName();
// Drop the ns if it somehow exists
if (namespaceExists(ns)) {
admin.deleteNamespace(ns);
}
// Create the ns
NamespaceDescriptor desc = NamespaceDescriptor.create(ns).build();
admin.createNamespace(desc);
assertEquals(0, getNumSpaceQuotas());
// Set a quota
QuotaSettings settings = QuotaSettingsFactory.limitNamespaceSpace(
ns, 1024L, SpaceViolationPolicy.NO_INSERTS);
admin.setQuota(settings);
assertEquals(1, getNumSpaceQuotas());
// Delete the namespace and observe the quota being automatically deleted as well
admin.deleteNamespace(ns);
assertEquals(0, getNumSpaceQuotas());
}
内容来源于网络,如有侵权,请联系作者删除!