Search in sources :

Example 16 with SpaceQuotaStatus

use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus in project hbase by apache.

the class TestQuotaStatusRPCs method testQuotaSnapshotsFromRS.

@Test
public void testQuotaSnapshotsFromRS() throws Exception {
    // 1MB
    final long sizeLimit = 1024L * 1024L;
    // 10KB
    final long tableSize = 1024L * 10L;
    final int numRegions = 10;
    final TableName tn = helper.createTableWithRegions(numRegions);
    // Define the quota
    QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tn, sizeLimit, SpaceViolationPolicy.NO_INSERTS);
    TEST_UTIL.getAdmin().setQuota(settings);
    // Write at least `tableSize` data
    helper.writeData(tn, tableSize);
    final HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
    final RegionServerSpaceQuotaManager manager = rs.getRegionServerSpaceQuotaManager();
    Waiter.waitFor(TEST_UTIL.getConfiguration(), 30 * 1000, new Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            SpaceQuotaSnapshot snapshot = manager.copyQuotaSnapshots().get(tn);
            if (snapshot == null) {
                return false;
            }
            return snapshot.getUsage() >= tableSize;
        }
    });
    @SuppressWarnings("unchecked") Map<TableName, SpaceQuotaSnapshot> snapshots = (Map<TableName, SpaceQuotaSnapshot>) TEST_UTIL.getAdmin().getRegionServerSpaceQuotaSnapshots(rs.getServerName());
    SpaceQuotaSnapshot snapshot = snapshots.get(tn);
    assertNotNull("Did not find snapshot for " + tn, snapshot);
    assertTrue("Observed table usage was " + snapshot.getUsage(), snapshot.getUsage() >= tableSize);
    assertEquals(sizeLimit, snapshot.getLimit());
    SpaceQuotaStatus pbStatus = snapshot.getQuotaStatus();
    assertFalse(pbStatus.isInViolation());
}
Also used : SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) RetriesExhaustedWithDetailsException(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TableName(org.apache.hadoop.hbase.TableName) Map(java.util.Map) Test(org.junit.Test)

Example 17 with SpaceQuotaStatus

use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus in project hbase by apache.

the class TestQuotaTableUtil method testSerDeViolationPolicies.

@Test
public void testSerDeViolationPolicies() throws Exception {
    final TableName tn1 = getUniqueTableName();
    final SpaceQuotaSnapshot snapshot1 = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 512L, 1024L);
    final TableName tn2 = getUniqueTableName();
    final SpaceQuotaSnapshot snapshot2 = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 512L, 1024L);
    final TableName tn3 = getUniqueTableName();
    final SpaceQuotaSnapshot snapshot3 = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 512L, 1024L);
    List<Put> puts = new ArrayList<>();
    puts.add(QuotaTableUtil.createPutForSpaceSnapshot(tn1, snapshot1));
    puts.add(QuotaTableUtil.createPutForSpaceSnapshot(tn2, snapshot2));
    puts.add(QuotaTableUtil.createPutForSpaceSnapshot(tn3, snapshot3));
    final Map<TableName, SpaceQuotaSnapshot> expectedPolicies = new HashMap<>();
    expectedPolicies.put(tn1, snapshot1);
    expectedPolicies.put(tn2, snapshot2);
    expectedPolicies.put(tn3, snapshot3);
    final Map<TableName, SpaceQuotaSnapshot> actualPolicies = new HashMap<>();
    try (Table quotaTable = connection.getTable(QuotaUtil.QUOTA_TABLE_NAME)) {
        quotaTable.put(puts);
        ResultScanner scanner = quotaTable.getScanner(QuotaTableUtil.makeQuotaSnapshotScan());
        for (Result r : scanner) {
            QuotaTableUtil.extractQuotaSnapshot(r, actualPolicies);
        }
        scanner.close();
    }
    assertEquals(expectedPolicies, actualPolicies);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

SpaceQuotaStatus (org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus)17 TableName (org.apache.hadoop.hbase.TableName)9 Test (org.junit.Test)9 IOException (java.io.IOException)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 HashMap (java.util.HashMap)2 Put (org.apache.hadoop.hbase.client.Put)2 Table (org.apache.hadoop.hbase.client.Table)2 SpaceQuotaSnapshot (org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot)2 DefaultViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.DefaultViolationPolicyEnforcement)2 DisableTableViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.DisableTableViolationPolicyEnforcement)2 NoInsertsViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.NoInsertsViolationPolicyEnforcement)2 NoWritesCompactionsViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.NoWritesCompactionsViolationPolicyEnforcement)2 NoWritesViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.NoWritesViolationPolicyEnforcement)2 RegionServerServices (org.apache.hadoop.hbase.regionserver.RegionServerServices)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Result (org.apache.hadoop.hbase.client.Result)1 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)1 RetriesExhaustedWithDetailsException (org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException)1