@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]); }
@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()); }
admin.setQuota(QuotaSettingsFactory.throttleTable(tableName, ThrottleType.WRITE_NUMBER, 6, TimeUnit.SECONDS));
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); }
@Test public void testSetModifyRemoveRPCQuota() throws Exception { Admin admin = TEST_UTIL.getAdmin(); final TableName tn = TableName.valueOf("sq_table1"); QuotaSettings settings = QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); admin.setQuota(settings); // Verify the Quota in the table verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); // Verify we can retrieve it via the QuotaRetriever API verifyFetchableViaAPI(admin, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); // Setting a limit and time unit should be reflected QuotaSettings newSettings = QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 3L, TimeUnit.DAYS); admin.setQuota(newSettings); // Verify the new Quota in the table verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_SIZE, 3L, TimeUnit.DAYS); // Verify we can retrieve the new quota via the QuotaRetriever API verifyFetchableViaAPI(admin, ThrottleType.REQUEST_SIZE, 3L, TimeUnit.DAYS); // 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); }
@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()); }
@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]); }
@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]); }
@Test public void testTableGlobalReadAndWriteThrottle() throws Exception { final Admin admin = TEST_UTIL.getAdmin(); // Add 6req/min limit for read request admin.setQuota(QuotaSettingsFactory .throttleTable(TABLE_NAMES[0], ThrottleType.READ_NUMBER, 6, TimeUnit.MINUTES)); triggerTableCacheRefresh(false, TABLE_NAMES[0]); // should execute at max 6 read requests and have no limit for write request assertEquals(6, doGets(100, tables[0])); assertEquals(100, doPuts(100, tables[0])); // should have no limits on tables[1] assertEquals(30, doPuts(30, tables[1])); assertEquals(30, doGets(30, tables[1])); // wait a minute and you should get other 6 requests executed waitMinuteQuota(); // Add 6req/min limit for write request, too admin.setQuota(QuotaSettingsFactory .throttleTable(TABLE_NAMES[0], ThrottleType.WRITE_NUMBER, 6, TimeUnit.MINUTES)); triggerTableCacheRefresh(false, TABLE_NAMES[0]); // should execute at max 6 read requests and at max 6 write requests assertEquals(6, doGets(100, tables[0])); assertEquals(6, doPuts(100, tables[0])); // should have no limits on tables[1] assertEquals(30, doPuts(30, tables[1])); assertEquals(30, doGets(30, tables[1])); // Remove all the limits admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0])); triggerTableCacheRefresh(true, TABLE_NAMES[0]); assertEquals(80, doGets(80, tables[0], tables[1])); }
@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])); }
QuotaSettingsFactory.throttleTable(table, ThrottleType.REQUEST_NUMBER, 4, TimeUnit.MINUTES)) .get();
@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]); }
admin.setQuota(settings); settings = QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); admin.setQuota(settings); QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); admin.setQuota(settings); assertEquals(1, getNumSpaceQuotas());
.throttleTable(TABLE_NAMES[1], ThrottleType.REQUEST_NUMBER, 8, TimeUnit.MINUTES)); triggerTableCacheRefresh(false, TABLE_NAMES[1]); .throttleTable(TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER, 3, TimeUnit.MINUTES)); triggerTableCacheRefresh(false, TABLE_NAMES[0]);
QuotaSettings qs = QuotaSettingsFactory.throttleTable(fooLimited, // co QuotaExample-3-Quota1 Configure a quota setting record at the table level, and assign it. ThrottleType.READ_NUMBER, 5, TimeUnit.DAYS); admin.setQuota(qs);
.throttleTable(table, ThrottleType.REQUEST_NUMBER, 4, TimeUnit.MINUTES));
.throttleTable(TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES)); triggerTableCacheRefresh(false, TABLE_NAMES[0]);
@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]); }
@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()); }
@Test public void testSetGetRemoveRPCQuota() throws Exception { Admin admin = TEST_UTIL.getAdmin(); final TableName tn = TableName.valueOf("sq_table1"); QuotaSettings settings = QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); admin.setQuota(settings); // Verify the Quota in the table verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); // Verify we can retrieve it via the QuotaRetriever API verifyFetchableViaAPI(admin, ThrottleType.REQUEST_SIZE, 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); }