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 2020/03/13 18:09:34 UTC

[GitHub] [helix] jiajunwang commented on a change in pull request #889: Remove possible score-tie between two AssignableNodes

jiajunwang commented on a change in pull request #889: Remove possible score-tie between two AssignableNodes
URL: https://github.com/apache/helix/pull/889#discussion_r392390285
 
 

 ##########
 File path: helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintBasedAlgorithm.java
 ##########
 @@ -122,9 +121,12 @@ public OptimalAssignment calculate(ClusterModel clusterModel)
           if (scoreCompareResult == 0) {
             // If the evaluation scores of 2 nodes are the same, the algorithm assigns the replica
             // to the idle node first.
-            int idleScore1 = busyInstances.contains(nodeEntry1.getKey().getInstanceName()) ? 0 : 1;
-            int idleScore2 = busyInstances.contains(nodeEntry2.getKey().getInstanceName()) ? 0 : 1;
-            return idleScore1 - idleScore2;
+            String instanceName1 = nodeEntry1.getKey().getInstanceName();
+            String instanceName2 = nodeEntry2.getKey().getInstanceName();
+            int idleScore1 = busyInstances.contains(instanceName1) ? 0 : 1;
+            int idleScore2 = busyInstances.contains(instanceName2) ? 0 : 1;
+            return idleScore1 != idleScore2 ? idleScore1 - idleScore2
 
 Review comment:
   nit, adding parenthesis to the calculation so it is cleaner and safer.

----------------------------------------------------------------
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