Java Code Examples for org.apache.hadoop.hbase.client.Admin#setQuota()

The following examples show how to use org.apache.hadoop.hbase.client.Admin#setQuota() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestQuotaThrottle.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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(TEST_UTIL, false, TABLE_NAMES[0]);

  // should execute at max 6 requests on tables[0] and have no limit on tables[1]
  assertEquals(6, doPuts(100, FAMILY, QUALIFIER, tables[0]));

  // wait a minute and you should get other 6 requests executed
  waitMinuteQuota();
  assertEquals(6, doPuts(100, FAMILY, QUALIFIER, tables[1]));

  // Remove all the limits
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, NAMESPACE));
  triggerUserCacheRefresh(TEST_UTIL, true, TABLE_NAMES);
  assertEquals(60, doPuts(60, FAMILY, QUALIFIER, tables));
  assertEquals(60, doGets(60, tables));
}
 
Example 2
Source File: TestQuotaThrottle.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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(TEST_UTIL, false, TABLE_NAMES[0]);

  assertEquals(20, doPuts(20, 10, FAMILY, QUALIFIER, 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, FAMILY, QUALIFIER, 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(TEST_UTIL, true, TABLE_NAMES[0]);
}
 
Example 3
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserTableUnThrottleByType() throws Exception {
  final Admin admin = TEST_UTIL.getAdmin();
  final String userName = User.getCurrent().getShortName();
  String userName01 = "user01";
  // Add 6req/min limit
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName, TABLE_NAMES[0],
    ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName, TABLE_NAMES[0],
    ThrottleType.REQUEST_SIZE, 6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName01, TABLE_NAMES[1],
    ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName01, TABLE_NAMES[1],
    ThrottleType.REQUEST_SIZE, 6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.unthrottleUserByThrottleType(userName, TABLE_NAMES[0],
    ThrottleType.REQUEST_NUMBER));
  assertEquals(3, getQuotaSettingCount(admin));
  admin.setQuota(QuotaSettingsFactory.unthrottleUserByThrottleType(userName, TABLE_NAMES[0],
    ThrottleType.REQUEST_SIZE));
  assertEquals(2, getQuotaSettingCount(admin));
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName01));
  assertEquals(0, getQuotaSettingCount(admin));
}
 
Example 4
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testNameSpaceUnThrottleByType() throws Exception {
  final Admin admin = TEST_UTIL.getAdmin();
  final String userName = User.getCurrent().getShortName();
  // Add 6req/min limit
  admin.setQuota(QuotaSettingsFactory.throttleNamespace(NAMESPACES[0],
    ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleNamespace(NAMESPACES[0], ThrottleType.REQUEST_SIZE,
    6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleNamespace(NAMESPACES[1],
    ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleNamespace(NAMESPACES[1], ThrottleType.REQUEST_SIZE,
    6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.unthrottleNamespaceByThrottleType(NAMESPACES[0],
    ThrottleType.REQUEST_NUMBER));
  assertEquals(3, getQuotaSettingCount(admin));
  admin.setQuota(QuotaSettingsFactory.unthrottleNamespaceByThrottleType(NAMESPACES[0],
    ThrottleType.REQUEST_SIZE));
  assertEquals(2, getQuotaSettingCount(admin));
  admin.setQuota(QuotaSettingsFactory.unthrottleNamespace(NAMESPACES[1]));
  assertEquals(0, getQuotaSettingCount(admin));
}
 
Example 5
Source File: TestQuotaThrottle.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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(TEST_UTIL, false, TABLE_NAMES[0]);

  // should execute at max 6 requests
  assertEquals(6, doPuts(100, FAMILY, QUALIFIER, tables[0]));
  // should have no limits
  assertEquals(30, doPuts(30, FAMILY, QUALIFIER, tables[1]));

  // wait a minute and you should get other 6 requests executed
  waitMinuteQuota();
  assertEquals(6, doPuts(100, FAMILY, QUALIFIER, tables[0]));

  // Remove all the limits
  admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
  triggerTableCacheRefresh(TEST_UTIL, true, TABLE_NAMES[0]);
  assertEquals(80, doGets(80, tables[0], tables[1]));
}
 
Example 6
Source File: TestQuotaThrottle.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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(TEST_UTIL, 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(TEST_UTIL, true, TABLE_NAMES[0]);
}
 
Example 7
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testTableUnThrottleByType() throws Exception {
  final Admin admin = TEST_UTIL.getAdmin();
  final String userName = User.getCurrent().getShortName();
  // Add 6req/min limit
  admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER,
    6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], ThrottleType.REQUEST_SIZE, 6,
    TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[1], ThrottleType.REQUEST_NUMBER,
    6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[1], ThrottleType.REQUEST_SIZE, 6,
    TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.unthrottleTableByThrottleType(TABLE_NAMES[0],
    ThrottleType.REQUEST_NUMBER));
  assertEquals(3, getQuotaSettingCount(admin));
  admin.setQuota(QuotaSettingsFactory.unthrottleTableByThrottleType(TABLE_NAMES[0],
    ThrottleType.REQUEST_SIZE));
  assertEquals(2, getQuotaSettingCount(admin));
  admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[1]));
  assertEquals(0, getQuotaSettingCount(admin));
}
 
