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();