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

Chris Nauroth commented on HDFS-9350:
-------------------------------------

I think this patch should be reverted, because it broke the contract of the 
static {{Block#toString}} method.  Here is the code before the patch:

{code}
  /**
   * A helper method to output the string representation of the Block portion of
   * a derived class' instance.
   *
   * @param b the target object
   * @return the string representation of the block
   */
  public static String toString(final Block b) {
    return getBlockName() + "_" + getGenerationStamp();
  }
{code}

Here is the code after the patch:
{code}
  /**
   * A helper method to output the string representation of the Block portion of
   * a derived class' instance.
   *
   * @param b the target object
   * @return the string representation of the block
   */
  public static String toString(final Block b) {
    StringBuilder sb = new StringBuilder();
    b.appendStringTo(sb);
    return sb.toString();
  }
{code}

Notice that the JavaDocs say this method is supposed to provide just the basic 
{{Block}} data, even in cases where the parameter is a subclass that may have 
overridden {{appendStringTo}}.  Having a widening cast to {{Block}} in the 
method signature's argument does not influence the outcome of runtime dynamic 
dispatch.  One specific problem would be {{ReplicaUnderConstruction}}, which 
overrides {{appendStringTo}}, so passing an instance of that will not in fact 
give the caller the basic {{Block}} data.

Thoughts?  Cc'ing [~jojochuang], who I think is the original author of the 
static {{Block#toString}} method.  He can help confirm the intent of the method.

> 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