SpaceQuotaSnapshot masterSnapshot = null; Quotas quota = QuotaTableUtil.getTableQuota(master.getConnection(), tn); if (quota == null || !quota.hasSpace()) { quota = QuotaTableUtil.getNamespaceQuota(master.getConnection(), tn.getNamespaceAsString()); if (quota != null) { masterSnapshot = master.getQuotaObserverChore().getTableQuotaSnapshots().get(tn); if (quota != null && quota.hasSpace()) { SpaceQuota spaceQuota = quota.getSpace();
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasBypassGlobals()) { hash = (37 * hash) + BYPASS_GLOBALS_FIELD_NUMBER; hash = (53 * hash) + org.apache.hbase.thirdparty.com.google.protobuf.Internal.hashBoolean( getBypassGlobals()); } if (hasThrottle()) { hash = (37 * hash) + THROTTLE_FIELD_NUMBER; hash = (53 * hash) + getThrottle().hashCode(); } if (hasSpace()) { hash = (37 * hash) + SPACE_FIELD_NUMBER; hash = (53 * hash) + getSpace().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@Test public void testGetSpaceQuota() throws Exception { NamespaceQuotaSnapshotStore mockStore = mock(NamespaceQuotaSnapshotStore.class); when(mockStore.getSpaceQuota(any())).thenCallRealMethod(); Quotas quotaWithSpace = Quotas.newBuilder().setSpace( SpaceQuota.newBuilder() .setSoftLimit(1024L) .setViolationPolicy(QuotaProtos.SpaceViolationPolicy.DISABLE) .build()) .build(); Quotas quotaWithoutSpace = Quotas.newBuilder().build(); AtomicReference<Quotas> quotaRef = new AtomicReference<>(); when(mockStore.getQuotaForNamespace(any())).then(new Answer<Quotas>() { @Override public Quotas answer(InvocationOnMock invocation) throws Throwable { return quotaRef.get(); } }); quotaRef.set(quotaWithSpace); assertEquals(quotaWithSpace.getSpace(), mockStore.getSpaceQuota("ns")); quotaRef.set(quotaWithoutSpace); assertNull(mockStore.getSpaceQuota("ns")); }
final String user = "testUser"; Quotas quotaNamespace = Quotas.newBuilder() .setThrottle(Throttle.newBuilder() .setReqNum(ProtobufUtil.toTimedQuota(50000, TimeUnit.SECONDS, QuotaScope.MACHINE)) .build()) .build(); Quotas quotaTable = Quotas.newBuilder() .setThrottle(Throttle.newBuilder() .setReqNum(ProtobufUtil.toTimedQuota(1000, TimeUnit.SECONDS, QuotaScope.MACHINE)) .build()) .build(); Quotas quota = Quotas.newBuilder() .setThrottle(Throttle.newBuilder() .setReqSize(ProtobufUtil.toTimedQuota(8192, TimeUnit.SECONDS, QuotaScope.MACHINE))
@Test public void testMergeThrottleAndSpace() throws IOException { final String ns = "org1"; QuotaProtos.Quotas quota = QuotaProtos.Quotas.newBuilder() .setThrottle(THROTTLE).setSpace(SPACE_QUOTA).build(); GlobalQuotaSettingsImpl settings = new GlobalQuotaSettingsImpl(null, null, ns, quota);
Quotas q = QuotaTableUtil .quotasFromData(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); assertTrue("Quota should have rpc quota defined", q.hasThrottle()); QuotaProtos.Throttle rpcQuota = q.getThrottle(); QuotaProtos.TimedQuota t = null;
@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.Quotas)) { return super.equals(obj); } org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas other = (org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas) obj; boolean result = true; result = result && (hasBypassGlobals() == other.hasBypassGlobals()); if (hasBypassGlobals()) { result = result && (getBypassGlobals() == other.getBypassGlobals()); } result = result && (hasThrottle() == other.hasThrottle()); if (hasThrottle()) { result = result && getThrottle() .equals(other.getThrottle()); } result = result && (hasSpace() == other.hasSpace()); if (hasSpace()) { result = result && getSpace() .equals(other.getSpace()); } result = result && unknownFields.equals(other.unknownFields); return result; }
@Test public void testGetSpaceQuota() throws Exception { NamespaceQuotaSnapshotStore mockStore = mock(NamespaceQuotaSnapshotStore.class); when(mockStore.getSpaceQuota(any())).thenCallRealMethod(); Quotas quotaWithSpace = Quotas.newBuilder().setSpace( SpaceQuota.newBuilder() .setSoftLimit(1024L) .setViolationPolicy(QuotaProtos.SpaceViolationPolicy.DISABLE) .build()) .build(); Quotas quotaWithoutSpace = Quotas.newBuilder().build(); AtomicReference<Quotas> quotaRef = new AtomicReference<>(); when(mockStore.getQuotaForNamespace(any())).then(new Answer<Quotas>() { @Override public Quotas answer(InvocationOnMock invocation) throws Throwable { return quotaRef.get(); } }); quotaRef.set(quotaWithSpace); assertEquals(quotaWithSpace.getSpace(), mockStore.getSpaceQuota("ns")); quotaRef.set(quotaWithoutSpace); assertNull(mockStore.getSpaceQuota("ns")); }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasBypassGlobals()) { hash = (37 * hash) + BYPASS_GLOBALS_FIELD_NUMBER; hash = (53 * hash) + org.apache.hbase.thirdparty.com.google.protobuf.Internal.hashBoolean( getBypassGlobals()); } if (hasThrottle()) { hash = (37 * hash) + THROTTLE_FIELD_NUMBER; hash = (53 * hash) + getThrottle().hashCode(); } if (hasSpace()) { hash = (37 * hash) + SPACE_FIELD_NUMBER; hash = (53 * hash) + getSpace().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@Test public void testGetSpaceQuota() throws Exception { TableQuotaSnapshotStore mockStore = mock(TableQuotaSnapshotStore.class); when(mockStore.getSpaceQuota(any())).thenCallRealMethod(); Quotas quotaWithSpace = Quotas.newBuilder().setSpace( SpaceQuota.newBuilder() .setSoftLimit(1024L) .setViolationPolicy(QuotaProtos.SpaceViolationPolicy.DISABLE) .build()) .build(); Quotas quotaWithoutSpace = Quotas.newBuilder().build(); AtomicReference<Quotas> quotaRef = new AtomicReference<>(); when(mockStore.getQuotaForTable(any())).then(new Answer<Quotas>() { @Override public Quotas answer(InvocationOnMock invocation) throws Throwable { return quotaRef.get(); } }); quotaRef.set(quotaWithSpace); assertEquals(quotaWithSpace.getSpace(), mockStore.getSpaceQuota(TableName.valueOf("foo"))); quotaRef.set(quotaWithoutSpace); assertNull(mockStore.getSpaceQuota(TableName.valueOf("foo"))); }
@Test public void testMergeThrottle() throws IOException { QuotaProtos.Quotas quota = QuotaProtos.Quotas.newBuilder() .setThrottle(THROTTLE).build(); QuotaProtos.TimedQuota writeQuota = REQUEST_THROTTLE.toBuilder() .setSoftLimit(500).build(); // Unset the req throttle, set a write throttle QuotaProtos.ThrottleRequest writeThrottle = QuotaProtos.ThrottleRequest.newBuilder() .setTimedQuota(writeQuota).setType(QuotaProtos.ThrottleType.WRITE_NUMBER).build(); GlobalQuotaSettingsImpl settings = new GlobalQuotaSettingsImpl("joe", null, null, quota); GlobalQuotaSettingsImpl merged = settings.merge( new ThrottleSettings("joe", null, null, writeThrottle)); QuotaProtos.Throttle mergedThrottle = merged.getThrottleProto(); // Verify the request throttle is in place assertTrue(mergedThrottle.hasReqNum()); QuotaProtos.TimedQuota actualReqNum = mergedThrottle.getReqNum(); assertEquals(REQUEST_THROTTLE.getSoftLimit(), actualReqNum.getSoftLimit()); // Verify the write throttle is in place assertTrue(mergedThrottle.hasWriteNum()); QuotaProtos.TimedQuota actualWriteNum = mergedThrottle.getWriteNum(); assertEquals(writeQuota.getSoftLimit(), actualWriteNum.getSoftLimit()); }
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 .computeBoolSize(1, bypassGlobals_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream .computeMessageSize(2, getThrottle()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream .computeMessageSize(3, getSpace()); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
@Test public void testNamespaceQuotaUtil() throws Exception { final String namespace = "testNamespaceQuotaUtilNS"; Quotas quota = Quotas.newBuilder() .setThrottle(Throttle.newBuilder() .setReqNum(ProtobufUtil.toTimedQuota(1000, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setWriteNum(ProtobufUtil.toTimedQuota(600, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setReadSize(ProtobufUtil.toTimedQuota(8192, TimeUnit.SECONDS, QuotaScope.MACHINE)) .build()) .build(); // Add user quota and verify it QuotaUtil.addNamespaceQuota(this.connection, namespace, quota); Quotas resQuota = QuotaUtil.getNamespaceQuota(this.connection, namespace); assertEquals(quota, resQuota); // Remove user quota and verify it QuotaUtil.deleteNamespaceQuota(this.connection, namespace); resQuota = QuotaUtil.getNamespaceQuota(this.connection, namespace); assertEquals(null, resQuota); }
@Test public void testTableQuotaUtil() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); Quotas quota = Quotas.newBuilder() .setThrottle(Throttle.newBuilder() .setReqNum(ProtobufUtil.toTimedQuota(1000, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setWriteNum(ProtobufUtil.toTimedQuota(600, TimeUnit.SECONDS, QuotaScope.MACHINE)) .setReadSize(ProtobufUtil.toTimedQuota(8192, TimeUnit.SECONDS, QuotaScope.MACHINE)) .build()) .build(); // Add user quota and verify it QuotaUtil.addTableQuota(this.connection, tableName, quota); Quotas resQuota = QuotaUtil.getTableQuota(this.connection, tableName); assertEquals(quota, resQuota); // Remove user quota and verify it QuotaUtil.deleteTableQuota(this.connection, tableName); resQuota = QuotaUtil.getTableQuota(this.connection, tableName); assertEquals(null, resQuota); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
public Builder mergeFrom(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas other) { if (other == org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas.getDefaultInstance()) return this; if (other.hasBypassGlobals()) { setBypassGlobals(other.getBypassGlobals()); } if (other.hasThrottle()) { mergeThrottle(other.getThrottle()); } if (other.hasSpace()) { mergeSpace(other.getSpace()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
protected static byte[] quotasToData(final Quotas data) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); stream.write(ProtobufMagic.PB_MAGIC); data.writeTo(stream); return stream.toByteArray(); }
protected static Quotas quotasFromData( final byte[] data, int offset, int length) throws IOException { int magicLen = ProtobufMagic.lengthOfPBMagic(); if (!ProtobufMagic.isPBMagicPrefix(data, offset, magicLen)) { throw new IOException("Missing pb magic prefix"); } return Quotas.parseFrom(new ByteArrayInputStream(data, offset + magicLen, length - magicLen)); }
@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, 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()); }
public void writeTo(org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeBool(1, bypassGlobals_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeMessage(2, getThrottle()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeMessage(3, getSpace()); } unknownFields.writeTo(output); }