|
@@ -42,6 +42,10 @@ public class StaticRouterRpcFairnessPolicyController extends
|
|
|
private static final Logger LOG =
|
|
|
LoggerFactory.getLogger(StaticRouterRpcFairnessPolicyController.class);
|
|
|
|
|
|
+ public static final String ERROR_MSG = "Configured handlers "
|
|
|
+ + DFS_ROUTER_HANDLER_COUNT_KEY + '='
|
|
|
+ + " %d is less than the minimum required handlers %d";
|
|
|
+
|
|
|
public StaticRouterRpcFairnessPolicyController(Configuration conf) {
|
|
|
init(conf);
|
|
|
}
|
|
@@ -65,15 +69,13 @@ public class StaticRouterRpcFairnessPolicyController extends
|
|
|
|
|
|
// Insert the concurrent nameservice into the set to process together
|
|
|
allConfiguredNS.add(CONCURRENT_NS);
|
|
|
+ validateHandlersCount(conf, handlerCount, allConfiguredNS);
|
|
|
for (String nsId : allConfiguredNS) {
|
|
|
int dedicatedHandlers =
|
|
|
conf.getInt(DFS_ROUTER_FAIR_HANDLER_COUNT_KEY_PREFIX + nsId, 0);
|
|
|
LOG.info("Dedicated handlers {} for ns {} ", dedicatedHandlers, nsId);
|
|
|
if (dedicatedHandlers > 0) {
|
|
|
handlerCount -= dedicatedHandlers;
|
|
|
- // Total handlers should not be less than sum of dedicated
|
|
|
- // handlers.
|
|
|
- validateCount(nsId, handlerCount, 0);
|
|
|
insertNameServiceWithPermits(nsId, dedicatedHandlers);
|
|
|
logAssignment(nsId, dedicatedHandlers);
|
|
|
} else {
|
|
@@ -88,8 +90,6 @@ public class StaticRouterRpcFairnessPolicyController extends
|
|
|
int handlersPerNS = handlerCount / unassignedNS.size();
|
|
|
LOG.info("Handlers available per ns {}", handlersPerNS);
|
|
|
for (String nsId : unassignedNS) {
|
|
|
- // Each NS should have at least one handler assigned.
|
|
|
- validateCount(nsId, handlersPerNS, 1);
|
|
|
insertNameServiceWithPermits(nsId, handlersPerNS);
|
|
|
logAssignment(nsId, handlersPerNS);
|
|
|
}
|
|
@@ -112,15 +112,26 @@ public class StaticRouterRpcFairnessPolicyController extends
|
|
|
count, nsId);
|
|
|
}
|
|
|
|
|
|
- private static void validateCount(String nsId, int handlers, int min) throws
|
|
|
- IllegalArgumentException {
|
|
|
- if (handlers < min) {
|
|
|
- String msg =
|
|
|
- "Available handlers " + handlers +
|
|
|
- " lower than min " + min +
|
|
|
- " for nsId " + nsId;
|
|
|
+ private void validateHandlersCount(Configuration conf, int handlerCount,
|
|
|
+ Set<String> allConfiguredNS) {
|
|
|
+ int totalDedicatedHandlers = 0;
|
|
|
+ for (String nsId : allConfiguredNS) {
|
|
|
+ int dedicatedHandlers =
|
|
|
+ conf.getInt(DFS_ROUTER_FAIR_HANDLER_COUNT_KEY_PREFIX + nsId, 0);
|
|
|
+ if (dedicatedHandlers > 0) {
|
|
|
+ // Total handlers should not be less than sum of dedicated handlers.
|
|
|
+ totalDedicatedHandlers += dedicatedHandlers;
|
|
|
+ } else {
|
|
|
+ // Each NS should have at least one handler assigned.
|
|
|
+ totalDedicatedHandlers++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (totalDedicatedHandlers > handlerCount) {
|
|
|
+ String msg = String.format(ERROR_MSG, handlerCount,
|
|
|
+ totalDedicatedHandlers);
|
|
|
LOG.error(msg);
|
|
|
throw new IllegalArgumentException(msg);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|