@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(); }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasQuota()) { hash = (37 * hash) + QUOTA_FIELD_NUMBER; hash = (53 * hash) + getQuota().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@Override protected QuotaSettings merge(QuotaSettings newSettings) { if (newSettings instanceof SpaceLimitSettings) { SpaceLimitSettings settingsToMerge = (SpaceLimitSettings) newSettings; // The message contained the expect SpaceQuota object if (settingsToMerge.proto.hasQuota()) { SpaceQuota quotaToMerge = settingsToMerge.proto.getQuota(); if (quotaToMerge.getRemove()) { return settingsToMerge; } else { // Validate that the two settings are for the same target. // SpaceQuotas either apply to a table or a namespace (no user spacequota). if (!Objects.equals(getTableName(), settingsToMerge.getTableName()) && !Objects.equals(getNamespace(), settingsToMerge.getNamespace())) { throw new IllegalArgumentException("Cannot merge " + newSettings + " into " + this); } // Create a builder from the old settings SpaceQuota.Builder mergedBuilder = this.proto.getQuota().toBuilder(); // Build a new SpaceQuotas object from merging in the new settings return new SpaceLimitSettings( getTableName(), getNamespace(), buildProtoFromQuota(mergedBuilder.mergeFrom(quotaToMerge).build())); } } // else, we don't know what to do, so return the original object } return this; }
@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()); }
@Test public void testSpaceLimitSettingsForDeletes() { final String ns = "ns1"; final TableName tn = TableName.valueOf("tn1"); QuotaSettings nsSettings = QuotaSettingsFactory.removeNamespaceSpaceLimit(ns); assertNotNull("QuotaSettings should not be null", nsSettings); assertTrue("Should be an instance of SpaceLimitSettings", nsSettings instanceof SpaceLimitSettings); SpaceLimitRequest nsProto = ((SpaceLimitSettings) nsSettings).getProto(); assertTrue("Request should have a SpaceQuota", nsProto.hasQuota()); assertTrue("The remove attribute should be true", nsProto.getQuota().getRemove()); QuotaSettings tableSettings = QuotaSettingsFactory.removeTableSpaceLimit(tn); assertNotNull("QuotaSettings should not be null", tableSettings); assertTrue("Should be an instance of SpaceLimitSettings", tableSettings instanceof SpaceLimitSettings); SpaceLimitRequest tableProto = ((SpaceLimitSettings) tableSettings).getProto(); assertTrue("Request should have a SpaceQuota", tableProto.hasQuota()); assertTrue("The remove attribute should be true", tableProto.getQuota().getRemove()); } }
@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(); }
@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()); }
SpaceQuota quotaToMerge = spaceRequest.getQuota();
assertNull("RegionServer should be null", spaceLimit.getRegionServer()); assertTrue("SpaceLimitSettings should have a SpaceQuota", spaceLimit.getProto().hasQuota()); assertEquals(spaceQuota, spaceLimit.getProto().getQuota()); seenSpace = true; } else {
tableName, namespace, request.getSpaceLimit().getQuota()); } else if (request.hasThrottle()) { return new ThrottleSettings(username, tableName, namespace, regionServer,
@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)); }
@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()); }
@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 testSpaceLimitSettingsForDeletes() { final String ns = "ns1"; final TableName tn = TableName.valueOf("tn1"); QuotaSettings nsSettings = QuotaSettingsFactory.removeNamespaceSpaceLimit(ns); assertNotNull("QuotaSettings should not be null", nsSettings); assertTrue("Should be an instance of SpaceLimitSettings", nsSettings instanceof SpaceLimitSettings); SpaceLimitRequest nsProto = ((SpaceLimitSettings) nsSettings).getProto(); assertTrue("Request should have a SpaceQuota", nsProto.hasQuota()); assertTrue("The remove attribute should be true", nsProto.getQuota().getRemove()); QuotaSettings tableSettings = QuotaSettingsFactory.removeTableSpaceLimit(tn); assertNotNull("QuotaSettings should not be null", tableSettings); assertTrue("Should be an instance of SpaceLimitSettings", tableSettings instanceof SpaceLimitSettings); SpaceLimitRequest tableProto = ((SpaceLimitSettings) tableSettings).getProto(); assertTrue("Request should have a SpaceQuota", tableProto.hasQuota()); assertTrue("The remove attribute should be true", tableProto.getQuota().getRemove()); } }
@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.SpaceLimitRequest)) { return super.equals(obj); } org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceLimitRequest other = (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceLimitRequest) obj; boolean result = true; result = result && (hasQuota() == other.hasQuota()); if (hasQuota()) { result = result && getQuota() .equals(other.getQuota()); } result = result && unknownFields.equals(other.unknownFields); return result; }
@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 void writeTo(org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeMessage(1, getQuota()); } unknownFields.writeTo(output); }
public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream .computeMessageSize(1, getQuota()); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
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())); }
public Builder mergeFrom(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceLimitRequest other) { if (other == org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceLimitRequest.getDefaultInstance()) return this; if (other.hasQuota()) { mergeQuota(other.getQuota()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }