use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota 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.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.
the class TestQuotaObserverChoreWithMiniCluster method testFetchSpaceQuota.
@Test
public void testFetchSpaceQuota() throws Exception {
Multimap<TableName, QuotaSettings> tables = helper.createTablesWithSpaceQuotas();
// Can pass in an empty map, we're not consulting it.
chore.initializeSnapshotStores(Collections.emptyMap());
// All tables that were created should have a quota defined.
for (Entry<TableName, QuotaSettings> entry : tables.entries()) {
final TableName table = entry.getKey();
final QuotaSettings qs = entry.getValue();
assertTrue("QuotaSettings was an instance of " + qs.getClass(), qs instanceof SpaceLimitSettings);
SpaceQuota spaceQuota = null;
if (qs.getTableName() != null) {
spaceQuota = chore.getTableSnapshotStore().getSpaceQuota(table);
assertNotNull("Could not find table space quota for " + table, spaceQuota);
} else if (qs.getNamespace() != null) {
spaceQuota = chore.getNamespaceSnapshotStore().getSpaceQuota(table.getNamespaceAsString());
assertNotNull("Could not find namespace space quota for " + table.getNamespaceAsString(), spaceQuota);
} else {
fail("Expected table or namespace space quota");
}
final SpaceLimitSettings sls = (SpaceLimitSettings) qs;
assertEquals(sls.getProto().getQuota(), spaceQuota);
}
TableName tableWithoutQuota = helper.createTable();
assertNull(chore.getTableSnapshotStore().getSpaceQuota(tableWithoutQuota));
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.
the class TestQuotaSettingsFactory method testNeitherTableNorNamespace.
@Test(expected = IllegalArgumentException.class)
public void testNeitherTableNorNamespace() {
final SpaceQuota spaceQuota = SpaceQuota.newBuilder().setSoftLimit(1L).setViolationPolicy(QuotaProtos.SpaceViolationPolicy.DISABLE).build();
QuotaSettingsFactory.fromSpace(null, null, spaceQuota);
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.
the class TestQuotaSettingsFactory method testSpaceLimitSettings.
@Test
public void testSpaceLimitSettings() {
final TableName tableName = TableName.valueOf("foo");
// 75GB
final long sizeLimit = 1024L * 1024L * 1024L * 75;
final SpaceViolationPolicy violationPolicy = SpaceViolationPolicy.NO_INSERTS;
QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tableName, sizeLimit, violationPolicy);
assertNotNull("QuotaSettings should not be null", settings);
assertTrue("Should be an instance of SpaceLimitSettings", settings instanceof SpaceLimitSettings);
SpaceLimitSettings spaceLimitSettings = (SpaceLimitSettings) settings;
SpaceLimitRequest protoRequest = spaceLimitSettings.getProto();
assertTrue("Request should have a SpaceQuota", protoRequest.hasQuota());
SpaceQuota quota = protoRequest.getQuota();
assertEquals(sizeLimit, quota.getSoftLimit());
assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(quota.getViolationPolicy()));
assertFalse("The remove attribute should be false", quota.getRemove());
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.
the class TestSpaceLimitSettings method testNamespaceQuota.
@Test
public void testNamespaceQuota() {
final String namespace = "foo_ns";
final long sizeLimit = 1024 * 1024;
final SpaceViolationPolicy policy = SpaceViolationPolicy.NO_WRITES;
SpaceLimitSettings settings = new SpaceLimitSettings(namespace, sizeLimit, policy);
SetQuotaRequest proto = QuotaSettings.buildSetQuotaRequestProto(settings);
assertFalse("User should be missing", proto.hasUserName());
assertFalse("TableName should be missing", proto.hasTableName());
assertEquals(namespace, proto.getNamespace());
SpaceLimitRequest spaceLimitReq = proto.getSpaceLimit();
assertNotNull("SpaceLimitRequest was null", spaceLimitReq);
SpaceQuota spaceQuota = spaceLimitReq.getQuota();
assertNotNull("SpaceQuota was null", spaceQuota);
assertEquals(sizeLimit, spaceQuota.getSoftLimit());
assertEquals(ProtobufUtil.toProtoViolationPolicy(policy), spaceQuota.getViolationPolicy());
assertEquals(QuotaType.SPACE, settings.getQuotaType());
SpaceLimitSettings copy = new SpaceLimitSettings(namespace, sizeLimit, policy);
assertEquals(settings, copy);
assertEquals(settings.hashCode(), copy.hashCode());
}
Aggregations