You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2019/08/15 05:39:20 UTC

[GitHub] [helix] narendly commented on a change in pull request #333: Fix issue when client only sets ANY at cluster level throttle config

narendly commented on a change in pull request #333: Fix issue when client only sets ANY at cluster level throttle config
URL: https://github.com/apache/helix/pull/333#discussion_r314178477
 
 

 ##########
 File path: helix-core/src/main/java/org/apache/helix/controller/stages/StateTransitionThrottleController.java
 ##########
 @@ -208,13 +195,20 @@ protected void chargeResource(StateTransitionThrottleConfig.RebalanceType rebala
    */
   protected void chargeInstance(StateTransitionThrottleConfig.RebalanceType rebalanceType,
       String instance) {
-    if (_pendingTransitionAllowedPerInstance.containsKey(instance)
-        && _pendingTransitionAllowedPerInstance.get(instance).containsKey(rebalanceType)) {
-      chargeANYType(_pendingTransitionAllowedPerInstance.get(instance));
-      Long instanceThrottle = _pendingTransitionAllowedPerInstance.get(instance).get(rebalanceType);
-      if (instanceThrottle > 0) {
-        _pendingTransitionAllowedPerInstance.get(instance).put(rebalanceType, instanceThrottle - 1);
-      }
+    charge(rebalanceType, _pendingTransitionAllowedPerInstance.getOrDefault(instance, new HashMap<>()));
+  }
+
+  private void charge(StateTransitionThrottleConfig.RebalanceType rebalanceType,
+      Map<StateTransitionThrottleConfig.RebalanceType, Long> quota) {
+    if (StateTransitionThrottleConfig.RebalanceType.NONE.equals(rebalanceType)) {
+      logger.error("Wrong rebalance type NONE as parameter");
+      return;
+    }
+    // if ANY type is present, decrement one else do nothing
+    quota.computeIfPresent(StateTransitionThrottleConfig.RebalanceType.ANY, (type, quotaNumber) -> Math.max(0, quotaNumber - 1));
 
 Review comment:
   Minor: Did you format this?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org