Skip to content

Commit cd8b9d5

Browse files
rmdmattinglyRay Mattingly
andauthored
HBASE-29281 Atomic request throttles are missing QuotaSettingsFactory support (#6953) (#6956)
Signed-off-by: Nick Dimiduk <[email protected]> Co-authored-by: Ray Mattingly <[email protected]>
1 parent 987012d commit cd8b9d5

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaSettingsFactory.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ protected static List<ThrottleSettings> fromThrottle(final String userName,
168168
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
169169
ThrottleType.WRITE_CAPACITY_UNIT, throttle.getWriteCapacityUnit()));
170170
}
171+
if (throttle.hasAtomicReadSize()) {
172+
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
173+
ThrottleType.ATOMIC_READ_SIZE, throttle.getAtomicReadSize()));
174+
}
175+
if (throttle.hasAtomicWriteSize()) {
176+
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
177+
ThrottleType.ATOMIC_WRITE_SIZE, throttle.getAtomicWriteSize()));
178+
}
179+
if (throttle.hasAtomicReqNum()) {
180+
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
181+
ThrottleType.ATOMIC_REQUEST_NUMBER, throttle.getAtomicReqNum()));
182+
}
171183
return settings;
172184
}
173185

hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaThrottle.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerUserCacheRefresh;
2727
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.waitMinuteQuota;
2828
import static org.junit.Assert.assertEquals;
29+
import static org.junit.Assert.assertTrue;
2930

31+
import java.io.IOException;
32+
import java.util.List;
3033
import java.util.concurrent.TimeUnit;
3134
import org.apache.hadoop.hbase.HBaseClassTestRule;
3235
import org.apache.hadoop.hbase.HBaseTestingUtil;
@@ -652,4 +655,39 @@ public void testExceedThrottleQuota() throws Exception {
652655
admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
653656
triggerTableCacheRefresh(TEST_UTIL, true, TABLE_NAMES[0]);
654657
}
658+
659+
@Test
660+
public void testSetAndGetAllThrottleTypes() throws Exception {
661+
for (ThrottleType throttleType : ThrottleType.values()) {
662+
canSetAndGetUserThrottle(throttleType);
663+
}
664+
}
665+
666+
private void canSetAndGetUserThrottle(ThrottleType throttleType) throws IOException {
667+
final Admin admin = TEST_UTIL.getAdmin();
668+
final String userName = User.getCurrent().getShortName();
669+
670+
QuotaSettings setQuota =
671+
QuotaSettingsFactory.throttleUser(userName, throttleType, 123, TimeUnit.SECONDS);
672+
admin.setQuota(setQuota);
673+
674+
boolean found = false;
675+
List<QuotaSettings> quotaSettings = admin.getQuota(new QuotaFilter().setUserFilter(userName));
676+
for (QuotaSettings settings : quotaSettings) {
677+
if (settings instanceof ThrottleSettings) {
678+
ThrottleSettings throttle = (ThrottleSettings) settings;
679+
if (
680+
userName.equals(throttle.getUserName()) && throttle.getThrottleType() == throttleType
681+
&& throttle.getSoftLimit() == 123 && throttle.getTimeUnit() == TimeUnit.SECONDS
682+
) {
683+
found = true;
684+
break;
685+
}
686+
}
687+
}
688+
689+
assertTrue("Expected to find " + throttleType.name() + " quota for user " + userName, found);
690+
admin.setQuota(QuotaSettingsFactory.unthrottleUserByThrottleType(userName, throttleType));
691+
}
692+
655693
}

0 commit comments

Comments
 (0)