Example 8
Source File: TestQuotaThrottle.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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(TEST_UTIL, false, TABLE_NAMES[0]);

  // should execute at max 6 requests on tables[0] and have no limit on tables[1]
  assertEquals(6, doPuts(100, FAMILY, QUALIFIER, tables[0]));
  assertEquals(30, doPuts(30, FAMILY, QUALIFIER, tables[1]));

  // wait a minute and you should get other 6 requests executed
  waitMinuteQuota();
  assertEquals(6, doPuts(100, FAMILY, QUALIFIER, tables[0]));

  // Remove all the limits
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, TABLE_NAMES[0]));
  triggerUserCacheRefresh(TEST_UTIL, true, TABLE_NAMES);
  assertEquals(60, doPuts(60, FAMILY, QUALIFIER, tables));
  assertEquals(60, doGets(60, tables));
}
 
Example 9
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegionServerUnThrottleByType() throws Exception {
  final Admin admin = TEST_UTIL.getAdmin();
  final String[] REGIONSERVER = { "RS01", "RS02" };

  admin.setQuota(QuotaSettingsFactory.throttleRegionServer(REGIONSERVER[0],
    ThrottleType.READ_NUMBER, 4, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleRegionServer(REGIONSERVER[0],
    ThrottleType.WRITE_NUMBER, 4, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleRegionServer(REGIONSERVER[1],
    ThrottleType.READ_NUMBER, 4, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.throttleRegionServer(REGIONSERVER[1],
    ThrottleType.WRITE_NUMBER, 4, TimeUnit.MINUTES));

  admin.setQuota(QuotaSettingsFactory.unthrottleRegionServerByThrottleType(REGIONSERVER[0],
    ThrottleType.READ_NUMBER));
  assertEquals(3, getQuotaSettingCount(admin));
  admin.setQuota(QuotaSettingsFactory.unthrottleRegionServerByThrottleType(REGIONSERVER[0],
    ThrottleType.WRITE_NUMBER));
  assertEquals(2, getQuotaSettingCount(admin));
  admin.setQuota(QuotaSettingsFactory.unthrottleRegionServer(REGIONSERVER[1]));
  assertEquals(0, getQuotaSettingCount(admin));
}
 
Example 10
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 11
Source File: TestClusterScopeQuotaThrottle.java    From hbase with Apache License 2.0 6 votes vote down vote up
@org.junit.Ignore @Test // Spews the log w/ triggering of scheduler? HBASE-24035
public void testUserNamespaceClusterScopeQuota() throws Exception {
  final Admin admin = TEST_UTIL.getAdmin();
  final String userName = User.getCurrent().getShortName();
  final String namespace = TABLE_NAMES[0].getNamespaceAsString();

  // Add 10req/min limit for read request in cluster scope
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName, namespace, ThrottleType.READ_NUMBER,
    10, TimeUnit.MINUTES, QuotaScope.CLUSTER));
  // Add 6req/min limit for write request in machine scope
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName, namespace, ThrottleType.WRITE_NUMBER,
    6, TimeUnit.MINUTES));
  triggerUserCacheRefresh(TEST_UTIL, false, TABLE_NAMES[0]);
  // should execute at max 5 read requests and at max 6 write requests
  assertEquals(5, doGets(10, tables[0]));
  assertEquals(6, doPuts(10, FAMILY, QUALIFIER, tables[0]));

  // Remove all the limits
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, namespace));
  triggerUserCacheRefresh(TEST_UTIL, true, TABLE_NAMES[0]);
}
 
