HDDS-1637. Fix random test failure TestSCMContainerPlacementRackAware. Contributed by Sammi Chen. (#904)

This commit is contained in:
ChenSammi 2019-06-06 00:09:36 +08:00 committed by Xiaoyu Yao
parent d1aad44490
commit 0b1e288deb
1 changed files with 13 additions and 0 deletions

View File

@ -237,6 +237,7 @@ private Node chooseNode(List<Node> excludedNodes, Node affinityNode,
long sizeRequired) throws SCMException {
int ancestorGen = RACK_LEVEL;
int maxRetry = MAX_RETRY;
List<Node> excludedNodesForCapacity = null;
while(true) {
Node node = networkTopology.chooseRandom(NetConstants.ROOT, null,
excludedNodes, affinityNode, ancestorGen);
@ -265,6 +266,9 @@ private Node chooseNode(List<Node> 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<Node> 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);
}
}
}
}