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

This commit is contained in:
Andrew Wang 2018-07-02 12:02:19 +02:00
parent d40121845e
commit 6ba9974108
3 changed files with 8 additions and 7 deletions

View File

@ -1423,7 +1423,7 @@ protected void reportCheckSumFailure(CorruptedBlocks corruptedBlocks,
Map<ExtendedBlock, Set<DatanodeInfo>> corruptedBlockMap = Map<ExtendedBlock, Set<DatanodeInfo>> corruptedBlockMap =
corruptedBlocks.getCorruptionMap(); corruptedBlocks.getCorruptionMap();
if (corruptedBlockMap.isEmpty()) { if (corruptedBlockMap == null) {
return; return;
} }
List<LocatedBlock> reportList = new ArrayList<>(corruptedBlockMap.size()); List<LocatedBlock> reportList = new ArrayList<>(corruptedBlockMap.size());

View File

@ -751,14 +751,14 @@ public static InterruptedIOException toInterruptedIOException(String message,
public static class CorruptedBlocks { public static class CorruptedBlocks {
private Map<ExtendedBlock, Set<DatanodeInfo>> corruptionMap; private Map<ExtendedBlock, Set<DatanodeInfo>> corruptionMap;
public CorruptedBlocks() {
this.corruptionMap = new HashMap<>();
}
/** /**
* Indicate a block replica on the specified datanode is corrupted * Indicate a block replica on the specified datanode is corrupted
*/ */
public void addCorruptedBlock(ExtendedBlock blk, DatanodeInfo node) { public void addCorruptedBlock(ExtendedBlock blk, DatanodeInfo node) {
if (corruptionMap == null) {
corruptionMap = new HashMap<>();
}
Set<DatanodeInfo> dnSet = corruptionMap.get(blk); Set<DatanodeInfo> dnSet = corruptionMap.get(blk);
if (dnSet == null) { if (dnSet == null) {
dnSet = new HashSet<>(); dnSet = new HashSet<>();
@ -770,7 +770,8 @@ public void addCorruptedBlock(ExtendedBlock blk, DatanodeInfo node) {
} }
/** /**
* @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() { public Map<ExtendedBlock, Set<DatanodeInfo>> getCorruptionMap() {
return corruptionMap; return corruptionMap;

View File

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