@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("TYPE => SPACE"); if (getTableName() != null) { sb.append(", TABLE => ").append(getTableName()); } if (getNamespace() != null) { sb.append(", NAMESPACE => ").append(getNamespace()); } if (proto.getQuota().getRemove()) { sb.append(", REMOVE => ").append(proto.getQuota().getRemove()); } else { sb.append(", LIMIT => ").append(sizeToString(proto.getQuota().getSoftLimit())); sb.append(", VIOLATION_POLICY => ").append(proto.getQuota().getViolationPolicy()); } return sb.toString(); }
} else { builder.append(", LIMIT => ").append(sizeToString(spaceProto.getSoftLimit())); builder.append(", VIOLATION_POLICY => ").append(spaceProto.getViolationPolicy());
protected static SpaceViolationPolicy getViolationPolicy(SpaceQuota proto) { if (!proto.hasViolationPolicy()) { throw new IllegalArgumentException("Protobuf SpaceQuota does not have violation policy."); } return ProtobufUtil.toViolationPolicy(proto.getViolationPolicy()); }
/** * Constructs a {@link SpaceLimitSettings} from the provided protobuf message and namespace. * * @param namespace The target namespace for the limit. * @param proto The protobuf representation. * @return A QuotaSettings. */ static SpaceLimitSettings fromSpaceQuota( final String namespace, final QuotaProtos.SpaceQuota proto) { validateProtoArguments(proto); return new SpaceLimitSettings(namespace, proto.getSoftLimit(), ProtobufUtil.toViolationPolicy(proto.getViolationPolicy())); }
/** * Constructs a {@link SpaceLimitSettings} from the provided protobuf message and tablename. * * @param tableName The target tablename for the limit. * @param proto The protobuf representation. * @return A QuotaSettings. */ static SpaceLimitSettings fromSpaceQuota( final TableName tableName, final QuotaProtos.SpaceQuota proto) { validateProtoArguments(proto); return new SpaceLimitSettings(tableName, proto.getSoftLimit(), ProtobufUtil.toViolationPolicy(proto.getViolationPolicy())); }
protected static SpaceViolationPolicy getViolationPolicy(SpaceQuota proto) { if (!proto.hasViolationPolicy()) { throw new IllegalArgumentException("Protobuf SpaceQuota does not have violation policy."); } return ProtobufUtil.toViolationPolicy(proto.getViolationPolicy()); }
out.print( StringUtils.byteDesc(spaceQuota.getSoftLimit()) ); out.write("</td>\n </tr>\n <tr>\n <td>Policy</td>\n <td>"); out.print( spaceQuota.getViolationPolicy() ); out.write("</td>\n </tr>\n");
Quotas quotaForTable = QuotaUtil.getTableQuota(getConnection(), tableName); if (quotaForTable != null && quotaForTable.hasSpace()) { SpaceViolationPolicy policy = quotaForTable.getSpace().getViolationPolicy(); if (SpaceViolationPolicy.DISABLE == policy) { throw new AccessDeniedException("Enabling the table '" + tableName
assertEquals( QuotaProtos.SpaceViolationPolicy.NO_WRITES_COMPACTIONS, finalSpaceQuota.getViolationPolicy());
@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()); }
@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(); } }
@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(); } }
@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()); }
@Test public void testSpaceLimitSettings() { final TableName tableName = TableName.valueOf("foo"); final long sizeLimit = 1024L * 1024L * 1024L * 75; // 75GB 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()); }
public Builder mergeFrom(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota other) { if (other == org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota.getDefaultInstance()) return this; if (other.hasSoftLimit()) { setSoftLimit(other.getSoftLimit()); } if (other.hasViolationPolicy()) { setViolationPolicy(other.getViolationPolicy()); } if (other.hasRemove()) { setRemove(other.getRemove()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@Test public void testMergeSpace() throws IOException { TableName tn = TableName.valueOf("foo"); QuotaProtos.Quotas quota = QuotaProtos.Quotas.newBuilder() .setSpace(SPACE_QUOTA).build(); GlobalQuotaSettingsImpl settings = new GlobalQuotaSettingsImpl(null, tn, null, null, quota); // Switch the violation policy to DISABLE GlobalQuotaSettingsImpl merged = settings.merge( new SpaceLimitSettings(tn, SPACE_QUOTA.getSoftLimit(), SpaceViolationPolicy.DISABLE)); QuotaProtos.SpaceQuota mergedSpaceQuota = merged.getSpaceProto(); assertEquals(SPACE_QUOTA.getSoftLimit(), mergedSpaceQuota.getSoftLimit()); assertEquals( QuotaProtos.SpaceViolationPolicy.DISABLE, mergedSpaceQuota.getViolationPolicy()); }
/** * Constructs a {@link SpaceLimitSettings} from the provided protobuf message and tablename. * * @param tableName The target tablename for the limit. * @param proto The protobuf representation. * @return A QuotaSettings. */ static SpaceLimitSettings fromSpaceQuota( final TableName tableName, final QuotaProtos.SpaceQuota proto) { validateProtoArguments(proto); return new SpaceLimitSettings(tableName, proto.getSoftLimit(), ProtobufUtil.toViolationPolicy(proto.getViolationPolicy())); }
/** * Constructs a {@link SpaceLimitSettings} from the provided protobuf message and namespace. * * @param namespace The target namespace for the limit. * @param proto The protobuf representation. * @return A QuotaSettings. */ static SpaceLimitSettings fromSpaceQuota( final String namespace, final QuotaProtos.SpaceQuota proto) { validateProtoArguments(proto); return new SpaceLimitSettings(namespace, proto.getSoftLimit(), ProtobufUtil.toViolationPolicy(proto.getViolationPolicy())); }
private void assertSpaceQuota( long sizeLimit, SpaceViolationPolicy violationPolicy, Cell cell) throws Exception { Quotas q = QuotaTableUtil.quotasFromData( cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); assertTrue("Quota should have space quota defined", q.hasSpace()); QuotaProtos.SpaceQuota spaceQuota = q.getSpace(); assertEquals(sizeLimit, spaceQuota.getSoftLimit()); assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(spaceQuota.getViolationPolicy())); }
private void assertSpaceQuota( long sizeLimit, SpaceViolationPolicy violationPolicy, QuotaSettings actualSettings) { assertTrue("The actual QuotaSettings was not an instance of " + SpaceLimitSettings.class + " but of " + actualSettings.getClass(), actualSettings instanceof SpaceLimitSettings); SpaceLimitRequest spaceLimitRequest = ((SpaceLimitSettings) actualSettings).getProto(); assertEquals(sizeLimit, spaceLimitRequest.getQuota().getSoftLimit()); assertEquals(violationPolicy, ProtobufUtil.toViolationPolicy(spaceLimitRequest.getQuota().getViolationPolicy())); }