HADOOP-13666. Supporting rack exclusion in countNumOfAvailableNodes in NetworkTopology. Contributed by Inigo Goiri.
This commit is contained in:
parent
439d935e1d
commit
84f7638840
@ -670,7 +670,11 @@ public int countNumOfAvailableNodes(String scope,
|
|||||||
}
|
}
|
||||||
if ((NodeBase.getPath(node) + NodeBase.PATH_SEPARATOR_STR)
|
if ((NodeBase.getPath(node) + NodeBase.PATH_SEPARATOR_STR)
|
||||||
.startsWith(scope + NodeBase.PATH_SEPARATOR_STR)) {
|
.startsWith(scope + NodeBase.PATH_SEPARATOR_STR)) {
|
||||||
excludedCountInScope++;
|
if (node instanceof InnerNode) {
|
||||||
|
excludedCountInScope += ((InnerNode) node).getNumOfLeaves();
|
||||||
|
} else {
|
||||||
|
excludedCountInScope++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
excludedCountOffScope++;
|
excludedCountOffScope++;
|
||||||
}
|
}
|
||||||
|
@ -614,4 +614,22 @@ public void testChooseRandomInclude3() {
|
|||||||
frequency.get(dataNodes[i]) > 0);
|
frequency.get(dataNodes[i]) > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCountNumOfAvailableNodes() {
|
||||||
|
int numNodes = cluster.countNumOfAvailableNodes(NodeBase.ROOT, null);
|
||||||
|
assertEquals(20, numNodes);
|
||||||
|
|
||||||
|
// Excluding a single node
|
||||||
|
Collection<Node> excludedNodes = new HashSet<Node>();
|
||||||
|
excludedNodes.add(dataNodes[0]);
|
||||||
|
numNodes = cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes);
|
||||||
|
assertEquals(19, numNodes);
|
||||||
|
|
||||||
|
// Excluding a full rack
|
||||||
|
Node d4r1 = cluster.getNode("/d4/r1");
|
||||||
|
excludedNodes.add(d4r1);
|
||||||
|
numNodes = cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes);
|
||||||
|
assertEquals(12, numNodes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user