Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ protected static List<ThrottleSettings> fromThrottle(final String userName,
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
ThrottleType.WRITE_CAPACITY_UNIT, throttle.getWriteCapacityUnit()));
}
if (throttle.hasAtomicReadSize()) {
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
ThrottleType.ATOMIC_READ_SIZE, throttle.getAtomicReadSize()));
}
if (throttle.hasAtomicWriteSize()) {
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
ThrottleType.ATOMIC_WRITE_SIZE, throttle.getAtomicWriteSize()));
}
Comment on lines 170 to +178
Copy link

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding an inline comment here (and similarly for atomic write and request numbers) to explain the purpose of handling these atomic throttle settings for improved maintainability.

Suggested change
}
if (throttle.hasAtomicReadSize()) {
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
ThrottleType.ATOMIC_READ_SIZE, throttle.getAtomicReadSize()));
}
if (throttle.hasAtomicWriteSize()) {
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
ThrottleType.ATOMIC_WRITE_SIZE, throttle.getAtomicWriteSize()));
}
}
// Handle atomic read size throttling: This enforces limits on the size of read operations
// at an atomic level, ensuring precise control over resource usage.
if (throttle.hasAtomicReadSize()) {
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
ThrottleType.ATOMIC_READ_SIZE, throttle.getAtomicReadSize()));
}
// Handle atomic write size throttling: This enforces limits on the size of write operations
// at an atomic level, ensuring precise control over resource usage.
if (throttle.hasAtomicWriteSize()) {
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
ThrottleType.ATOMIC_WRITE_SIZE, throttle.getAtomicWriteSize()));
}
// Handle atomic request number throttling: This enforces limits on the number of requests
// at an atomic level, ensuring precise control over resource usage.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm against superfluous comments that just reiterate straightforward code. This is already too verbose

if (throttle.hasAtomicReqNum()) {
settings.add(ThrottleSettings.fromTimedQuota(userName, tableName, namespace, regionServer,
ThrottleType.ATOMIC_REQUEST_NUMBER, throttle.getAtomicReqNum()));
}
return settings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerUserCacheRefresh;
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.waitMinuteQuota;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
Expand Down Expand Up @@ -652,4 +655,39 @@ public void testExceedThrottleQuota() throws Exception {
admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
triggerTableCacheRefresh(TEST_UTIL, true, TABLE_NAMES[0]);
}

@Test
public void testSetAndGetAllThrottleTypes() throws Exception {
for (ThrottleType throttleType : ThrottleType.values()) {
canSetAndGetUserThrottle(throttleType);
}
Comment on lines +661 to +663
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By validating this for every throttle type, we'll prevent new throttle types from missing this key usability piece down the road

}

private void canSetAndGetUserThrottle(ThrottleType throttleType) throws IOException {
final Admin admin = TEST_UTIL.getAdmin();
final String userName = User.getCurrent().getShortName();

QuotaSettings setQuota =
QuotaSettingsFactory.throttleUser(userName, throttleType, 123, TimeUnit.SECONDS);
admin.setQuota(setQuota);

boolean found = false;
List<QuotaSettings> quotaSettings = admin.getQuota(new QuotaFilter().setUserFilter(userName));
for (QuotaSettings settings : quotaSettings) {
if (settings instanceof ThrottleSettings) {
ThrottleSettings throttle = (ThrottleSettings) settings;
if (
userName.equals(throttle.getUserName()) && throttle.getThrottleType() == throttleType
&& throttle.getSoftLimit() == 123 && throttle.getTimeUnit() == TimeUnit.SECONDS
) {
found = true;
break;
}
}
}

assertTrue("Expected to find " + throttleType.name() + " quota for user " + userName, found);
admin.setQuota(QuotaSettingsFactory.unthrottleUserByThrottleType(userName, throttleType));
}

}