From c7156503856e24faf844c5c647157b310d8b537f Mon Sep 17 00:00:00 2001 From: Vinayakumar B Date: Sat, 12 Sep 2015 17:40:16 +0530 Subject: [PATCH] HDFS-9036. In BlockPlacementPolicyWithNodeGroup#chooseLocalStorage , random node is selected eventhough fallbackToLocalRack is true. (Contributed by J.Andreina) --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 4 ++++ .../BlockPlacementPolicyWithNodeGroup.java | 14 ++++++-------- .../TestReplicationPolicyWithNodeGroup.java | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 5a42499d9d..0c891ab931 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -1315,6 +1315,10 @@ Release 2.8.0 - UNRELEASED HDFS-8581. ContentSummary on / skips further counts on yielding lock (J.Andreina via vinayakumarb) + HDFS-9036. In BlockPlacementPolicyWithNodeGroup#chooseLocalStorage , random + node is selected eventhough fallbackToLocalRack is true. + (J.Andreina via vinayakumarb) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyWithNodeGroup.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyWithNodeGroup.java index b1c4b7819e..89f47ad9d6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyWithNodeGroup.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyWithNodeGroup.java @@ -31,7 +31,7 @@ * for placing block replicas on environment with node-group layer. * The replica placement strategy is adjusted to: * If the writer is on a datanode, the 1st replica is placed on the local - * node (or local node-group), otherwise a random datanode. + * node(or local node-group or on local rack), otherwise a random datanode. * The 2nd replica is placed on a datanode that is on a different rack with 1st * replica node. * The 3rd replica is placed on a datanode which is on a different node-group @@ -165,7 +165,7 @@ protected void chooseRemoteRack(int numOfReplicas, /* choose one node from the nodegroup that localMachine is on. * if no such node is available, choose one node from the nodegroup where * a second replica is on. - * if still no such node is available, choose a random node in the cluster. + * if still no such node is available, return null. * @return the chosen node */ private DatanodeStorageInfo chooseLocalNodeGroup( @@ -195,14 +195,12 @@ private DatanodeStorageInfo chooseLocalNodeGroup( excludedNodes, blocksize, maxNodesPerRack, results, avoidStaleNodes, storageTypes); } catch(NotEnoughReplicasException e2) { - //otherwise randomly choose one from the network - return chooseRandom(NodeBase.ROOT, excludedNodes, blocksize, - maxNodesPerRack, results, avoidStaleNodes, storageTypes); + //otherwise return null + return null; } } else { - //otherwise randomly choose one from the network - return chooseRandom(NodeBase.ROOT, excludedNodes, blocksize, - maxNodesPerRack, results, avoidStaleNodes, storageTypes); + //otherwise return null + return null; } } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyWithNodeGroup.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyWithNodeGroup.java index ed54aeb571..e9739253fd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyWithNodeGroup.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyWithNodeGroup.java @@ -486,6 +486,25 @@ public void testChooseTarget5() throws Exception { verifyNoTwoTargetsOnSameNodeGroup(targets); } + /** + * In this testcase, client is dataNodes[7], but it is not qualified + * to be chosen. And there is no other node available on client Node group. + * So the 1st replica should be placed on client local rack dataNodes[6] + * @throws Exception + */ + @Test + public void testChooseTargetForLocalStorage() throws Exception { + updateHeartbeatWithUsage(dataNodes[7], + 2* HdfsServerConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0L, + (HdfsServerConstants.MIN_BLOCKS_FOR_WRITE-1)*BLOCK_SIZE, 0L, + 0L, 0L, 0, 0); // no space + + DatanodeStorageInfo[] targets; + targets = chooseTarget(1, dataNodes[7]); + assertEquals(targets.length, 1); + assertTrue(targets[0].getDatanodeDescriptor().equals(dataNodes[6])); + } + /** * This testcase tests re-replication, when dataNodes[0] is already chosen. * So the 1st replica can be placed on random rack.