Example 12
Source File: TestClusterScopeQuotaThrottle.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserClusterScopeQuota() throws Exception {
  final Admin admin = TEST_UTIL.getAdmin();
  final String userName = User.getCurrent().getShortName();

  // Add 6req/min limit for read request in cluster scope
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName, ThrottleType.READ_NUMBER, 6,
    TimeUnit.MINUTES, QuotaScope.CLUSTER));
  // Add 6req/min limit for write request in machine scope
  admin.setQuota(
    QuotaSettingsFactory.throttleUser(userName, ThrottleType.WRITE_NUMBER, 6, TimeUnit.MINUTES));
  triggerUserCacheRefresh(TEST_UTIL, false, TABLE_NAMES);
  // should execute at max 6 read requests and at max 3 write write requests
  assertEquals(6, doPuts(10, FAMILY, QUALIFIER, tables[0]));
  assertEquals(3, doGets(10, tables[0]));
  // Remove all the limits
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName));
  triggerUserCacheRefresh(TEST_UTIL, true, TABLE_NAMES);
}
 
Example 13
Source File: TestMasterQuotasObserver.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 14
Source File: TestQuotaThrottle.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testUserTableReadAndWriteThrottle() throws Exception {
  final Admin admin = TEST_UTIL.getAdmin();
  final String userName = User.getCurrent().getShortName();

  // Add 6req/min limit for write request on tables[0]
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName, TABLE_NAMES[0],
    ThrottleType.WRITE_NUMBER, 6, TimeUnit.MINUTES));
  triggerUserCacheRefresh(TEST_UTIL, false, TABLE_NAMES[0]);

  // should execute at max 6 write requests and have no limit for read request
  assertEquals(6, doPuts(100, FAMILY, QUALIFIER, tables[0]));
  assertEquals(60, doGets(60, tables[0]));

  // no limit on tables[1]
  assertEquals(60, doPuts(60, FAMILY, QUALIFIER, tables[1]));
  assertEquals(60, doGets(60, tables[1]));

  // wait a minute and you should get other 6 write requests executed
  waitMinuteQuota();

  // Add 6req/min limit for read request on tables[0]
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName, TABLE_NAMES[0],
    ThrottleType.READ_NUMBER, 6, TimeUnit.MINUTES));
  triggerUserCacheRefresh(TEST_UTIL, false, TABLE_NAMES[0]);

  // should execute at max 6 read requests and at max 6 write requests
  assertEquals(6, doPuts(100, FAMILY, QUALIFIER, tables[0]));
  assertEquals(6, doGets(60, tables[0]));

  // no limit on tables[1]
  assertEquals(30, doPuts(30, FAMILY, QUALIFIER, tables[1]));
  assertEquals(30, doGets(30, tables[1]));

  // Remove all the limits
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, TABLE_NAMES[0]));
  triggerUserCacheRefresh(TEST_UTIL, true, TABLE_NAMES);
  assertEquals(60, doPuts(60, FAMILY, QUALIFIER, tables));
  assertEquals(60, doGets(60, tables));
}
 
Example 15
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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);

}
 
Example 16
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testThrottleType() throws Exception {
  Admin admin = TEST_UTIL.getAdmin();
  String userName = User.getCurrent().getShortName();

  admin.setQuota(
      QuotaSettingsFactory.throttleUser(userName, ThrottleType.READ_NUMBER, 6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory
      .throttleUser(userName, ThrottleType.WRITE_NUMBER, 12, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.bypassGlobals(userName, true));

  try (QuotaRetriever scanner = QuotaRetriever.open(TEST_UTIL.getConfiguration())) {
    int countThrottle = 0;
    int countGlobalBypass = 0;
    for (QuotaSettings settings: scanner) {
      switch (settings.getQuotaType()) {
        case THROTTLE:
          ThrottleSettings throttle = (ThrottleSettings)settings;
          if (throttle.getSoftLimit() == 6) {
            assertEquals(ThrottleType.READ_NUMBER, throttle.getThrottleType());
          } else if (throttle.getSoftLimit() == 12) {
            assertEquals(ThrottleType.WRITE_NUMBER, throttle.getThrottleType());
          } else {
            fail("should not come here, because don't set quota with this limit");
          }
          assertEquals(userName, throttle.getUserName());
          assertEquals(null, throttle.getTableName());
          assertEquals(null, throttle.getNamespace());
          assertEquals(TimeUnit.MINUTES, throttle.getTimeUnit());
          countThrottle++;
          break;
        case GLOBAL_BYPASS:
          countGlobalBypass++;
          break;
        default:
          fail("unexpected settings type: " + settings.getQuotaType());
      }
    }
    assertEquals(2, countThrottle);
    assertEquals(1, countGlobalBypass);
  }

  admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName));
  assertNumResults(1, null);
  admin.setQuota(QuotaSettingsFactory.bypassGlobals(userName, false));
  assertNumResults(0, null);
}
 
