diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 0d586cfc1e1..e64aa999ee5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -201,6 +201,8 @@ Release 0.23.3 - UNRELEASED OPTIMIZATIONS + HDFS-3024. Improve performance of stringification in addStoredBlock (todd) + BUG FIXES HDFS-2481. Unknown protocol: org.apache.hadoop.hdfs.protocol.ClientProtocol. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java index f6bf6b0b715..33c86f96d89 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java @@ -150,6 +150,14 @@ public class Block implements Writable, Comparable { return getBlockName() + "_" + getGenerationStamp(); } + public void appendStringTo(StringBuilder sb) { + sb.append(BLOCK_FILE_PREFIX) + .append(blockId) + .append("_") + .append(getGenerationStamp()); + } + + ///////////////////////////////////// // Writable ///////////////////////////////////// diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoUnderConstruction.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoUnderConstruction.java index beeb2c8fa21..6509f3d7fa9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoUnderConstruction.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockInfoUnderConstruction.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs.server.blockmanagement; import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import org.apache.hadoop.hdfs.protocol.Block; @@ -114,14 +115,19 @@ public class BlockInfoUnderConstruction extends BlockInfo { @Override public String toString() { - final StringBuilder b = new StringBuilder(getClass().getSimpleName()); - b.append("[") - .append(expectedLocation) - .append("|") - .append(state) - .append("]"); + final StringBuilder b = new StringBuilder(50); + appendStringTo(b); return b.toString(); } + + @Override + public void appendStringTo(StringBuilder sb) { + sb.append("ReplicaUnderConstruction[") + .append(expectedLocation) + .append("|") + .append(state) + .append("]"); + } } /** @@ -269,11 +275,29 @@ public class BlockInfoUnderConstruction extends BlockInfo { @Override public String toString() { - final StringBuilder b = new StringBuilder(super.toString()); - b.append("{blockUCState=").append(blockUCState) - .append(", primaryNodeIndex=").append(primaryNodeIndex) - .append(", replicas=").append(replicas) - .append("}"); + final StringBuilder b = new StringBuilder(100); + appendStringTo(b); return b.toString(); } + + @Override + public void appendStringTo(StringBuilder sb) { + super.appendStringTo(sb); + appendUCParts(sb); + } + + private void appendUCParts(StringBuilder sb) { + sb.append("{blockUCState=").append(blockUCState) + .append(", primaryNodeIndex=").append(primaryNodeIndex) + .append(", replicas=["); + Iterator iter = replicas.iterator(); + if (iter.hasNext()) { + iter.next().appendStringTo(sb); + while (iter.hasNext()) { + sb.append(", "); + iter.next().appendStringTo(sb); + } + } + sb.append("]}"); + } } 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 ada3d7c85c2..c8f36a01d96 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 @@ -1722,9 +1722,7 @@ public class BlockManager { if (added) { curReplicaDelta = 1; if (logEveryBlock) { - NameNode.stateChangeLog.info("BLOCK* addStoredBlock: " - + "blockMap updated: " + node.getName() + " is added to " + - storedBlock + " size " + storedBlock.getNumBytes()); + logAddStoredBlock(storedBlock, node); } } else { curReplicaDelta = 0; @@ -1784,6 +1782,20 @@ public class BlockManager { return storedBlock; } + private void logAddStoredBlock(BlockInfo storedBlock, DatanodeDescriptor node) { + if (!NameNode.stateChangeLog.isInfoEnabled()) { + return; + } + + StringBuilder sb = new StringBuilder(500); + sb.append("BLOCK* addStoredBlock: blockMap updated: ") + .append(node.getName()) + .append(" is added to "); + storedBlock.appendStringTo(sb); + sb.append(" size " ) + .append(storedBlock.getNumBytes()); + NameNode.stateChangeLog.info(sb); + } /** * Invalidate corrupt replicas. *