[ 
https://issues.apache.org/jira/browse/HELIX-631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15531493#comment-15531493
 ] 

ASF GitHub Bot commented on HELIX-631:
--------------------------------------

Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/52#discussion_r81051316
  
    --- Diff: 
helix-core/src/main/java/org/apache/helix/controller/rebalancer/strategy/AutoRebalanceStrategy.java
 ---
    @@ -177,15 +176,26 @@ private void assignOrphans() {
         while (it.hasNext()) {
           Replica replica = it.next();
           boolean added = false;
    -      int startIndex = computeRandomStartIndex(replica);
    -      for (int index = startIndex; index < startIndex + 
_liveNodesList.size(); index++) {
    -        Node receiver = _liveNodesList.get(index % _liveNodesList.size());
    -        if (receiver.capacity > receiver.currentlyAssigned && 
receiver.canAdd(replica)) {
    -          receiver.currentlyAssigned = receiver.currentlyAssigned + 1;
    -          receiver.nonPreferred.add(replica);
    -          receiver.newReplicas.add(replica);
    -          added = true;
    -          break;
    +
    +      // first find if it preferred node still has capacity
    +      Node preferred = _preferredAssignment.get(replica);
    +      if (preferred.capacity > preferred.currentlyAssigned && 
preferred.canAdd(replica)) {
    --- End diff --
    
    Fixed, refactored to a separated method.


> AutoRebalanceStrategy does not work correctly all the time
> ----------------------------------------------------------
>
>                 Key: HELIX-631
>                 URL: https://issues.apache.org/jira/browse/HELIX-631
>             Project: Apache Helix
>          Issue Type: Bug
>            Reporter: Subbu
>            Assignee: Lei Xia
>
> I have 16 partitions, 3 replicas each, and 4 instances to distribute these 
> on. The auto-rebalancer assigns only 2 replicas for one of the partitions.
> Here is the code snippet to reproduce the problem
> {code}
>     final String resourceName = "something";
>     final List<String> instanceNames = null; // Initialize to 4 unique strings
>     final int nReplicas = 3;
>     List<String> partitions = new ArrayList<>(nPartitions);
>     for (int i = 0; i < nPartitions; i++) {
>       partitions.add(Integer.toString(i));
>     }
>     LinkedHashMap<String, Integer> states = new LinkedHashMap<>(2);
>     states.put("OFFLINE", 0);
>     states.put("ONLINE", nReplicas);
>     AutoRebalanceStrategy strategy = new AutoRebalanceStrategy(resourceName, 
> partitions, states);
>     ZNRecord znRecord = strategy.computePartitionAssignment(instanceNames, 
> new HashMap<String, Map<String, String>>(0), instanceNames);
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to