diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockSender.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockSender.java index d9ff1821b5..5ac6ee9ccb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockSender.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockSender.java @@ -41,6 +41,7 @@ import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.ReplicaState; import org.apache.hadoop.hdfs.server.common.DataNodeLockManager.LockLevel; import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeReference; +import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi; import org.apache.hadoop.hdfs.server.datanode.fsdataset.LengthInputStream; import org.apache.hadoop.hdfs.server.datanode.fsdataset.ReplicaInputStreams; import org.apache.hadoop.hdfs.util.DataTransferThrottler; @@ -295,7 +296,12 @@ class BlockSender implements java.io.Closeable { (!is32Bit || length <= Integer.MAX_VALUE); // Obtain a reference before reading data - volumeRef = datanode.data.getVolume(block).obtainReference(); + FsVolumeSpi volume = datanode.data.getVolume(block); + if (volume == null) { + LOG.warn("Cannot find FsVolumeSpi to obtain a reference for block: {}", block); + throw new ReplicaNotFoundException(block); + } + volumeRef = volume.obtainReference(); /* * (corruptChecksumOK, meta_file_exist): operation diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java index 9f73b1cd3c..53ec38dfa5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java @@ -4107,8 +4107,12 @@ void handleBadBlock(ExtendedBlock block, IOException e, boolean fromScanner) { return; } if (!fromScanner && blockScanner.isEnabled()) { - blockScanner.markSuspectBlock(data.getVolume(block).getStorageID(), - block); + FsVolumeSpi volume = data.getVolume(block); + if (volume == null) { + LOG.warn("Cannot find FsVolumeSpi to handle bad block: {}", block); + return; + } + blockScanner.markSuspectBlock(volume.getStorageID(), block); } else { try { reportBadBlocks(block);