HDFS-14216. NullPointerException happens in NamenodeWebHdfs. Contributed by lujie.
(cherry picked from commit 92b53c40f0
)
This commit is contained in:
parent
685a41f449
commit
2e939515df
|
@ -273,11 +273,19 @@ public class NamenodeWebHdfsMethods {
|
||||||
for (String host : StringUtils
|
for (String host : StringUtils
|
||||||
.getTrimmedStringCollection(excludeDatanodes)) {
|
.getTrimmedStringCollection(excludeDatanodes)) {
|
||||||
int idx = host.indexOf(":");
|
int idx = host.indexOf(":");
|
||||||
|
Node excludeNode = null;
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
excludes.add(bm.getDatanodeManager().getDatanodeByXferAddr(
|
excludeNode = bm.getDatanodeManager().getDatanodeByXferAddr(
|
||||||
host.substring(0, idx), Integer.parseInt(host.substring(idx + 1))));
|
host.substring(0, idx), Integer.parseInt(host.substring(idx + 1)));
|
||||||
} else {
|
} else {
|
||||||
excludes.add(bm.getDatanodeManager().getDatanodeByHost(host));
|
excludeNode = bm.getDatanodeManager().getDatanodeByHost(host);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (excludeNode != null) {
|
||||||
|
excludes.add(excludeNode);
|
||||||
|
} else {
|
||||||
|
LOG.debug("DataNode {} was requested to be excluded, "
|
||||||
|
+ "but it was not found.", host);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,6 +239,29 @@ public class TestWebHdfsDataLocality {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExcludeWrongDataNode() throws Exception {
|
||||||
|
final Configuration conf = WebHdfsTestUtil.createConf();
|
||||||
|
final String[] racks = {RACK0};
|
||||||
|
final String[] hosts = {"DataNode1"};
|
||||||
|
final int nDataNodes = hosts.length;
|
||||||
|
|
||||||
|
final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
|
||||||
|
.hosts(hosts).numDataNodes(nDataNodes).racks(racks).build();
|
||||||
|
try {
|
||||||
|
cluster.waitActive();
|
||||||
|
final NameNode namenode = cluster.getNameNode();
|
||||||
|
NamenodeWebHdfsMethods.chooseDatanode(
|
||||||
|
namenode, "/path", PutOpParam.Op.CREATE, 0,
|
||||||
|
DFSConfigKeys.DFS_BLOCK_SIZE_DEFAULT,
|
||||||
|
"DataNode2", LOCALHOST, null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Assert.fail("Failed to exclude DataNode2" + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
cluster.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChooseDatanodeBeforeNamesystemInit() throws Exception {
|
public void testChooseDatanodeBeforeNamesystemInit() throws Exception {
|
||||||
NameNode nn = mock(NameNode.class);
|
NameNode nn = mock(NameNode.class);
|
||||||
|
|
Loading…
Reference in New Issue