Example 17
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimpleScan() throws Exception {
  Admin admin = TEST_UTIL.getAdmin();
  String userName = User.getCurrent().getShortName();

  admin.setQuota(QuotaSettingsFactory
    .throttleUser(userName, ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
  admin.setQuota(QuotaSettingsFactory.bypassGlobals(userName, true));

  try (QuotaRetriever scanner = QuotaRetriever.open(TEST_UTIL.getConfiguration())) {
    int countThrottle = 0;
    int countGlobalBypass = 0;
    for (QuotaSettings settings: scanner) {
      LOG.debug(Objects.toString(settings));
      switch (settings.getQuotaType()) {
        case THROTTLE:
          ThrottleSettings throttle = (ThrottleSettings)settings;
          assertEquals(userName, throttle.getUserName());
          assertEquals(null, throttle.getTableName());
          assertEquals(null, throttle.getNamespace());
          assertEquals(null, throttle.getRegionServer());
          assertEquals(6, throttle.getSoftLimit());
          assertEquals(TimeUnit.MINUTES, throttle.getTimeUnit());
          countThrottle++;
          break;
        case GLOBAL_BYPASS:
          countGlobalBypass++;
          break;
        default:
          fail("unexpected settings type: " + settings.getQuotaType());
      }
    }
    assertEquals(1, countThrottle);
    assertEquals(1, countGlobalBypass);
  }

  admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName));
  assertNumResults(1, null);
  admin.setQuota(QuotaSettingsFactory.bypassGlobals(userName, false));
  assertNumResults(0, null);
}
 
Example 18
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetAndRemoveRegionServerQuota() throws Exception {
  Admin admin = TEST_UTIL.getAdmin();
  String regionServer = QuotaTableUtil.QUOTA_REGION_SERVER_ROW_KEY;
  QuotaFilter rsFilter = new QuotaFilter().setRegionServerFilter(regionServer);

  admin.setQuota(QuotaSettingsFactory.throttleRegionServer(regionServer,
    ThrottleType.REQUEST_NUMBER, 10, TimeUnit.MINUTES));
  assertNumResults(1, rsFilter);
  // Verify the Quota in the table
  verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_NUMBER, 10, TimeUnit.MINUTES);

  admin.setQuota(QuotaSettingsFactory.throttleRegionServer(regionServer,
    ThrottleType.REQUEST_NUMBER, 20, TimeUnit.MINUTES));
  assertNumResults(1, rsFilter);
  // Verify the Quota in the table
  verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_NUMBER, 20, TimeUnit.MINUTES);

  admin.setQuota(QuotaSettingsFactory.throttleRegionServer(regionServer, ThrottleType.READ_NUMBER,
    30, TimeUnit.SECONDS));
  int count = 0;
  QuotaRetriever scanner = QuotaRetriever.open(TEST_UTIL.getConfiguration(), rsFilter);
  try {
    for (QuotaSettings settings : scanner) {
      assertTrue(settings.getQuotaType() == QuotaType.THROTTLE);
      ThrottleSettings throttleSettings = (ThrottleSettings) settings;
      assertEquals(regionServer, throttleSettings.getRegionServer());
      count++;
      if (throttleSettings.getThrottleType() == ThrottleType.REQUEST_NUMBER) {
        assertEquals(20, throttleSettings.getSoftLimit());
        assertEquals(TimeUnit.MINUTES, throttleSettings.getTimeUnit());
      } else if (throttleSettings.getThrottleType() == ThrottleType.READ_NUMBER) {
        assertEquals(30, throttleSettings.getSoftLimit());
        assertEquals(TimeUnit.SECONDS, throttleSettings.getTimeUnit());
      }
    }
  } finally {
    scanner.close();
  }
  assertEquals(2, count);

  admin.setQuota(QuotaSettingsFactory.unthrottleRegionServer(regionServer));
  assertNumResults(0, new QuotaFilter().setRegionServerFilter(regionServer));
}
 
