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

View File

@ -237,6 +237,7 @@ public final class SCMContainerPlacementRackAware extends SCMCommonPolicy {
long sizeRequired) throws SCMException { long sizeRequired) throws SCMException {
int ancestorGen = RACK_LEVEL; int ancestorGen = RACK_LEVEL;
int maxRetry = MAX_RETRY; int maxRetry = MAX_RETRY;
List<Node> excludedNodesForCapacity = null;
while(true) { while(true) {
Node node = networkTopology.chooseRandom(NetConstants.ROOT, null, Node node = networkTopology.chooseRandom(NetConstants.ROOT, null,
excludedNodes, affinityNode, ancestorGen); excludedNodes, affinityNode, ancestorGen);
@ -265,6 +266,9 @@ public final class SCMContainerPlacementRackAware extends SCMCommonPolicy {
if (hasEnoughSpace((DatanodeDetails)node, sizeRequired)) { if (hasEnoughSpace((DatanodeDetails)node, sizeRequired)) {
LOG.debug("Datanode {} is chosen. Required size is {}", LOG.debug("Datanode {} is chosen. Required size is {}",
node.toString(), sizeRequired); node.toString(), sizeRequired);
if (excludedNodes != null && excludedNodesForCapacity != null) {
excludedNodes.removeAll(excludedNodesForCapacity);
}
return node; return node;
} else { } else {
maxRetry--; maxRetry--;
@ -275,6 +279,15 @@ public final class SCMContainerPlacementRackAware extends SCMCommonPolicy {
LOG.info(errMsg); LOG.info(errMsg);
throw new SCMException(errMsg, null); throw new SCMException(errMsg, null);
} }
if (excludedNodesForCapacity == null) {
excludedNodesForCapacity = new ArrayList<>();
}
excludedNodesForCapacity.add(node);
if (excludedNodes == null) {
excludedNodes = excludedNodesForCapacity;
} else {
excludedNodes.add(node);
}
} }
} }
} }