HDFS-17624. Fix DFSNetworkTopology#chooseRandomWithStorageType() availableCount when excluded node is not in selected scope. (#7042). Contributed by fuchaohong.
Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
This commit is contained in:
parent
21cdb450ef
commit
3d81dde28b
@ -219,7 +219,8 @@ Node chooseRandomWithStorageType(final String scope,
|
|||||||
}
|
}
|
||||||
if (excludedNodes != null) {
|
if (excludedNodes != null) {
|
||||||
for (Node excludedNode : excludedNodes) {
|
for (Node excludedNode : excludedNodes) {
|
||||||
if (excludeRoot != null && isNodeInScope(excludedNode, excludedScope)) {
|
if ((excludeRoot != null && isNodeInScope(excludedNode, excludedScope)) ||
|
||||||
|
!isNodeInScope(excludedNode, scope)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (excludedNode instanceof DatanodeDescriptor) {
|
if (excludedNode instanceof DatanodeDescriptor) {
|
||||||
|
@ -667,4 +667,23 @@ public void testChooseRandomWithStorageTypeScopeEqualsExcludedNodes() {
|
|||||||
null, excluded, StorageType.DISK);
|
null, excluded, StorageType.DISK);
|
||||||
assertNull("No node should have been selected.", n);
|
assertNull("No node should have been selected.", n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testChooseRandomWithStorageTypeWithExcludeNodes() {
|
||||||
|
DFSNetworkTopology dfsCluster =
|
||||||
|
DFSNetworkTopology.getInstance(new Configuration());
|
||||||
|
final String[] racks = {"/default/rack1", "/default/rack2"};
|
||||||
|
final String[] hosts = {"host1", "host2"};
|
||||||
|
final StorageType[] types = {StorageType.DISK, StorageType.DISK};
|
||||||
|
final DatanodeStorageInfo[] storages =
|
||||||
|
DFSTestUtil.createDatanodeStorageInfos(2, racks, hosts, types);
|
||||||
|
DatanodeDescriptor[] dns = DFSTestUtil.toDatanodeDescriptor(storages);
|
||||||
|
dfsCluster.add(dns[0]);
|
||||||
|
dfsCluster.add(dns[1]);
|
||||||
|
HashSet<Node> excluded = new HashSet<>();
|
||||||
|
excluded.add(dns[1]);
|
||||||
|
Node n = dfsCluster.chooseRandomWithStorageType("/default/rack1",
|
||||||
|
null, excluded, StorageType.DISK);
|
||||||
|
assertNotNull("/default/rack1/host1 should be selected.", n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user