sodonnel commented on code in PR #4006:
URL: https://github.com/apache/ozone/pull/4006#discussion_r1039714802


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMCommonPlacementPolicy.java:
##########
@@ -426,4 +431,41 @@ public boolean isValidNode(DatanodeDetails datanodeDetails,
     }
     return false;
   }
+
+  /**
+   * Given a set of replicas of a container, return a set of replicas to copy
+   * to another node to fix misreplication.
+   * @param replicas
+   */
+  @Override
+  public Set<ContainerReplica> replicasToCopyToFixMisreplication(
+         Set<ContainerReplica> replicas) {
+    Map<Node, List<ContainerReplica>> placementGroupReplicaIdMap
+            = replicas.stream().collect(Collectors.groupingBy(replica ->
+            this.getPlacementGroup(replica.getDatanodeDetails())));
+
+    int totalNumberOfReplicas = replicas.size();
+    int requiredNumberOfPlacementGroups = getRequiredRackCount(
+            totalNumberOfReplicas);
+    int replicasPerPlacementGroup =
+            totalNumberOfReplicas / requiredNumberOfPlacementGroups;

Review Comment:
   Do we need to round up the results of the division? Say we have 9 replicas 
and 2 racks. 9 / 2 = 4, so it will say each rack has 4, but actually the max 
per rack is 5. Same for 9 / 4, it will say 2 per rack, but its really 3, 2, 2, 
2 which is ideal. 
   
   An interesting question is then what about 3, 3, 2, 1. I guess that is valid 
as our tolerance to a rack down is governed by the racks with the most replicas.
   
   Going back to the 2 rack example, if we have 9 replicas and 8 on rack 1 and 
1 on rack 2. We need to move 3 to rack 2.
   
   ```
   int misreplicationCnt = Math.max(requiredNumberOfPlacementGroups - 
placementGroupReplicaIdMap.size(), 0);
   ```
   The above will give Math.max(2 - 2, 0) = 0 in this case, but its not correct 
and that will prevent anything from being copied I think.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to