Author: eli
Date: Mon Mar 26 21:30:51 2012
New Revision: 1305613
URL: http://svn.apache.org/viewvc?rev=1305613&view=rev
Log:
HADOOP-8159. NetworkTopology: getLeaf should check for invalid topologies.
Contributed by Colin Patrick McCabe
Modified:
hadoop/common/branches/branch-1/CHANGES.txt
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/net/NetworkTopology.java
Modified: hadoop/common/branches/branch-1/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/CHANGES.txt?rev=1305613&r1=1305612&r2=1305613&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/CHANGES.txt (original)
+++ hadoop/common/branches/branch-1/CHANGES.txt Mon Mar 26 21:30:51 2012
@@ -172,6 +172,9 @@ Release 1.1.0 - unreleased
MAPREDUCE-3992. Reduce fetcher doesn't verify HTTP status code of response
(todd)
+ HADOOP-8159. NetworkTopology: getLeaf should check for invalid topologies.
+ (Colin Patrick McCabe via eli)
+
Release 1.0.3 - unreleased
NEW FEATURES
Modified:
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/net/NetworkTopology.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/core/org/apache/hadoop/net/NetworkTopology.java?rev=1305613&r1=1305612&r2=1305613&view=diff
==============================================================================
---
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/net/NetworkTopology.java
(original)
+++
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/net/NetworkTopology.java
Mon Mar 26 21:30:51 2012
@@ -42,6 +42,13 @@ public class NetworkTopology {
public static final Log LOG =
LogFactory.getLog(NetworkTopology.class);
+ public static class InvalidTopologyException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+ public InvalidTopologyException(String msg) {
+ super(msg);
+ }
+ }
+
/* Inner Node represent a switch/router of a data center or rack.
* Different from a leave node, it has non-null children.
*/
@@ -296,6 +303,8 @@ public class NetworkTopology {
} // end of InnerNode
InnerNode clusterMap = new InnerNode(InnerNode.ROOT); // the root
+ /** Depth of all leaf nodes */
+ private int depthOfAllLeaves = -1;
private int numOfRacks = 0; // rack counter
private ReadWriteLock netlock;
@@ -312,6 +321,7 @@ public class NetworkTopology {
*/
public void add(Node node) {
if (node==null) return;
+ String oldTopoStr = this.toString();
if( node instanceof InnerNode ) {
throw new IllegalArgumentException(
"Not allow to add an inner node: "+NodeBase.getPath(node));
@@ -329,6 +339,19 @@ public class NetworkTopology {
if (rack == null) {
numOfRacks++;
}
+ if (!(node instanceof InnerNode)) {
+ if (depthOfAllLeaves == -1) {
+ depthOfAllLeaves = node.getLevel();
+ } else {
+ if (depthOfAllLeaves != node.getLevel()) {
+ LOG.error("Error: can't add leaf node at depth " +
+ node.getLevel() + " to topology:\n" + oldTopoStr);
+ throw new InvalidTopologyException("Invalid network topology. " +
+ "You cannot have a rack and a non-rack node at the same " +
+ "level of the network topology.");
+ }
+ }
+ }
}
LOG.debug("NetworkTopology became:\n" + this.toString());
} finally {