-
Couldn't load subscription status.
- Fork 3.4k
HBASE-27800: Add support for default user quotas #5666
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestDefaultQuota.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.hbase.quotas; | ||
|
|
||
| import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerUserCacheRefresh; | ||
| import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.waitMinuteQuota; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.Admin; | ||
| import org.apache.hadoop.hbase.client.Table; | ||
| import org.apache.hadoop.hbase.security.User; | ||
| import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
| import org.apache.hadoop.hbase.testclassification.RegionServerTests; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
| import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; | ||
| import org.junit.After; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
|
|
||
| @Category({ RegionServerTests.class, MediumTests.class }) | ||
| public class TestDefaultQuota { | ||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestDefaultQuota.class); | ||
| private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); | ||
| private static final TableName TABLE_NAME = TableName.valueOf(UUID.randomUUID().toString()); | ||
| private static final int REFRESH_TIME = 5000; | ||
| private static final byte[] FAMILY = Bytes.toBytes("cf"); | ||
| private static final byte[] QUALIFIER = Bytes.toBytes("q"); | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| ThrottleQuotaTestUtil.clearQuotaCache(TEST_UTIL); | ||
| EnvironmentEdgeManager.reset(); | ||
| TEST_UTIL.deleteTable(TABLE_NAME); | ||
| TEST_UTIL.shutdownMiniCluster(); | ||
| } | ||
|
|
||
| @BeforeClass | ||
| public static void setUpBeforeClass() throws Exception { | ||
| // quotas enabled, using block bytes scanned | ||
| TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, true); | ||
| TEST_UTIL.getConfiguration().setInt(QuotaCache.REFRESH_CONF_KEY, REFRESH_TIME); | ||
| TEST_UTIL.getConfiguration().setInt(QuotaUtil.QUOTA_DEFAULT_USER_MACHINE_READ_NUM, 1); | ||
|
|
||
| // don't cache blocks to make IO predictable | ||
| TEST_UTIL.getConfiguration().setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0.0f); | ||
|
|
||
| TEST_UTIL.startMiniCluster(1); | ||
| TEST_UTIL.waitTableAvailable(QuotaTableUtil.QUOTA_TABLE_NAME); | ||
| TEST_UTIL.createTable(TABLE_NAME, FAMILY); | ||
| TEST_UTIL.waitTableAvailable(TABLE_NAME); | ||
| QuotaCache.TEST_FORCE_REFRESH = true; | ||
|
|
||
| try (Admin admin = TEST_UTIL.getAdmin()) { | ||
| ThrottleQuotaTestUtil.doPuts(1_000, FAMILY, QUALIFIER, | ||
| admin.getConnection().getTable(TABLE_NAME)); | ||
| } | ||
| TEST_UTIL.flush(TABLE_NAME); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDefaultUserReadNum() throws Exception { | ||
| // Should have a strict throttle by default | ||
| TEST_UTIL.waitFor(60_000, () -> runGetsTest(100) < 100); | ||
|
|
||
| // Add big quota and should be effectively unlimited | ||
| configureLenientThrottle(); | ||
| refreshQuotas(); | ||
| // Should run without error | ||
| TEST_UTIL.waitFor(60_000, () -> runGetsTest(100) == 100); | ||
|
|
||
| // Remove all the limits, and should revert to strict default | ||
| unsetQuota(); | ||
| TEST_UTIL.waitFor(60_000, () -> runGetsTest(100) < 100); | ||
| } | ||
|
|
||
| private void configureLenientThrottle() throws IOException { | ||
| try (Admin admin = TEST_UTIL.getAdmin()) { | ||
| admin.setQuota(QuotaSettingsFactory.throttleUser(getUserName(), ThrottleType.READ_NUMBER, | ||
| 100_000, TimeUnit.SECONDS)); | ||
| } | ||
| } | ||
|
|
||
| private static String getUserName() throws IOException { | ||
| return User.getCurrent().getShortName(); | ||
| } | ||
|
|
||
| private void refreshQuotas() throws Exception { | ||
| triggerUserCacheRefresh(TEST_UTIL, false, TABLE_NAME); | ||
| waitMinuteQuota(); | ||
| } | ||
|
|
||
| private void unsetQuota() throws Exception { | ||
| try (Admin admin = TEST_UTIL.getAdmin()) { | ||
| admin.setQuota(QuotaSettingsFactory.unthrottleUser(getUserName())); | ||
| } | ||
| refreshQuotas(); | ||
| } | ||
|
|
||
| private long runGetsTest(int attempts) throws Exception { | ||
| refreshQuotas(); | ||
| try (Table table = getTable()) { | ||
| return ThrottleQuotaTestUtil.doGets(attempts, FAMILY, QUALIFIER, table); | ||
| } | ||
| } | ||
|
|
||
| private Table getTable() throws IOException { | ||
| TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 100); | ||
| TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); | ||
| return TEST_UTIL.getConnection().getTableBuilder(TABLE_NAME, null).setOperationTimeout(250) | ||
| .build(); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.