@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(); }
builder.append(", REMOVE => ").append(spaceProto.getRemove()); } else { builder.append(", LIMIT => ").append(sizeToString(spaceProto.getSoftLimit())); builder.append(", VIOLATION_POLICY => ").append(spaceProto.getViolationPolicy());
@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 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()); }
/** * 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())); }
out.print( StringUtils.byteDesc(spaceQuota.getSoftLimit()) ); out.write("</td>\n </tr>\n <tr>\n <td>Policy</td>\n <td>"); out.print( spaceQuota.getViolationPolicy() );
new ThrottleSettings(null, null, ns, null, writeThrottle)); GlobalQuotaSettingsImpl finalQuota = merged.merge(new SpaceLimitSettings( ns, SPACE_QUOTA.getSoftLimit(), SpaceViolationPolicy.NO_WRITES_COMPACTIONS)); assertEquals(SPACE_QUOTA.getSoftLimit(), finalSpaceQuota.getSoftLimit()); assertEquals( QuotaProtos.SpaceViolationPolicy.NO_WRITES_COMPACTIONS,
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota)) { return super.equals(obj); } org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota other = (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota) obj; boolean result = true; result = result && (hasSoftLimit() == other.hasSoftLimit()); if (hasSoftLimit()) { result = result && (getSoftLimit() == other.getSoftLimit()); } result = result && (hasViolationPolicy() == other.hasViolationPolicy()); if (hasViolationPolicy()) { result = result && violationPolicy_ == other.violationPolicy_; } result = result && (hasRemove() == other.hasRemove()); if (hasRemove()) { result = result && (getRemove() == other.getRemove()); } result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasSoftLimit()) { hash = (37 * hash) + SOFT_LIMIT_FIELD_NUMBER; hash = (53 * hash) + org.apache.hbase.thirdparty.com.google.protobuf.Internal.hashLong( getSoftLimit()); } if (hasViolationPolicy()) { hash = (37 * hash) + VIOLATION_POLICY_FIELD_NUMBER; hash = (53 * hash) + violationPolicy_; } if (hasRemove()) { hash = (37 * hash) + REMOVE_FIELD_NUMBER; hash = (53 * hash) + org.apache.hbase.thirdparty.com.google.protobuf.Internal.hashBoolean( getRemove()); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@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(); } }
@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 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())); }
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())); }
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())); }