HDFS-13703. Avoid allocation of CorruptedBlocks hashmap when no corrupted blocks are hit. Contributed by Todd Lipcon.

(cherry picked from commit 6ba9974108)
This commit is contained in:
Andrew Wang 2018-07-02 12:02:19 +02:00
parent e1cd5732a6
commit 0268b954e0
3 changed files with 8 additions and 7 deletions

View File

@ -1419,7 +1419,7 @@ public class DFSInputStream extends FSInputStream
Map<ExtendedBlock, Set<DatanodeInfo>> corruptedBlockMap =
corruptedBlocks.getCorruptionMap();
if (corruptedBlockMap.isEmpty()) {
if (corruptedBlockMap == null) {
return;
}
List<LocatedBlock> reportList = new ArrayList<>(corruptedBlockMap.size());

View File

@ -751,14 +751,14 @@ public class DFSUtilClient {
public static class CorruptedBlocks {
private Map<ExtendedBlock, Set<DatanodeInfo>> corruptionMap;
public CorruptedBlocks() {
this.corruptionMap = new HashMap<>();
}
/**
* Indicate a block replica on the specified datanode is corrupted
*/
public void addCorruptedBlock(ExtendedBlock blk, DatanodeInfo node) {
if (corruptionMap == null) {
corruptionMap = new HashMap<>();
}
Set<DatanodeInfo> dnSet = corruptionMap.get(blk);
if (dnSet == null) {
dnSet = new HashSet<>();
@ -770,7 +770,8 @@ public class DFSUtilClient {
}
/**
* @return the map that contains all the corruption entries.
* @return the map that contains all the corruption entries, or null if
* there were no corrupted entries
*/
public Map<ExtendedBlock, Set<DatanodeInfo>> getCorruptionMap() {
return corruptionMap;

View File

@ -1278,7 +1278,7 @@ public class DataNode extends ReconfigurableBase
DFSUtilClient.CorruptedBlocks corruptedBlocks) throws IOException {
Map<ExtendedBlock, Set<DatanodeInfo>> corruptionMap =
corruptedBlocks.getCorruptionMap();
if (!corruptionMap.isEmpty()) {
if (corruptionMap != null) {
for (Map.Entry<ExtendedBlock, Set<DatanodeInfo>> entry :
corruptionMap.entrySet()) {
for (DatanodeInfo dnInfo : entry.getValue()) {