瀏覽代碼

HADOOP-9451. Fault single-layer config if node group topology is enabled. (Junping Du via llu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1@1464300 13f79535-47bb-0310-9956-ffa450edef68
Luke Lu 12 年之前
父節點
當前提交
e1e7b849ed

+ 3 - 0
CHANGES.txt

@@ -229,6 +229,9 @@ Release 1.2.0 - unreleased
 
   BUG FIXES
 
+    HADOOP-9451. Fault single-layer config if node group topology is enabled.
+    (Junping Du via llu)
+
     MAPREDUCE-4904. OTHER_LOCAL_MAPS counter is not correct.
     (Junping Du via llu)
 

+ 6 - 1
src/core/org/apache/hadoop/net/NetworkTopologyWithNodeGroup.java

@@ -190,7 +190,12 @@ public class NetworkTopologyWithNodeGroup extends NetworkTopology {
       }
       rack = getNode(nodeGroup.getNetworkLocation());
 
-      if (rack != null && !(rack instanceof InnerNode)) {
+      // rack should be an innerNode and with parent.
+      // note: rack's null parent case is: node's topology only has one layer, 
+      //       so rack is recognized as "/" and no parent. 
+      // This will be recognized as a node with fault topology.
+      if (rack != null && 
+          (!(rack instanceof InnerNode)|| rack.getParent() == null)) {
         throw new IllegalArgumentException("Unexpected data node " 
             + node.toString() 
             + " at an illegal network location");

+ 18 - 0
src/test/org/apache/hadoop/net/TestNetworkTopologyWithNodeGroup.java

@@ -39,6 +39,8 @@ public class TestNetworkTopologyWithNodeGroup extends TestCase {
   };
 
   private final static NodeBase computeNode = new NodeBase("/d1/r1/n1/h9");
+  
+  private final static NodeBase rackOnlyNode = new NodeBase("h10", "/r1");
 
   static {
     for(int i=0; i<dataNodes.length; i++) {
@@ -159,5 +161,21 @@ public class TestNetworkTopologyWithNodeGroup extends TestCase {
       assertTrue(frequency.get(key) > 0 || key == dataNodes[0]);
     }
   }
+  /**
+   * This test checks that adding a node with invalid topology will be failed 
+   * with an exception to show topology is invalid.
+   */
+  public void testAddNodeWithInvalidTopology() {
+    // The last node is a node with invalid topology
+    try {
+      cluster.add(rackOnlyNode);
+      fail("Exception should be thrown, so we should not have reached here.");
+    } catch (Exception e) {
+      if (!(e instanceof IllegalArgumentException)) {
+        fail("Expecting IllegalArgumentException, but caught:" + e);
+      }
+      assertTrue(e.getMessage().contains("illegal network location"));
+    }
+  }
 
 }