Skip to content

Commit 4886732

Browse files
committed
HDFS-3601. Add BlockPlacementPolicyWithNodeGroup to support block placement with 4-layer network topology. Contributed by Junping Du
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1357442 13f79535-47bb-0310-9956-ffa450edef68
1 parent d3a6024 commit 4886732

File tree

6 files changed

+853
-6
lines changed

6 files changed

+853
-6
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ boolean add(Node n) {
170170
}
171171
if (parentNode == null) {
172172
// create a new InnerNode
173-
parentNode = new InnerNode(parentName, getPath(this),
174-
this, this.getLevel()+1);
173+
parentNode = createParentNode(parentName);
175174
children.add(parentNode);
176175
}
177176
// add n to the subtree of the next ancestor node
@@ -288,7 +287,7 @@ Node getLeaf(int leafIndex, Node excludedNode) {
288287
// calculate the total number of excluded leaf nodes
289288
int numOfExcludedLeaves =
290289
isLeaf ? 1 : ((InnerNode)excludedNode).getNumOfLeaves();
291-
if (isRack()) { // children are leaves
290+
if (isLeafParent()) { // children are leaves
292291
if (isLeaf) { // excluded node is a leaf node
293292
int excludedIndex = children.indexOf(excludedNode);
294293
if (excludedIndex != -1 && leafIndex >= 0) {
@@ -326,6 +325,10 @@ Node getLeaf(int leafIndex, Node excludedNode) {
326325
}
327326
}
328327

328+
protected boolean isLeafParent() {
329+
return isRack();
330+
}
331+
329332
/**
330333
* Determine if children a leaves, default implementation calls {@link #isRack()}
331334
* <p>To be overridden in subclasses for specific InnerNode implementations,
@@ -752,6 +755,30 @@ public String toString() {
752755
}
753756
return tree.toString();
754757
}
758+
759+
/**
760+
* Divide networklocation string into two parts by last separator, and get
761+
* the first part here.
762+
*
763+
* @param networkLocation
764+
* @return
765+
*/
766+
public static String getFirstHalf(String networkLocation) {
767+
int index = networkLocation.lastIndexOf(NodeBase.PATH_SEPARATOR_STR);
768+
return networkLocation.substring(0, index);
769+
}
770+
771+
/**
772+
* Divide networklocation string into two parts by last separator, and get
773+
* the second part here.
774+
*
775+
* @param networkLocation
776+
* @return
777+
*/
778+
public static String getLastHalf(String networkLocation) {
779+
int index = networkLocation.lastIndexOf(NodeBase.PATH_SEPARATOR_STR);
780+
return networkLocation.substring(index);
781+
}
755782

756783
/** swap two array items */
757784
static protected void swap(Node[] nodes, int i, int j) {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopologyWithNodeGroup.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected Node getNodeForNetworkLocation(Node node) {
4949
}
5050
Node nodeGroup = getNode(node.getNetworkLocation());
5151
if (nodeGroup == null) {
52-
nodeGroup = new InnerNode(node.getNetworkLocation());
52+
nodeGroup = new InnerNodeWithNodeGroup(node.getNetworkLocation());
5353
}
5454
return getNode(nodeGroup.getNetworkLocation());
5555
}
@@ -383,6 +383,11 @@ boolean isNodeGroup() {
383383
}
384384
return true;
385385
}
386+
387+
@Override
388+
protected boolean isLeafParent() {
389+
return isNodeGroup();
390+
}
386391

387392
@Override
388393
protected InnerNode createParentNode(String parentName) {

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Trunk (unreleased changes)
1313

1414
HDFS-3125. Add JournalService to enable Journal Daemon. (suresh)
1515

16+
HDFS-3601. Add BlockPlacementPolicyWithNodeGroup to support block placement
17+
with 4-layer network topology. (Junping Du via szetszwo)
18+
1619
IMPROVEMENTS
1720

1821
HDFS-1620. Rename HdfsConstants -> HdfsServerConstants, FSConstants ->

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ DatanodeDescriptor[] chooseTarget(int numOfReplicas,
148148
new ArrayList<DatanodeDescriptor>(chosenNodes);
149149
for (Node node:chosenNodes) {
150150
excludedNodes.put(node, node);
151+
adjustExcludedNodes(excludedNodes, node);
151152
}
152153

153154
if (!clusterMap.contains(writer)) {
@@ -359,10 +360,11 @@ protected DatanodeDescriptor chooseRandom(
359360
(DatanodeDescriptor)(clusterMap.chooseRandom(nodes));
360361

361362
Node oldNode = excludedNodes.put(chosenNode, chosenNode);
362-
if (oldNode == null) { // choosendNode was not in the excluded list
363+
if (oldNode == null) { // chosenNode was not in the excluded list
363364
numOfAvailableNodes--;
364365
if (isGoodTarget(chosenNode, blocksize, maxNodesPerRack, results)) {
365366
results.add(chosenNode);
367+
adjustExcludedNodes(excludedNodes, chosenNode);
366368
return chosenNode;
367369
} else {
368370
badTarget = true;
@@ -409,6 +411,7 @@ protected void chooseRandom(int numOfReplicas,
409411
if (isGoodTarget(chosenNode, blocksize, maxNodesPerRack, results)) {
410412
numOfReplicas--;
411413
results.add(chosenNode);
414+
adjustExcludedNodes(excludedNodes, chosenNode);
412415
} else {
413416
badTarget = true;
414417
}
@@ -426,7 +429,21 @@ protected void chooseRandom(int numOfReplicas,
426429
throw new NotEnoughReplicasException(detail);
427430
}
428431
}
429-
432+
433+
/**
434+
* After choosing a node to place replica, adjust excluded nodes accordingly.
435+
* It should do nothing here as chosenNode is already put into exlcudeNodes,
436+
* but it can be overridden in subclass to put more related nodes into
437+
* excludedNodes.
438+
*
439+
* @param excludedNodes
440+
* @param chosenNode
441+
*/
442+
protected void adjustExcludedNodes(HashMap<Node, Node> excludedNodes,
443+
Node chosenNode) {
444+
// do nothing here.
445+
}
446+
430447
/* judge if a node is a good target.
431448
* return true if <i>node</i> has enough space,
432449
* does not have too much load, and the rack does not have too many nodes

0 commit comments

Comments
 (0)