From 2685e16f381532d53aea413ce1c0a14181ee7c89 Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Tue, 19 Jul 2016 15:13:01 -0700 Subject: [PATCH] HDFS-10620. StringBuilder created and appended even if logging is disabled. Contributed by Staffan Friberg. (cherry picked from commit f7dabe3addf3f6eb32ea9b8ec1354fb442ce4222) --- .../hadoop/hdfs/server/blockmanagement/BlockManager.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java index 0f6d6dd09ea..04e349af9ae 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java @@ -1195,16 +1195,19 @@ public class BlockManager implements BlockStatsMXBean { if (!isPopulatingReplQueues()) { return; } - StringBuilder datanodes = new StringBuilder(); + StringBuilder datanodes = blockLog.isDebugEnabled() + ? new StringBuilder() : null; for (DatanodeStorageInfo storage : blocksMap.getStorages(b)) { if (storage.getState() != State.NORMAL) { continue; } final DatanodeDescriptor node = storage.getDatanodeDescriptor(); invalidateBlocks.add(b, node, false); - datanodes.append(node).append(" "); + if (datanodes != null) { + datanodes.append(node).append(" "); + } } - if (datanodes.length() != 0) { + if (datanodes != null & datanodes.length() != 0) { blockLog.debug("BLOCK* addToInvalidates: {} {}", b, datanodes); } }