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

Muddy Dixon commented on HDFS-3015:
-----------------------------------

I surveys NamenodeFsck, JspHelper, DFSInputStream and DFSClient (which referred 
in NamenodeFsck#copyBlock comment).

"copyBlock" is declared in 
* NamenodeFsck

"bestNode" is declared in
* NamenodeFsck
* DFSInputStream
* JspHelper (3 arg patterns)

At first, copyBlock is not declared duplicate.



And then, all implementations of bestNode have different arg patterns and 
implementation.
So these are not duplicated.



NamenodeFsck#bestNode and DFSInputStream#bestNode are similar implementation.

NamenodeFsck
{code}

  private DatanodeInfo bestNode(DFSClient dfs, DatanodeInfo[] nodes,
                                TreeSet<DatanodeInfo> deadNodes) throws 
IOException {
    if ((nodes == null) ||
        (nodes.length - deadNodes.size() < 1)) {
      throw new IOException("No live nodes contain current block");
    }
    DatanodeInfo chosenNode;
    do {
      chosenNode = nodes[DFSUtil.getRandom().nextInt(nodes.length)];
    } while (deadNodes.contains(chosenNode));
    return chosenNode;
  }
{code}

DFSInputStream#bestNode
{code}

  static DatanodeInfo bestNode(DatanodeInfo nodes[], 
                               AbstractMap<DatanodeInfo, DatanodeInfo> 
deadNodes)
                               throws IOException {
    if (nodes != null) { 
      for (int i = 0; i < nodes.length; i++) {
        if (!deadNodes.containsKey(nodes[i])) {
          return nodes[i];
        }
      }
    }
    throw new IOException("No live nodes contain current block");
  }
{code}
                
> NamenodeFsck and JspHelper duplicate DFSInputStream#copyBlock and bestNode
> --------------------------------------------------------------------------
>
>                 Key: HDFS-3015
>                 URL: https://issues.apache.org/jira/browse/HDFS-3015
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>            Reporter: Eli Collins
>            Priority: Minor
>              Labels: newbie
>
> Both NamenodeFsck and JspHelper duplicate DFSInputStream#copyBlock and 
> bestNode. There should be one shared implementation.
> {code}
>   /*
>    * XXX (ab) Bulk of this method is copied verbatim from {@link DFSClient}, 
> which is
>    * bad. Both places should be refactored to provide a method to copy blocks
>    * around.
>    */
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to