Search in sources :

Example 6 with SpaceQuotaStatus

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

the class TestTableQuotaViolationStore method testTargetViolationState.

@Test
public void testTargetViolationState() throws IOException {
    mockNoSnapshotSizes();
    TableName tn1 = TableName.valueOf("violation1");
    TableName tn2 = TableName.valueOf("observance1");
    TableName tn3 = TableName.valueOf("observance2");
    SpaceQuota quota = SpaceQuota.newBuilder().setSoftLimit(1024L * 1024L).setViolationPolicy(ProtobufUtil.toProtoViolationPolicy(SpaceViolationPolicy.DISABLE)).build();
    // immediately violate the quota.
    for (int i = 0; i < 3; i++) {
        regionReports.put(RegionInfoBuilder.newBuilder(tn2).setStartKey(Bytes.toBytes(i)).setEndKey(Bytes.toBytes(i + 1)).build(), 5L * ONE_MEGABYTE);
        regionReports.put(RegionInfoBuilder.newBuilder(tn3).setStartKey(Bytes.toBytes(i)).setEndKey(Bytes.toBytes(i + 1)).build(), 5L * ONE_MEGABYTE);
    }
    regionReports.put(RegionInfoBuilder.newBuilder(tn1).setStartKey(Bytes.toBytes(0)).setEndKey(Bytes.toBytes(1)).build(), 1024L * 512L);
    regionReports.put(RegionInfoBuilder.newBuilder(tn1).setStartKey(Bytes.toBytes(1)).setEndKey(Bytes.toBytes(2)).build(), 1024L * 256L);
    SpaceQuotaSnapshot tn1Snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 1024L * 768L, 1024L * 1024L);
    // Below the quota
    assertEquals(tn1Snapshot, store.getTargetState(tn1, quota));
    regionReports.put(RegionInfoBuilder.newBuilder(tn1).setStartKey(Bytes.toBytes(2)).setEndKey(Bytes.toBytes(3)).build(), 1024L * 256L);
    tn1Snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 1024L * 1024L, 1024L * 1024L);
    // Equal to the quota is still in observance
    assertEquals(tn1Snapshot, store.getTargetState(tn1, quota));
    regionReports.put(RegionInfoBuilder.newBuilder(tn1).setStartKey(Bytes.toBytes(3)).setEndKey(Bytes.toBytes(4)).build(), 1024L);
    tn1Snapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 1024L * 1024L + 1024L, 1024L * 1024L);
    // Exceeds the quota, should be in violation
    assertEquals(tn1Snapshot, store.getTargetState(tn1, quota));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) SpaceQuota(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota) Test(org.junit.Test)

Example 7 with SpaceQuotaStatus

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

the class TestTableSpaceQuotaViolationNotifier method testToViolation.

@Test
public void testToViolation() throws Exception {
    final TableName tn = TableName.valueOf("inviolation");
    final SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 1024L, 512L);
    final Table quotaTable = mock(Table.class);
    when(conn.getTable(QuotaTableUtil.QUOTA_TABLE_NAME)).thenReturn(quotaTable);
    final Put expectedPut = new Put(Bytes.toBytes("t." + tn.getNameAsString()));
    final QuotaProtos.SpaceQuotaSnapshot protoQuota = QuotaProtos.SpaceQuotaSnapshot.newBuilder().setQuotaStatus(QuotaProtos.SpaceQuotaStatus.newBuilder().setInViolation(true).setViolationPolicy(QuotaProtos.SpaceViolationPolicy.NO_INSERTS)).setQuotaLimit(512L).setQuotaUsage(1024L).build();
    expectedPut.addColumn(Bytes.toBytes("u"), Bytes.toBytes("p"), protoQuota.toByteArray());
    notifier.transitionTable(tn, snapshot);
    verify(quotaTable).put(argThat(new SingleCellMutationMatcher<Put>(expectedPut)));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) Table(org.apache.hadoop.hbase.client.Table) Put(org.apache.hadoop.hbase.client.Put) QuotaProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos) Test(org.junit.Test)

Example 8 with SpaceQuotaStatus

use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus 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)

Example 9 with SpaceQuotaStatus

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

the class TableQuotaSnapshotStore method getTargetState.

@Override
public SpaceQuotaSnapshot getTargetState(TableName table, SpaceQuota spaceQuota) throws IOException {
    rlock.lock();
    try {
        final long sizeLimitInBytes = spaceQuota.getSoftLimit();
        long sum = 0L;
        for (Entry<RegionInfo, Long> entry : filterBySubject(table)) {
            sum += entry.getValue();
        }
        // Add in the size for any snapshots against this table
        sum += getSnapshotSizesForTable(table);
        // Observance is defined as the size of the table being less than the limit
        SpaceQuotaStatus status = sum <= sizeLimitInBytes ? SpaceQuotaStatus.notInViolation() : new SpaceQuotaStatus(ProtobufUtil.toViolationPolicy(spaceQuota.getViolationPolicy()));
        return new SpaceQuotaSnapshot(status, sum, sizeLimitInBytes);
    } finally {
        rlock.unlock();
    }
}
Also used : SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo)

Example 10 with SpaceQuotaStatus

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

the class NamespaceQuotaSnapshotStore method getTargetState.

@Override
public SpaceQuotaSnapshot getTargetState(String subject, SpaceQuota spaceQuota) throws IOException {
    rlock.lock();
    try {
        final long sizeLimitInBytes = spaceQuota.getSoftLimit();
        long sum = 0L;
        for (Entry<RegionInfo, Long> entry : filterBySubject(subject)) {
            sum += entry.getValue();
        }
        // Add in the size for any snapshots against this table
        sum += QuotaTableUtil.getNamespaceSnapshotSize(conn, subject);
        // Observance is defined as the size of the table being less than the limit
        SpaceQuotaStatus status = sum <= sizeLimitInBytes ? SpaceQuotaStatus.notInViolation() : new SpaceQuotaStatus(ProtobufUtil.toViolationPolicy(spaceQuota.getViolationPolicy()));
        return new SpaceQuotaSnapshot(status, sum, sizeLimitInBytes);
    } finally {
        rlock.unlock();
    }
}
Also used : SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo)

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