HDFS-16417. StaticRouterRpcFairnessPolicyController init (#3871)

This commit is contained in:
Felix Nguyen 2022-01-10 18:28:20 +08:00 committed by GitHub
parent b27732c69b
commit b88d5ae1c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -96,7 +96,8 @@ public void init(Configuration conf)
} }
// Assign remaining handlers if any to fan out calls. // Assign remaining handlers if any to fan out calls.
int leftOverHandlers = handlerCount % unassignedNS.size(); int leftOverHandlers = unassignedNS.isEmpty() ? handlerCount :
handlerCount % unassignedNS.size();
int existingPermits = getAvailablePermits(CONCURRENT_NS); int existingPermits = getAvailablePermits(CONCURRENT_NS);
if (leftOverHandlers > 0) { if (leftOverHandlers > 0) {
LOG.info("Assigned extra {} handlers to commons pool", leftOverHandlers); LOG.info("Assigned extra {} handlers to commons pool", leftOverHandlers);

View File

@ -129,6 +129,30 @@ public void testAllocationErrorForLowPreconfiguredHandlers() {
verifyInstantiationError(conf, 1, 4); verifyInstantiationError(conf, 1, 4);
} }
@Test
public void testHandlerAllocationConcurrentConfigured() {
Configuration conf = createConf(5);
conf.setInt(DFS_ROUTER_FAIR_HANDLER_COUNT_KEY_PREFIX + "ns1", 1);
conf.setInt(DFS_ROUTER_FAIR_HANDLER_COUNT_KEY_PREFIX + "ns2", 1);
conf.setInt(DFS_ROUTER_FAIR_HANDLER_COUNT_KEY_PREFIX + "concurrent", 1);
RouterRpcFairnessPolicyController routerRpcFairnessPolicyController =
FederationUtil.newFairnessPolicyController(conf);
// ns1, ns2 should have 1 permit each
assertTrue(routerRpcFairnessPolicyController.acquirePermit("ns1"));
assertTrue(routerRpcFairnessPolicyController.acquirePermit("ns2"));
assertFalse(routerRpcFairnessPolicyController.acquirePermit("ns1"));
assertFalse(routerRpcFairnessPolicyController.acquirePermit("ns2"));
// concurrent should have 3 permits
for (int i=0; i<3; i++) {
assertTrue(
routerRpcFairnessPolicyController.acquirePermit(CONCURRENT_NS));
}
assertFalse(routerRpcFairnessPolicyController.acquirePermit(CONCURRENT_NS));
}
private void verifyInstantiationError(Configuration conf, int handlerCount, private void verifyInstantiationError(Configuration conf, int handlerCount,
int totalDedicatedHandlers) { int totalDedicatedHandlers) {
GenericTestUtils.LogCapturer logs = GenericTestUtils.LogCapturer GenericTestUtils.LogCapturer logs = GenericTestUtils.LogCapturer