Search in sources :

Example 1 with DisableTableViolationPolicyEnforcement

use of org.apache.hadoop.hbase.quotas.policies.DisableTableViolationPolicyEnforcement in project hbase by apache.

the class TestRegionServerSpaceQuotaManager method testSpacePoliciesFromEnforcements.

@Test
public void testSpacePoliciesFromEnforcements() {
    final Map<TableName, SpaceViolationPolicyEnforcement> enforcements = new HashMap<>();
    final Map<TableName, SpaceQuotaSnapshot> expectedPolicies = new HashMap<>();
    when(quotaManager.copyActiveEnforcements()).thenReturn(enforcements);
    when(quotaManager.getActivePoliciesAsMap()).thenCallRealMethod();
    NoInsertsViolationPolicyEnforcement noInsertsPolicy = new NoInsertsViolationPolicyEnforcement();
    SpaceQuotaSnapshot noInsertsSnapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 256L, 1024L);
    noInsertsPolicy.initialize(rss, TableName.valueOf("no_inserts"), noInsertsSnapshot);
    enforcements.put(noInsertsPolicy.getTableName(), noInsertsPolicy);
    expectedPolicies.put(noInsertsPolicy.getTableName(), noInsertsSnapshot);
    NoWritesViolationPolicyEnforcement noWritesPolicy = new NoWritesViolationPolicyEnforcement();
    SpaceQuotaSnapshot noWritesSnapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 512L, 2048L);
    noWritesPolicy.initialize(rss, TableName.valueOf("no_writes"), noWritesSnapshot);
    enforcements.put(noWritesPolicy.getTableName(), noWritesPolicy);
    expectedPolicies.put(noWritesPolicy.getTableName(), noWritesSnapshot);
    NoWritesCompactionsViolationPolicyEnforcement noWritesCompactionsPolicy = new NoWritesCompactionsViolationPolicyEnforcement();
    SpaceQuotaSnapshot noWritesCompactionsSnapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES_COMPACTIONS), 1024L, 4096L);
    noWritesCompactionsPolicy.initialize(rss, TableName.valueOf("no_writes_compactions"), noWritesCompactionsSnapshot);
    enforcements.put(noWritesCompactionsPolicy.getTableName(), noWritesCompactionsPolicy);
    expectedPolicies.put(noWritesCompactionsPolicy.getTableName(), noWritesCompactionsSnapshot);
    DisableTableViolationPolicyEnforcement disablePolicy = new DisableTableViolationPolicyEnforcement();
    SpaceQuotaSnapshot disableSnapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 2048L, 8192L);
    disablePolicy.initialize(rss, TableName.valueOf("disable"), disableSnapshot);
    enforcements.put(disablePolicy.getTableName(), disablePolicy);
    expectedPolicies.put(disablePolicy.getTableName(), disableSnapshot);
    enforcements.put(TableName.valueOf("no_policy"), new DefaultViolationPolicyEnforcement());
    Map<TableName, SpaceQuotaSnapshot> actualPolicies = quotaManager.getActivePoliciesAsMap();
    assertEquals(expectedPolicies, actualPolicies);
}
Also used : DefaultViolationPolicyEnforcement(org.apache.hadoop.hbase.quotas.policies.DefaultViolationPolicyEnforcement) TableName(org.apache.hadoop.hbase.TableName) SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) NoInsertsViolationPolicyEnforcement(org.apache.hadoop.hbase.quotas.policies.NoInsertsViolationPolicyEnforcement) DisableTableViolationPolicyEnforcement(org.apache.hadoop.hbase.quotas.policies.DisableTableViolationPolicyEnforcement) HashMap(java.util.HashMap) NoWritesViolationPolicyEnforcement(org.apache.hadoop.hbase.quotas.policies.NoWritesViolationPolicyEnforcement) NoWritesCompactionsViolationPolicyEnforcement(org.apache.hadoop.hbase.quotas.policies.NoWritesCompactionsViolationPolicyEnforcement) Test(org.junit.Test)

Example 2 with DisableTableViolationPolicyEnforcement

use of org.apache.hadoop.hbase.quotas.policies.DisableTableViolationPolicyEnforcement in project hbase by apache.

the class SpaceViolationPolicyEnforcementFactory method create.

/**
 * Constructs the appropriate {@link SpaceViolationPolicyEnforcement} for tables that are
 * in violation of their space quota.
 */
public SpaceViolationPolicyEnforcement create(RegionServerServices rss, TableName tableName, SpaceQuotaSnapshot snapshot) {
    SpaceViolationPolicyEnforcement enforcement;
    SpaceQuotaStatus status = snapshot.getQuotaStatus();
    if (!status.isInViolation()) {
        throw new IllegalArgumentException(tableName + " is not in violation. Snapshot=" + snapshot);
    }
    switch(status.getPolicy().get()) {
        case DISABLE:
            enforcement = new DisableTableViolationPolicyEnforcement();
            break;
        case NO_WRITES_COMPACTIONS:
            enforcement = new NoWritesCompactionsViolationPolicyEnforcement();
            break;
        case NO_WRITES:
            enforcement = new NoWritesViolationPolicyEnforcement();
            break;
        case NO_INSERTS:
            enforcement = new NoInsertsViolationPolicyEnforcement();
            break;
        default:
            throw new IllegalArgumentException("Unhandled SpaceViolationPolicy: " + status.getPolicy());
    }
    enforcement.initialize(rss, tableName, snapshot);
    return enforcement;
}
Also used : SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) NoInsertsViolationPolicyEnforcement(org.apache.hadoop.hbase.quotas.policies.NoInsertsViolationPolicyEnforcement) DisableTableViolationPolicyEnforcement(org.apache.hadoop.hbase.quotas.policies.DisableTableViolationPolicyEnforcement) NoWritesViolationPolicyEnforcement(org.apache.hadoop.hbase.quotas.policies.NoWritesViolationPolicyEnforcement) NoWritesCompactionsViolationPolicyEnforcement(org.apache.hadoop.hbase.quotas.policies.NoWritesCompactionsViolationPolicyEnforcement)

Aggregations

SpaceQuotaStatus (org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus)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 HashMap (java.util.HashMap)1 TableName (org.apache.hadoop.hbase.TableName)1 DefaultViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.DefaultViolationPolicyEnforcement)1 Test (org.junit.Test)1