-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-28672 Ensure large batches are not indefinitely blocked by quotas #6003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,15 +18,20 @@ | |
| package org.apache.hadoop.hbase.quotas; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertThrows; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.testclassification.RegionServerTests; | ||
| import org.apache.hadoop.hbase.testclassification.SmallTests; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
|
|
||
| import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; | ||
| import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos; | ||
|
|
||
| @Category({ RegionServerTests.class, SmallTests.class }) | ||
| public class TestDefaultOperationQuota { | ||
| @ClassRule | ||
|
|
@@ -125,4 +130,67 @@ public void testScanEstimateShrinkingWorkload() { | |
| // shrinking workload should only shrink estimate to maxBBS | ||
| assertEquals(maxBlockBytesScanned, estimate); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLargeBatchSaturatesReadNumLimit() | ||
| throws RpcThrottlingException, InterruptedException { | ||
| int limit = 10; | ||
| QuotaProtos.Throttle throttle = | ||
| QuotaProtos.Throttle.newBuilder().setReadNum(QuotaProtos.TimedQuota.newBuilder() | ||
| .setSoftLimit(limit).setTimeUnit(HBaseProtos.TimeUnit.SECONDS).build()).build(); | ||
| QuotaLimiter limiter = TimeBasedLimiter.fromThrottle(throttle); | ||
| DefaultOperationQuota quota = new DefaultOperationQuota(new Configuration(), 65536, limiter); | ||
|
|
||
| // use the whole limit | ||
| quota.checkBatchQuota(0, limit); | ||
|
|
||
| // the next request should be rejected | ||
| assertThrows(RpcThrottlingException.class, () -> quota.checkBatchQuota(0, 1)); | ||
|
|
||
| Thread.sleep(1000); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's preferable not to sleep. Instead usually you can influence the timestamp by adding 1s to it or whatever. The reason not to sleep is that you're more subject to random Jenkins slowdowns or other problems. We do it in a lot of places of course, but iirc the quota stuff already can do some timestamp manipulation? |
||
| // after the TimeUnit, the limit should be refilled | ||
| quota.checkBatchQuota(0, limit); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTooLargeReadBatchIsNotBlocked() | ||
| throws RpcThrottlingException, InterruptedException { | ||
| int limit = 10; | ||
| QuotaProtos.Throttle throttle = | ||
| QuotaProtos.Throttle.newBuilder().setReadNum(QuotaProtos.TimedQuota.newBuilder() | ||
| .setSoftLimit(limit).setTimeUnit(HBaseProtos.TimeUnit.SECONDS).build()).build(); | ||
| QuotaLimiter limiter = TimeBasedLimiter.fromThrottle(throttle); | ||
| DefaultOperationQuota quota = new DefaultOperationQuota(new Configuration(), 65536, limiter); | ||
|
|
||
| // use more than the limit, which should succeed rather than being indefinitely blocked | ||
| quota.checkBatchQuota(0, 10 + limit); | ||
|
|
||
| // the next request should be blocked | ||
| assertThrows(RpcThrottlingException.class, () -> quota.checkBatchQuota(0, 1)); | ||
|
|
||
| Thread.sleep(1000); | ||
| // even after the TimeUnit, the limit should not be refilled because we oversubscribed | ||
| assertThrows(RpcThrottlingException.class, () -> quota.checkBatchQuota(0, limit)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTooLargeWriteBatchIsNotBlocked() | ||
| throws RpcThrottlingException, InterruptedException { | ||
| int limit = 10; | ||
| QuotaProtos.Throttle throttle = | ||
| QuotaProtos.Throttle.newBuilder().setWriteNum(QuotaProtos.TimedQuota.newBuilder() | ||
| .setSoftLimit(limit).setTimeUnit(HBaseProtos.TimeUnit.SECONDS).build()).build(); | ||
| QuotaLimiter limiter = TimeBasedLimiter.fromThrottle(throttle); | ||
| DefaultOperationQuota quota = new DefaultOperationQuota(new Configuration(), 65536, limiter); | ||
|
|
||
| // use more than the limit, which should succeed rather than being indefinitely blocked | ||
| quota.checkBatchQuota(10 + limit, 0); | ||
|
|
||
| // the next request should be blocked | ||
| assertThrows(RpcThrottlingException.class, () -> quota.checkBatchQuota(1, 0)); | ||
|
|
||
| Thread.sleep(1000); | ||
| // even after the TimeUnit, the limit should not be refilled because we oversubscribed | ||
| assertThrows(RpcThrottlingException.class, () -> quota.checkBatchQuota(limit, 0)); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.