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));
}
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)));
}
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;
}
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();
}
}
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();
}
}
Aggregations