HDFS-17298. Fix NPE in DataNode.handleBadBlock and BlockSender (#6374)

This commit is contained in:
huhaiyang 2023-12-26 08:41:10 +08:00 committed by GitHub
parent e07e445326
commit 7e2ebfc17e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -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

View File

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