HADOOP-8159. NetworkTopology: getLeaf should check for invalid topologies. Contributed by Colin Patrick McCabe
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1304118 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0259a3ea6b
commit
b5a8ccb75b
@ -264,6 +264,9 @@ Release 0.23.3 - UNRELEASED
|
|||||||
|
|
||||||
HADOOP-8197. Configuration logs WARNs on every use of a deprecated key (tucu)
|
HADOOP-8197. Configuration logs WARNs on every use of a deprecated key (tucu)
|
||||||
|
|
||||||
|
HADOOP-8159. NetworkTopology: getLeaf should check for invalid topologies.
|
||||||
|
(Colin Patrick McCabe via eli)
|
||||||
|
|
||||||
BREAKDOWN OF HADOOP-7454 SUBTASKS
|
BREAKDOWN OF HADOOP-7454 SUBTASKS
|
||||||
|
|
||||||
HADOOP-7455. HA: Introduce HA Service Protocol Interface. (suresh)
|
HADOOP-7455. HA: Introduce HA Service Protocol Interface. (suresh)
|
||||||
|
@ -45,6 +45,13 @@ public class NetworkTopology {
|
|||||||
public static final Log LOG =
|
public static final Log LOG =
|
||||||
LogFactory.getLog(NetworkTopology.class);
|
LogFactory.getLog(NetworkTopology.class);
|
||||||
|
|
||||||
|
public static class InvalidTopologyException extends RuntimeException {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
public InvalidTopologyException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** InnerNode represents a switch/router of a data center or rack.
|
/** InnerNode represents a switch/router of a data center or rack.
|
||||||
* Different from a leaf node, it has non-null children.
|
* Different from a leaf node, it has non-null children.
|
||||||
*/
|
*/
|
||||||
@ -311,6 +318,8 @@ int getNumOfLeaves() {
|
|||||||
* the root cluster map
|
* the root cluster map
|
||||||
*/
|
*/
|
||||||
InnerNode clusterMap = new InnerNode(InnerNode.ROOT);
|
InnerNode clusterMap = new InnerNode(InnerNode.ROOT);
|
||||||
|
/** Depth of all leaf nodes */
|
||||||
|
private int depthOfAllLeaves = -1;
|
||||||
/** rack counter */
|
/** rack counter */
|
||||||
private int numOfRacks = 0;
|
private int numOfRacks = 0;
|
||||||
/** the lock used to manage access */
|
/** the lock used to manage access */
|
||||||
@ -328,6 +337,7 @@ public NetworkTopology() {
|
|||||||
*/
|
*/
|
||||||
public void add(Node node) {
|
public void add(Node node) {
|
||||||
if (node==null) return;
|
if (node==null) return;
|
||||||
|
String oldTopoStr = this.toString();
|
||||||
if( node instanceof InnerNode ) {
|
if( node instanceof InnerNode ) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Not allow to add an inner node: "+NodeBase.getPath(node));
|
"Not allow to add an inner node: "+NodeBase.getPath(node));
|
||||||
@ -345,6 +355,19 @@ public void add(Node node) {
|
|||||||
if (rack == null) {
|
if (rack == null) {
|
||||||
numOfRacks++;
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(LOG.isDebugEnabled()) {
|
if(LOG.isDebugEnabled()) {
|
||||||
LOG.debug("NetworkTopology became:\n" + this.toString());
|
LOG.debug("NetworkTopology became:\n" + this.toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user