HDFS-16377. Should CheckNotNull before access FsDatasetSpi (#3784)

Reviewed-by: Viraj Jasani <vjasani@apache.org>
Signed-off-by: Takanobu Asanuma <tasanuma@apache.org>
(cherry picked from commit 22f5e1885d21c9db9ceecf611128508542ec0f11)
This commit is contained in:
litao 2021-12-16 12:49:50 +08:00 committed by Chao Sun
parent 24917bae9f
commit c0ae38c6b4

View File

@ -791,6 +791,7 @@ private void refreshVolumes(String newVolumes) throws IOException {
.newFixedThreadPool(changedVolumes.newLocations.size()); .newFixedThreadPool(changedVolumes.newLocations.size());
List<Future<IOException>> exceptions = Lists.newArrayList(); List<Future<IOException>> exceptions = Lists.newArrayList();
Preconditions.checkNotNull(data, "Storage not yet initialized");
for (final StorageLocation location : changedVolumes.newLocations) { for (final StorageLocation location : changedVolumes.newLocations) {
exceptions.add(service.submit(new Callable<IOException>() { exceptions.add(service.submit(new Callable<IOException>() {
@Override @Override
@ -890,6 +891,7 @@ private synchronized void removeVolumes(
clearFailure, Joiner.on(",").join(storageLocations))); clearFailure, Joiner.on(",").join(storageLocations)));
IOException ioe = null; IOException ioe = null;
Preconditions.checkNotNull(data, "Storage not yet initialized");
// Remove volumes and block infos from FsDataset. // Remove volumes and block infos from FsDataset.
data.removeVolumes(storageLocations, clearFailure); data.removeVolumes(storageLocations, clearFailure);
@ -1968,6 +1970,7 @@ FileInputStream[] requestShortCircuitFdsForRead(final ExtendedBlock blk,
FileInputStream fis[] = new FileInputStream[2]; FileInputStream fis[] = new FileInputStream[2];
try { try {
Preconditions.checkNotNull(data, "Storage not yet initialized");
fis[0] = (FileInputStream)data.getBlockInputStream(blk, 0); fis[0] = (FileInputStream)data.getBlockInputStream(blk, 0);
fis[1] = DatanodeUtil.getMetaDataInputStream(blk, data); fis[1] = DatanodeUtil.getMetaDataInputStream(blk, data);
} catch (ClassCastException e) { } catch (ClassCastException e) {
@ -2947,6 +2950,7 @@ public static void main(String args[]) {
@Override // InterDatanodeProtocol @Override // InterDatanodeProtocol
public ReplicaRecoveryInfo initReplicaRecovery(RecoveringBlock rBlock) public ReplicaRecoveryInfo initReplicaRecovery(RecoveringBlock rBlock)
throws IOException { throws IOException {
Preconditions.checkNotNull(data, "Storage not yet initialized");
return data.initReplicaRecovery(rBlock); return data.initReplicaRecovery(rBlock);
} }
@ -2957,6 +2961,7 @@ public ReplicaRecoveryInfo initReplicaRecovery(RecoveringBlock rBlock)
public String updateReplicaUnderRecovery(final ExtendedBlock oldBlock, public String updateReplicaUnderRecovery(final ExtendedBlock oldBlock,
final long recoveryId, final long newBlockId, final long newLength) final long recoveryId, final long newBlockId, final long newLength)
throws IOException { throws IOException {
Preconditions.checkNotNull(data, "Storage not yet initialized");
final Replica r = data.updateReplicaUnderRecovery(oldBlock, final Replica r = data.updateReplicaUnderRecovery(oldBlock,
recoveryId, newBlockId, newLength); recoveryId, newBlockId, newLength);
// Notify the namenode of the updated block info. This is important // Notify the namenode of the updated block info. This is important
@ -3238,7 +3243,7 @@ public void deleteBlockPool(String blockPoolId, boolean force)
"The block pool is still running. First do a refreshNamenodes to " + "The block pool is still running. First do a refreshNamenodes to " +
"shutdown the block pool service"); "shutdown the block pool service");
} }
Preconditions.checkNotNull(data, "Storage not yet initialized");
data.deleteBlockPool(blockPoolId, force); data.deleteBlockPool(blockPoolId, force);
} }
@ -3682,6 +3687,7 @@ public String getSlowDisks() {
@Override @Override
public List<DatanodeVolumeInfo> getVolumeReport() throws IOException { public List<DatanodeVolumeInfo> getVolumeReport() throws IOException {
checkSuperuserPrivilege(); checkSuperuserPrivilege();
Preconditions.checkNotNull(data, "Storage not yet initialized");
Map<String, Object> volumeInfoMap = data.getVolumeInfoMap(); Map<String, Object> volumeInfoMap = data.getVolumeInfoMap();
if (volumeInfoMap == null) { if (volumeInfoMap == null) {
LOG.warn("DataNode volume info not available."); LOG.warn("DataNode volume info not available.");