rich7420 commented on code in PR #11403:
URL: https://github.com/apache/ozone/pull/11403#discussion_r4181825586
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/TestSCMContainerPlacementRackAware.java:
##########
@@ -678,6 +679,43 @@ public void chooseNodeWithUsedNodesMultipleRack(int
datanodeCount)
cluster.isSameParent(datanodes.get(5), datanodeDetails.get(0)));
}
+ @Test
+ public void chooseNodeWhenUsedNodeRackHasOnlyDecommissionedNodes() throws
SCMException {
+ setup(3 * NODE_PER_RACK);
+ // rack1 has no usable node left: node5 already has a replica, and nodes
6-9 are decommissioned.
+ for (int i = 6; i < 10; i++) {
+ dnInfos.get(i).setNodeStatus(NodeStatus.valueOf(DECOMMISSIONED,
HEALTHY));
+ }
+ // The container has replicas on node5 (rack1) and node0 (rack0). rack1 is
tried first.
+ List<DatanodeDetails> usedNodes = new
ArrayList<>(Arrays.asList(datanodes.get(5), datanodes.get(0)));
+
+ List<DatanodeDetails> datanodeDetails = policy.chooseDatanodes(usedNodes,
new ArrayList<>(), null, 1, 0, 5);
+
+ assertEquals(1, datanodeDetails.size());
+ // Instead of giving up after rack1, placement tries rack0 and finds a
node there.
+ assertTrue(cluster.isSameParent(datanodes.get(0), datanodeDetails.get(0)));
+ assertNotEquals(datanodes.get(0), datanodeDetails.get(0));
+ }
+
+ @Test
+ public void fallbackWhenUsedNodeRacksHaveOnlyDecommissionedNodes() throws
SCMException {
+ setup(3 * NODE_PER_RACK);
+ // The replicas are on node0 (rack0) and node5 (rack1), and neither rack
has another usable node:
+ // node1 and node6 are excluded because their replicas are being
decommissioned, and the rest are decommissioned.
+ dnInfos.get(1).setNodeStatus(NodeStatus.valueOf(DECOMMISSIONING, HEALTHY));
+ for (int i : new int[] {2, 3, 4, 6, 7, 8, 9}) {
+ dnInfos.get(i).setNodeStatus(NodeStatus.valueOf(DECOMMISSIONED,
HEALTHY));
+ }
+ List<DatanodeDetails> usedNodes = new
ArrayList<>(Arrays.asList(datanodes.get(0), datanodes.get(5)));
+ List<DatanodeDetails> excludedNodes = new
ArrayList<>(Arrays.asList(datanodes.get(1), datanodes.get(6)));
+
+ List<DatanodeDetails> datanodeDetails = policy.chooseDatanodes(usedNodes,
excludedNodes, null, 1, 0, 5);
+
+ assertEquals(1, datanodeDetails.size());
+ // After both racks fail, placement falls back to rack2, the only rack
with usable nodes.
+ assertTrue(cluster.isSameParent(datanodes.get(10),
datanodeDetails.get(0)));
Review Comment:
Could we also assert `metrics.getDatanodeChooseFallbackCount()` is `1` here
and `0` in the preceding test, since trying another affinity rack should not
count as a fallback?
--
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]