Skip to content

Commit

Permalink
CDPD-35109. HDFS-16377. Should CheckNotNull before access FsDatasetSpi (
Browse files Browse the repository at this point in the history
apache#3784)

Reviewed-by: Viraj Jasani <[email protected]>
Signed-off-by: Takanobu Asanuma <[email protected]>
(cherry picked from commit 22f5e18)
(cherry picked from commit 3257646)
Change-Id: Icae290571be06f81cd15f82441201a201d350d9f
  • Loading branch information
tomscut authored and Stephen O'Donnell committed Jul 25, 2022
1 parent c93723e commit 9998f02
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ private void refreshVolumes(String newVolumes) throws IOException {
.newFixedThreadPool(changedVolumes.newLocations.size());
List<Future<IOException>> exceptions = Lists.newArrayList();

Preconditions.checkNotNull(data, "Storage not yet initialized");
for (final StorageLocation location : changedVolumes.newLocations) {
exceptions.add(service.submit(new Callable<IOException>() {
@Override
Expand Down Expand Up @@ -890,6 +891,7 @@ private synchronized void removeVolumes(
clearFailure, Joiner.on(",").join(storageLocations)));

IOException ioe = null;
Preconditions.checkNotNull(data, "Storage not yet initialized");
// Remove volumes and block infos from FsDataset.
data.removeVolumes(storageLocations, clearFailure);

Expand Down Expand Up @@ -1977,6 +1979,7 @@ FileInputStream[] requestShortCircuitFdsForRead(final ExtendedBlock blk,
FileInputStream fis[] = new FileInputStream[2];

try {
Preconditions.checkNotNull(data, "Storage not yet initialized");
fis[0] = (FileInputStream)data.getBlockInputStream(blk, 0);
fis[1] = DatanodeUtil.getMetaDataInputStream(blk, data);
} catch (ClassCastException e) {
Expand Down Expand Up @@ -2955,6 +2958,7 @@ public static void main(String args[]) {
@Override // InterDatanodeProtocol
public ReplicaRecoveryInfo initReplicaRecovery(RecoveringBlock rBlock)
throws IOException {
Preconditions.checkNotNull(data, "Storage not yet initialized");
return data.initReplicaRecovery(rBlock);
}

Expand All @@ -2965,6 +2969,7 @@ public ReplicaRecoveryInfo initReplicaRecovery(RecoveringBlock rBlock)
public String updateReplicaUnderRecovery(final ExtendedBlock oldBlock,
final long recoveryId, final long newBlockId, final long newLength)
throws IOException {
Preconditions.checkNotNull(data, "Storage not yet initialized");
final Replica r = data.updateReplicaUnderRecovery(oldBlock,
recoveryId, newBlockId, newLength);
// Notify the namenode of the updated block info. This is important
Expand Down Expand Up @@ -3232,7 +3237,7 @@ public void deleteBlockPool(String blockPoolId, boolean force)
"The block pool is still running. First do a refreshNamenodes to " +
"shutdown the block pool service");
}

Preconditions.checkNotNull(data, "Storage not yet initialized");
data.deleteBlockPool(blockPoolId, force);
}

Expand Down Expand Up @@ -3684,6 +3689,7 @@ public String getSlowDisks() {
@Override
public List<DatanodeVolumeInfo> getVolumeReport() throws IOException {
checkSuperuserPrivilege();
Preconditions.checkNotNull(data, "Storage not yet initialized");
Map<String, Object> volumeInfoMap = data.getVolumeInfoMap();
if (volumeInfoMap == null) {
LOG.warn("DataNode volume info not available.");
Expand Down

0 comments on commit 9998f02

Please sign in to comment.