Search in sources :

Example 11 with SpaceQuota

use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.

the class TestSpaceLimitSettings method testTableQuota.

@Test
public void testTableQuota() {
    final TableName tableName = TableName.valueOf("foo");
    final long sizeLimit = 1024 * 1024;
    final SpaceViolationPolicy policy = SpaceViolationPolicy.NO_WRITES;
    SpaceLimitSettings settings = new SpaceLimitSettings(tableName, sizeLimit, policy);
    SetQuotaRequest proto = QuotaSettings.buildSetQuotaRequestProto(settings);
    assertFalse("User should be missing", proto.hasUserName());
    assertFalse("Namespace should be missing", proto.hasNamespace());
    assertEquals(ProtobufUtil.toProtoTableName(tableName), proto.getTableName());
    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(tableName, sizeLimit, policy);
    assertEquals(settings, copy);
    assertEquals(settings.hashCode(), copy.hashCode());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) SpaceQuota(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota) SpaceLimitRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceLimitRequest) SetQuotaRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetQuotaRequest) Test(org.junit.Test)

Example 12 with SpaceQuota

use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.

the class TestNamespaceQuotaViolationStore method testTargetViolationState.

@Test
public void testTargetViolationState() throws IOException {
    mockNoSnapshotSizes();
    final String NS = "ns";
    TableName tn1 = TableName.valueOf(NS, "tn1");
    TableName tn2 = TableName.valueOf(NS, "tn2");
    TableName tn3 = TableName.valueOf("tn3");
    SpaceQuota quota = SpaceQuota.newBuilder().setSoftLimit(ONE_MEGABYTE).setViolationPolicy(ProtobufUtil.toProtoViolationPolicy(SpaceViolationPolicy.DISABLE)).build();
    // immediately violate the quota.
    for (int i = 0; i < 3; i++) {
        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);
    // Below the quota
    assertEquals(false, store.getTargetState(NS, quota).getQuotaStatus().isInViolation());
    regionReports.put(RegionInfoBuilder.newBuilder(tn2).setStartKey(Bytes.toBytes(2)).setEndKey(Bytes.toBytes(3)).build(), 1024L * 256L);
    // Equal to the quota is still in observance
    assertEquals(false, store.getTargetState(NS, quota).getQuotaStatus().isInViolation());
    regionReports.put(RegionInfoBuilder.newBuilder(tn2).setStartKey(Bytes.toBytes(3)).setEndKey(Bytes.toBytes(4)).build(), 1024L);
    // Exceeds the quota, should be in violation
    assertEquals(true, store.getTargetState(NS, quota).getQuotaStatus().isInViolation());
    assertEquals(SpaceViolationPolicy.DISABLE, store.getTargetState(NS, quota).getQuotaStatus().getPolicy().get());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) SpaceQuota(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota) Test(org.junit.Test)

Aggregations

SpaceQuota (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota)12 Test (org.junit.Test)9 TableName (org.apache.hadoop.hbase.TableName)7 SpaceLimitRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceLimitRequest)3 SetQuotaRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetQuotaRequest)2 Throttle (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Throttle)2 QuotaGlobalsSettingsBypass (org.apache.hadoop.hbase.quotas.QuotaSettingsFactory.QuotaGlobalsSettingsBypass)1 SpaceQuotaStatus (org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus)1 QuotaProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos)1 Quotas (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas)1