HADOOP-12295. Improve NetworkTopology#InnerNode#remove logic. (yliu)
This commit is contained in:
parent
200fadedc0
commit
073cb16d81
|
@ -173,6 +173,8 @@ Release 2.8.0 - UNRELEASED
|
||||||
HADOOP-11813. releasedocmaker.py should use today's date instead of
|
HADOOP-11813. releasedocmaker.py should use today's date instead of
|
||||||
unreleased (Darrell Taylor via aw)
|
unreleased (Darrell Taylor via aw)
|
||||||
|
|
||||||
|
HADOOP-12295. Improve NetworkTopology#InnerNode#remove logic. (yliu)
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
HADOOP-12124. Add HTrace support for FsShell (cmccabe)
|
HADOOP-12124. Add HTrace support for FsShell (cmccabe)
|
||||||
|
|
|
@ -166,10 +166,11 @@ public class NetworkTopology {
|
||||||
* @return true if the node is added; false otherwise
|
* @return true if the node is added; false otherwise
|
||||||
*/
|
*/
|
||||||
boolean add(Node n) {
|
boolean add(Node n) {
|
||||||
if (!isAncestor(n))
|
if (!isAncestor(n)) {
|
||||||
throw new IllegalArgumentException(n.getName()+", which is located at "
|
throw new IllegalArgumentException(n.getName()
|
||||||
+n.getNetworkLocation()+", is not a decendent of "
|
+ ", which is located at " + n.getNetworkLocation()
|
||||||
+getPath(this));
|
+ ", is not a descendent of " + getPath(this));
|
||||||
|
}
|
||||||
if (isParent(n)) {
|
if (isParent(n)) {
|
||||||
// this node is the parent of n; add n directly
|
// this node is the parent of n; add n directly
|
||||||
n.setParent(this);
|
n.setParent(this);
|
||||||
|
@ -227,12 +228,11 @@ public class NetworkTopology {
|
||||||
* @return true if the node is deleted; false otherwise
|
* @return true if the node is deleted; false otherwise
|
||||||
*/
|
*/
|
||||||
boolean remove(Node n) {
|
boolean remove(Node n) {
|
||||||
String parent = n.getNetworkLocation();
|
if (!isAncestor(n)) {
|
||||||
String currentPath = getPath(this);
|
|
||||||
if (!isAncestor(n))
|
|
||||||
throw new IllegalArgumentException(n.getName()
|
throw new IllegalArgumentException(n.getName()
|
||||||
+", which is located at "
|
+ ", which is located at " + n.getNetworkLocation()
|
||||||
+parent+", is not a descendent of "+currentPath);
|
+ ", is not a descendent of " + getPath(this));
|
||||||
|
}
|
||||||
if (isParent(n)) {
|
if (isParent(n)) {
|
||||||
// this node is the parent of n; remove n directly
|
// this node is the parent of n; remove n directly
|
||||||
if (childrenMap.containsKey(n.getName())) {
|
if (childrenMap.containsKey(n.getName())) {
|
||||||
|
@ -250,14 +250,7 @@ public class NetworkTopology {
|
||||||
} else {
|
} else {
|
||||||
// find the next ancestor node: the parent node
|
// find the next ancestor node: the parent node
|
||||||
String parentName = getNextAncestorName(n);
|
String parentName = getNextAncestorName(n);
|
||||||
InnerNode parentNode = null;
|
InnerNode parentNode = (InnerNode)childrenMap.get(parentName);
|
||||||
int i;
|
|
||||||
for(i=0; i<children.size(); i++) {
|
|
||||||
if (children.get(i).getName().equals(parentName)) {
|
|
||||||
parentNode = (InnerNode)children.get(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (parentNode == null) {
|
if (parentNode == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -266,8 +259,13 @@ public class NetworkTopology {
|
||||||
// if the parent node has no children, remove the parent node too
|
// if the parent node has no children, remove the parent node too
|
||||||
if (isRemoved) {
|
if (isRemoved) {
|
||||||
if (parentNode.getNumOfChildren() == 0) {
|
if (parentNode.getNumOfChildren() == 0) {
|
||||||
Node prev = children.remove(i);
|
for(int i=0; i < children.size(); i++) {
|
||||||
childrenMap.remove(prev.getName());
|
if (children.get(i).getName().equals(parentName)) {
|
||||||
|
children.remove(i);
|
||||||
|
childrenMap.remove(parentName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
numOfLeaves--;
|
numOfLeaves--;
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,6 +251,7 @@ public class TestNetworkTopology {
|
||||||
assertFalse(cluster.contains(dataNodes[i]));
|
assertFalse(cluster.contains(dataNodes[i]));
|
||||||
}
|
}
|
||||||
assertEquals(0, cluster.getNumOfLeaves());
|
assertEquals(0, cluster.getNumOfLeaves());
|
||||||
|
assertEquals(0, cluster.clusterMap.children.size());
|
||||||
for(int i=0; i<dataNodes.length; i++) {
|
for(int i=0; i<dataNodes.length; i++) {
|
||||||
cluster.add(dataNodes[i]);
|
cluster.add(dataNodes[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue