diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/InnerNode.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/InnerNode.java index 65eaf2481e..efd1cc07d4 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/InnerNode.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/InnerNode.java @@ -47,6 +47,9 @@ interface Factory { /** @return its children */ List getChildren(); + /** @return the number of children this node has. */ + int getNumOfChildren(); + /** @return the number of leave nodes. */ int getNumOfLeaves(); diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/InnerNodeImpl.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/InnerNodeImpl.java index a0a977334f..923515b6ef 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/InnerNodeImpl.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/InnerNodeImpl.java @@ -59,7 +59,8 @@ public List getChildren() { } /** @return the number of children this node has. */ - int getNumOfChildren() { + @Override + public int getNumOfChildren() { return children.size(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/net/DFSTopologyNodeImpl.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/net/DFSTopologyNodeImpl.java index 002f4fcee0..7a9afabc1e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/net/DFSTopologyNodeImpl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/net/DFSTopologyNodeImpl.java @@ -109,10 +109,6 @@ public int getSubtreeStorageCount(StorageType type) { } } - int getNumOfChildren() { - return children.size(); - } - private void incStorageTypeCount(StorageType type) { // no locking because the caller is synchronized already if (storageTypeCounts.containsKey(type)) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/net/TestNetworkTopology.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/net/TestNetworkTopology.java index 114b9a6895..9466a75243 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/net/TestNetworkTopology.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/net/TestNetworkTopology.java @@ -351,6 +351,10 @@ public void testSortByDistance() throws Exception { @Test public void testRemove() throws Exception { + // this cluster topology is: + // /d1/r1, /d1/r2, /d2/r3, /d3/r1, /d3/r2, /d4/r1 + // so root "" has four children + assertEquals(4, cluster.clusterMap.getNumOfChildren()); for(int i=0; i