From d505c8acd30d6f40d0632fe9c93c886a4499a9fc Mon Sep 17 00:00:00 2001 From: Vinayakumar B Date: Wed, 8 Apr 2015 09:56:37 +0530 Subject: [PATCH] HDFS-8073. Split BlockPlacementPolicyDefault.chooseTarget(..) so it can be easily overrided. (Contributed by Walter Su) --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 + .../BlockPlacementPolicyDefault.java | 87 +++++++++++-------- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index f194bd780bd..ac508cb51d6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -385,6 +385,9 @@ Release 2.8.0 - UNRELEASED HDFS-8079. Move dfs.client.retry.* confs from DFSConfigKeys to HdfsClientConfigKeys.Retry. (szetszwo) + HDFS-8073. Split BlockPlacementPolicyDefault.chooseTarget(..) so it + can be easily overrided. (Walter Su via vinayakumarb) + OPTIMIZATIONS HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java index 32627726138..09db986b111 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java @@ -333,41 +333,8 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy { + " unavailableStorages=" + unavailableStorages + ", storagePolicy=" + storagePolicy); } - - if (numOfResults == 0) { - writer = chooseLocalStorage(writer, excludedNodes, blocksize, - maxNodesPerRack, results, avoidStaleNodes, storageTypes, true) - .getDatanodeDescriptor(); - if (--numOfReplicas == 0) { - return writer; - } - } - final DatanodeDescriptor dn0 = results.get(0).getDatanodeDescriptor(); - if (numOfResults <= 1) { - chooseRemoteRack(1, dn0, excludedNodes, blocksize, maxNodesPerRack, - results, avoidStaleNodes, storageTypes); - if (--numOfReplicas == 0) { - return writer; - } - } - if (numOfResults <= 2) { - final DatanodeDescriptor dn1 = results.get(1).getDatanodeDescriptor(); - if (clusterMap.isOnSameRack(dn0, dn1)) { - chooseRemoteRack(1, dn0, excludedNodes, blocksize, maxNodesPerRack, - results, avoidStaleNodes, storageTypes); - } else if (newBlock){ - chooseLocalRack(dn1, excludedNodes, blocksize, maxNodesPerRack, - results, avoidStaleNodes, storageTypes); - } else { - chooseLocalRack(writer, excludedNodes, blocksize, maxNodesPerRack, - results, avoidStaleNodes, storageTypes); - } - if (--numOfReplicas == 0) { - return writer; - } - } - chooseRandom(numOfReplicas, NodeBase.ROOT, excludedNodes, blocksize, - maxNodesPerRack, results, avoidStaleNodes, storageTypes); + writer = chooseTargetInOrder(numOfReplicas, writer, excludedNodes, blocksize, + maxNodesPerRack, results, avoidStaleNodes, newBlock, storageTypes); } catch (NotEnoughReplicasException e) { final String message = "Failed to place enough replicas, still in need of " + (totalReplicasExpected - results.size()) + " to reach " @@ -422,7 +389,55 @@ public class BlockPlacementPolicyDefault extends BlockPlacementPolicy { } return writer; } - + + protected Node chooseTargetInOrder(int numOfReplicas, + Node writer, + final Set excludedNodes, + final long blocksize, + final int maxNodesPerRack, + final List results, + final boolean avoidStaleNodes, + final boolean newBlock, + EnumMap storageTypes) + throws NotEnoughReplicasException { + final int numOfResults = results.size(); + if (numOfResults == 0) { + writer = chooseLocalStorage(writer, excludedNodes, blocksize, + maxNodesPerRack, results, avoidStaleNodes, storageTypes, true) + .getDatanodeDescriptor(); + if (--numOfReplicas == 0) { + return writer; + } + } + final DatanodeDescriptor dn0 = results.get(0).getDatanodeDescriptor(); + if (numOfResults <= 1) { + chooseRemoteRack(1, dn0, excludedNodes, blocksize, maxNodesPerRack, + results, avoidStaleNodes, storageTypes); + if (--numOfReplicas == 0) { + return writer; + } + } + if (numOfResults <= 2) { + final DatanodeDescriptor dn1 = results.get(1).getDatanodeDescriptor(); + if (clusterMap.isOnSameRack(dn0, dn1)) { + chooseRemoteRack(1, dn0, excludedNodes, blocksize, maxNodesPerRack, + results, avoidStaleNodes, storageTypes); + } else if (newBlock){ + chooseLocalRack(dn1, excludedNodes, blocksize, maxNodesPerRack, + results, avoidStaleNodes, storageTypes); + } else { + chooseLocalRack(writer, excludedNodes, blocksize, maxNodesPerRack, + results, avoidStaleNodes, storageTypes); + } + if (--numOfReplicas == 0) { + return writer; + } + } + chooseRandom(numOfReplicas, NodeBase.ROOT, excludedNodes, blocksize, + maxNodesPerRack, results, avoidStaleNodes, storageTypes); + return writer; + } + /** * Choose localMachine as the target. * if localMachine is not available,