HDFS-11890. Handle NPE in BlockRecoveryWorker when DN is getting shoutdown. Contributed by Surendra Singh Lilhore.

This commit is contained in:
Brahma Reddy Battula 2017-06-20 11:03:56 +08:00
parent d954a64730
commit 099cbb427a
1 changed files with 10 additions and 4 deletions

View File

@ -127,8 +127,7 @@ public class BlockRecoveryWorker {
// - Original state is RWR or better // - Original state is RWR or better
for(DatanodeID id : locs) { for(DatanodeID id : locs) {
try { try {
DatanodeID bpReg = new DatanodeID( DatanodeID bpReg = getDatanodeID(bpid);
datanode.getBPOfferService(bpid).bpRegistration);
InterDatanodeProtocol proxyDN = bpReg.equals(id)? InterDatanodeProtocol proxyDN = bpReg.equals(id)?
datanode: DataNode.createInterDataNodeProtocolProxy(id, conf, datanode: DataNode.createInterDataNodeProtocolProxy(id, conf,
dnConf.socketTimeout, dnConf.connectToDnViaHostname); dnConf.socketTimeout, dnConf.connectToDnViaHostname);
@ -398,8 +397,7 @@ public class BlockRecoveryWorker {
for (int i = 0; i < locs.length; i++) { for (int i = 0; i < locs.length; i++) {
DatanodeID id = locs[i]; DatanodeID id = locs[i];
try { try {
DatanodeID bpReg = new DatanodeID( DatanodeID bpReg = getDatanodeID(bpid);
datanode.getBPOfferService(bpid).bpRegistration);
InterDatanodeProtocol proxyDN = bpReg.equals(id) ? InterDatanodeProtocol proxyDN = bpReg.equals(id) ?
datanode : DataNode.createInterDataNodeProtocolProxy(id, conf, datanode : DataNode.createInterDataNodeProtocolProxy(id, conf,
dnConf.socketTimeout, dnConf.connectToDnViaHostname); dnConf.socketTimeout, dnConf.connectToDnViaHostname);
@ -532,6 +530,14 @@ public class BlockRecoveryWorker {
} }
} }
private DatanodeID getDatanodeID(String bpid) throws IOException {
BPOfferService bpos = datanode.getBPOfferService(bpid);
if (bpos == null) {
throw new IOException("No block pool offer service for bpid=" + bpid);
}
return new DatanodeID(bpos.bpRegistration);
}
private static void logRecoverBlock(String who, RecoveringBlock rb) { private static void logRecoverBlock(String who, RecoveringBlock rb) {
ExtendedBlock block = rb.getBlock(); ExtendedBlock block = rb.getBlock();
DatanodeInfo[] targets = rb.getLocations(); DatanodeInfo[] targets = rb.getLocations();