[ 
https://issues.apache.org/jira/browse/HDFS-9350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15191491#comment-15191491
 ] 

Colin Patrick McCabe commented on HDFS-9350:
--------------------------------------------

Good catch, [~cnauroth].  I agree that we should restrict this method to just 
printing data from the base class.  However, Staffan's goal of reducing the 
number of memory allocations is nice.  How about this change?

{code}
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java
 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java
index 23bfa95..4128ece 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/Block.java
@@ -162,7 +162,9 @@ public void setGenerationStamp(long stamp) {
    */
   public static String toString(final Block b) {
     StringBuilder sb = new StringBuilder();
-    b.appendStringTo(sb);
+    sb.append(BLOCK_FILE_PREFIX).
+       append(b.blockId).append("_").
+       append(b.generationStamp);
     return sb.toString();
   }
{code}

> Avoid creating temprorary strings in Block.toString() and getBlockName()
> ------------------------------------------------------------------------
>
>                 Key: HDFS-9350
>                 URL: https://issues.apache.org/jira/browse/HDFS-9350
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: performance
>    Affects Versions: 2.7.1
>            Reporter: Staffan Friberg
>            Assignee: Staffan Friberg
>            Priority: Minor
>             Fix For: 2.9.0
>
>         Attachments: HDFS-9350.001.patch
>
>
> Minor change to use StringBuilders directly to avoid creating temporary 
> strings of Long and Block name when doing toString on a Block.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to