Skip to content

Commit

Permalink
HDFS-17298. Fix NPE in DataNode.handleBadBlock and BlockSender (#6374)
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyang1987 authored Dec 26, 2023
1 parent e07e445 commit 7e2ebfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7e2ebfc

Please sign in to comment.