From 0b1e288deb2c330521b9bb1d1803481afe49168b Mon Sep 17 00:00:00 2001 From: ChenSammi Date: Thu, 6 Jun 2019 00:09:36 +0800 Subject: [PATCH] HDDS-1637. Fix random test failure TestSCMContainerPlacementRackAware. Contributed by Sammi Chen. (#904) --- .../algorithms/SCMContainerPlacementRackAware.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java index ffebb84c4a..e126f27c1f 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java @@ -237,6 +237,7 @@ private Node chooseNode(List excludedNodes, Node affinityNode, long sizeRequired) throws SCMException { int ancestorGen = RACK_LEVEL; int maxRetry = MAX_RETRY; + List excludedNodesForCapacity = null; while(true) { Node node = networkTopology.chooseRandom(NetConstants.ROOT, null, excludedNodes, affinityNode, ancestorGen); @@ -265,6 +266,9 @@ private Node chooseNode(List excludedNodes, Node affinityNode, if (hasEnoughSpace((DatanodeDetails)node, sizeRequired)) { LOG.debug("Datanode {} is chosen. Required size is {}", node.toString(), sizeRequired); + if (excludedNodes != null && excludedNodesForCapacity != null) { + excludedNodes.removeAll(excludedNodesForCapacity); + } return node; } else { maxRetry--; @@ -275,6 +279,15 @@ private Node chooseNode(List excludedNodes, Node affinityNode, LOG.info(errMsg); throw new SCMException(errMsg, null); } + if (excludedNodesForCapacity == null) { + excludedNodesForCapacity = new ArrayList<>(); + } + excludedNodesForCapacity.add(node); + if (excludedNodes == null) { + excludedNodes = excludedNodesForCapacity; + } else { + excludedNodes.add(node); + } } } }