@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]); }
@Override public void postDeleteTable( ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName) throws IOException { // Do nothing if quotas aren't enabled if (!quotasEnabled) { return; } final Connection conn = ctx.getEnvironment().getConnection(); Quotas quotas = QuotaUtil.getTableQuota(conn, tableName); if (quotas != null){ if (quotas.hasSpace()){ QuotaSettings settings = QuotaSettingsFactory.removeTableSpaceLimit(tableName); try (Admin admin = conn.getAdmin()) { admin.setQuota(settings); } } if (quotas.hasThrottle()){ QuotaSettings settings = QuotaSettingsFactory.unthrottleTable(tableName); try (Admin admin = conn.getAdmin()) { admin.setQuota(settings); } } } }
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 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 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])); }
@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(QuotaSettingsFactory.unthrottleTable(table)).get();
triggerUserCacheRefresh(true, TABLE_NAMES[0], TABLE_NAMES[1]); admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[1])); triggerTableCacheRefresh(true, TABLE_NAMES[1]); waitMinuteQuota(); assertEquals(40, doGets(40, tables[1])); admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0])); triggerTableCacheRefresh(true, TABLE_NAMES[0]); waitMinuteQuota();
@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])); }
settings = QuotaSettingsFactory.unthrottleTable(tn); admin.setQuota(settings); assertEquals(1, getNumSpaceQuotas());
admin.setQuota(QuotaSettingsFactory.unthrottleTable(table));
admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0])); admin.setQuota(QuotaSettingsFactory.unthrottleNamespace(NAMESPACE)); waitMinuteQuota();
@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 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); }
@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 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])); }
@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])); }
admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0])); admin.setQuota(QuotaSettingsFactory.unthrottleNamespace(NAMESPACE)); waitMinuteQuota();