From 099cbb427ad535c3369d9ac3fda6463502fc1c54 Mon Sep 17 00:00:00 2001 From: Brahma Reddy Battula Date: Tue, 20 Jun 2017 11:03:56 +0800 Subject: [PATCH] HDFS-11890. Handle NPE in BlockRecoveryWorker when DN is getting shoutdown. Contributed by Surendra Singh Lilhore. --- .../hdfs/server/datanode/BlockRecoveryWorker.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockRecoveryWorker.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockRecoveryWorker.java index 792b6af4ac5..15c4af1a12e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockRecoveryWorker.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockRecoveryWorker.java @@ -127,8 +127,7 @@ public class BlockRecoveryWorker { // - Original state is RWR or better for(DatanodeID id : locs) { try { - DatanodeID bpReg = new DatanodeID( - datanode.getBPOfferService(bpid).bpRegistration); + DatanodeID bpReg = getDatanodeID(bpid); InterDatanodeProtocol proxyDN = bpReg.equals(id)? datanode: DataNode.createInterDataNodeProtocolProxy(id, conf, dnConf.socketTimeout, dnConf.connectToDnViaHostname); @@ -398,8 +397,7 @@ public class BlockRecoveryWorker { for (int i = 0; i < locs.length; i++) { DatanodeID id = locs[i]; try { - DatanodeID bpReg = new DatanodeID( - datanode.getBPOfferService(bpid).bpRegistration); + DatanodeID bpReg = getDatanodeID(bpid); InterDatanodeProtocol proxyDN = bpReg.equals(id) ? datanode : DataNode.createInterDataNodeProtocolProxy(id, conf, 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) { ExtendedBlock block = rb.getBlock(); DatanodeInfo[] targets = rb.getLocations();