Example 19
Source File: TestQuotaThrottle.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testUserGlobalBypassThrottle() throws Exception {
  final Admin admin = TEST_UTIL.getAdmin();
  final String userName = User.getCurrent().getShortName();
  final String NAMESPACE = "default";

  // Add 6req/min limit for tables[0]
  admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], ThrottleType.REQUEST_NUMBER,
    6, TimeUnit.MINUTES));
  triggerTableCacheRefresh(TEST_UTIL, false, TABLE_NAMES[0]);
  // Add 13req/min limit for the user
  admin.setQuota(QuotaSettingsFactory.throttleNamespace(NAMESPACE, ThrottleType.REQUEST_NUMBER,
    13, TimeUnit.MINUTES));
  triggerNamespaceCacheRefresh(TEST_UTIL, false, TABLE_NAMES[1]);

  // should execute at max 6 requests on table[0] and (13 - 6) on table[1]
  assertEquals(6, doPuts(100, FAMILY, QUALIFIER, tables[0]));
  assertEquals(7, doGets(100, tables[1]));
  waitMinuteQuota();

  // Set the global bypass for the user
  admin.setQuota(QuotaSettingsFactory.bypassGlobals(userName, true));
  admin.setQuota(QuotaSettingsFactory.throttleUser(userName, TABLE_NAMES[2],
    ThrottleType.REQUEST_NUMBER, 6, TimeUnit.MINUTES));
  triggerUserCacheRefresh(TEST_UTIL, false, TABLE_NAMES[2]);
  assertEquals(30, doGets(30, tables[0]));
  assertEquals(30, doGets(30, tables[1]));
  waitMinuteQuota();

  // Remove the global bypass
  // should execute at max 6 requests on table[0] and (13 - 6) on table[1]
  admin.setQuota(QuotaSettingsFactory.bypassGlobals(userName, false));
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(userName, TABLE_NAMES[2]));
  triggerUserCacheRefresh(TEST_UTIL, true, TABLE_NAMES[2]);
  assertEquals(6, doPuts(100, FAMILY, QUALIFIER, tables[0]));
  assertEquals(7, doGets(100, tables[1]));

  // unset throttle
  admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
  admin.setQuota(QuotaSettingsFactory.unthrottleNamespace(NAMESPACE));
  waitMinuteQuota();
  triggerTableCacheRefresh(TEST_UTIL, true, TABLE_NAMES[0]);
  triggerNamespaceCacheRefresh(TEST_UTIL, true, TABLE_NAMES[1]);
  assertEquals(30, doGets(30, tables[0]));
  assertEquals(30, doGets(30, tables[1]));
}
 
Example 20
Source File: TestQuotaAdmin.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testQuotaScope() throws Exception {
  Admin admin = TEST_UTIL.getAdmin();
  String user = "user1";
  String namespace = "testQuotaScope_ns";
  TableName tableName = TableName.valueOf("testQuotaScope");
  QuotaFilter filter = new QuotaFilter();

  // set CLUSTER quota scope for namespace
  admin.setQuota(QuotaSettingsFactory.throttleNamespace(namespace, ThrottleType.REQUEST_NUMBER,
    10, TimeUnit.MINUTES, QuotaScope.CLUSTER));
  assertNumResults(1, filter);
  verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_NUMBER, 10, TimeUnit.MINUTES,
    QuotaScope.CLUSTER);
  admin.setQuota(QuotaSettingsFactory.throttleNamespace(namespace, ThrottleType.REQUEST_NUMBER,
    10, TimeUnit.MINUTES, QuotaScope.MACHINE));
  assertNumResults(1, filter);
  verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_NUMBER, 10, TimeUnit.MINUTES,
    QuotaScope.MACHINE);
  admin.setQuota(QuotaSettingsFactory.unthrottleNamespace(namespace));
  assertNumResults(0, filter);

  // set CLUSTER quota scope for table
  admin.setQuota(QuotaSettingsFactory.throttleTable(tableName, ThrottleType.REQUEST_NUMBER, 10,
    TimeUnit.MINUTES, QuotaScope.CLUSTER));
  verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_NUMBER, 10, TimeUnit.MINUTES,
    QuotaScope.CLUSTER);
  admin.setQuota(QuotaSettingsFactory.unthrottleTable(tableName));

  // set CLUSTER quota scope for user
  admin.setQuota(QuotaSettingsFactory.throttleUser(user, ThrottleType.REQUEST_NUMBER, 10,
    TimeUnit.MINUTES, QuotaScope.CLUSTER));
  verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_NUMBER, 10, TimeUnit.MINUTES,
    QuotaScope.CLUSTER);
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(user));

    // set CLUSTER quota scope for user and table
  admin.setQuota(QuotaSettingsFactory.throttleUser(user, tableName, ThrottleType.REQUEST_NUMBER,
    10, TimeUnit.MINUTES, QuotaScope.CLUSTER));
  verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_NUMBER, 10, TimeUnit.MINUTES,
    QuotaScope.CLUSTER);
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(user));

    // set CLUSTER quota scope for user and namespace
  admin.setQuota(QuotaSettingsFactory.throttleUser(user, namespace, ThrottleType.REQUEST_NUMBER,
    10, TimeUnit.MINUTES, QuotaScope.CLUSTER));
  verifyRecordPresentInQuotaTable(ThrottleType.REQUEST_NUMBER, 10, TimeUnit.MINUTES,
    QuotaScope.CLUSTER);
  admin.setQuota(QuotaSettingsFactory.unthrottleUser(user));
}