HDFS-14853. NPE in DFSNetworkTopology#chooseRandomWithStorageType() when the excludedNode is not present. Contributed by Ranith Sardar.
This commit is contained in:
parent
2d7b37ea2b
commit
b7ee3938e9
|
@ -226,6 +226,9 @@ public class DFSNetworkTopology extends NetworkTopology {
|
||||||
String nodeLocation = excludedNode.getNetworkLocation()
|
String nodeLocation = excludedNode.getNetworkLocation()
|
||||||
+ "/" + excludedNode.getName();
|
+ "/" + excludedNode.getName();
|
||||||
DatanodeDescriptor dn = (DatanodeDescriptor)getNode(nodeLocation);
|
DatanodeDescriptor dn = (DatanodeDescriptor)getNode(nodeLocation);
|
||||||
|
if (dn == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
availableCount -= dn.hasStorageType(type)? 1 : 0;
|
availableCount -= dn.hasStorageType(type)? 1 : 0;
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Unexpected node type: {}.", excludedNode.getClass());
|
LOG.error("Unexpected node type: {}.", excludedNode.getClass());
|
||||||
|
|
|
@ -23,6 +23,8 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.StorageType;
|
import org.apache.hadoop.fs.StorageType;
|
||||||
import org.apache.hadoop.hdfs.DFSTestUtil;
|
import org.apache.hadoop.hdfs.DFSTestUtil;
|
||||||
|
import org.apache.hadoop.hdfs.protocol.DatanodeID;
|
||||||
|
import org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder;
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
|
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo;
|
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeStorageInfo;
|
||||||
import org.apache.hadoop.net.Node;
|
import org.apache.hadoop.net.Node;
|
||||||
|
@ -37,9 +39,11 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class tests the correctness of storage type info stored in
|
* This class tests the correctness of storage type info stored in
|
||||||
* DFSNetworkTopology.
|
* DFSNetworkTopology.
|
||||||
|
@ -368,6 +372,18 @@ public class TestDFSNetworkTopology {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testChooseRandomWithStorageTypeWithExcludedforNullCheck()
|
||||||
|
throws Exception {
|
||||||
|
HashSet<Node> excluded = new HashSet<>();
|
||||||
|
|
||||||
|
excluded.add(new DatanodeInfoBuilder()
|
||||||
|
.setNodeID(DatanodeID.EMPTY_DATANODE_ID).build());
|
||||||
|
Node node = CLUSTER.chooseRandomWithStorageType("/", "/l1/d1/r1", excluded,
|
||||||
|
StorageType.ARCHIVE);
|
||||||
|
|
||||||
|
assertNotNull(node);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test tests the wrapper method. The wrapper method only takes one scope
|
* This test tests the wrapper method. The wrapper method only takes one scope
|
||||||
|
|
Loading…
Reference in New Issue