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

Kihwal Lee commented on HDFS-7300:
----------------------------------

The base formula for caluculating the value is
{noformat}
  maxNodesPerRack = (totalNumOfReplicas-1)/numOfRacks + 2
{noformat}

In the patch, the single rack case and the single replica case are handled 
without applying this formula. Then it is guaranteed that the number of rack is 
greater than 1 when calculating the max value.  It is also guaranteed to give a 
sufficiently big max value.

{noformat}
  maxNodePerRack * numOfRacks >= totalNumOfReplicas
  totalNumOfReplicas-1 + 2 * numOfRack >= totalNumOfReplicas
  numOfRack >= 0.5
{noformat}

Since numOfRacks is greater than 1, maxNodePerRack is guaranteed to be large 
enough.
In order to take care of the case of {{maxNodePerRack == totalNumOfReplicas}}, 
which happens in the cases described in the description, maxNodePerRack is 
decremented if necessary. This still results in a sufficiently large value.

{noformat}
  (maxNodePerRack - 1) * numOfRacks > totalNumOfReplicas
  totalNumOfReplicas-1 + numOfRack > totalNumOfReplicas
  numOfRack > 1
{noformat}

It shows the resulting max value is not only large enough, but also allows a 
bit of slack for unbalanced racks, as the original formula does.

> The getMaxNodesPerRack() method in BlockPlacementPolicyDefault is flawed
> ------------------------------------------------------------------------
>
>                 Key: HDFS-7300
>                 URL: https://issues.apache.org/jira/browse/HDFS-7300
>             Project: Hadoop HDFS
>          Issue Type: Bug
>            Reporter: Kihwal Lee
>            Assignee: Kihwal Lee
>            Priority: Critical
>         Attachments: HDFS-7300.patch
>
>
> The {{getMaxNodesPerRack()}} can produce an undesirable result in some cases.
> - Three replicas on two racks. The max is 3, so everything can go to one rack.
> - Two replicas on two or more racks. The max is 2, both replicas can end up 
> in the same rack.
> {{BlockManager#isNeededReplication()}} fixes this after block/file is closed 
> because {{blockHasEnoughRacks()}} will return fail.  This is not only extra 
> work, but also can break the favored nodes feature.
> When there are two racks and two favored nodes are specified in the same 
> rack, NN may allocate the third replica on a node in the same rack, because 
> {{maxNodesPerRack}} is 3. When closing the file, NN moves a block to the 
> other rack. There is 66% chance that a favored node is moved.  If 
> {{maxNodesPerRack}} was 2, this would not happen.



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

Reply via email to