From 53bef9c5b98dee87d4ffaf35415bc38e2f876ed8 Mon Sep 17 00:00:00 2001 From: yliu Date: Thu, 13 Aug 2015 16:45:20 +0800 Subject: [PATCH] HADOOP-12295. Improve NetworkTopology#InnerNode#remove logic. (yliu) --- .../hadoop-common/CHANGES.txt | 2 + .../apache/hadoop/net/NetworkTopology.java | 38 +++++++++---------- .../hadoop/net/TestNetworkTopology.java | 1 + 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 78f12e4876..c80be05a67 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -749,6 +749,8 @@ Release 2.8.0 - UNRELEASED HADOOP-12318. Expose underlying LDAP exceptions in SaslPlainServer. (Mike Yoder via atm) + HADOOP-12295. Improve NetworkTopology#InnerNode#remove logic. (yliu) + OPTIMIZATIONS HADOOP-11785. Reduce the number of listStatus operation in distcp diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java index 970ad404f9..fe6e4399bc 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java @@ -166,10 +166,11 @@ private String getNextAncestorName(Node n) { * @return true if the node is added; false otherwise */ boolean add(Node n) { - if (!isAncestor(n)) - throw new IllegalArgumentException(n.getName()+", which is located at " - +n.getNetworkLocation()+", is not a decendent of " - +getPath(this)); + if (!isAncestor(n)) { + throw new IllegalArgumentException(n.getName() + + ", which is located at " + n.getNetworkLocation() + + ", is not a descendent of " + getPath(this)); + } if (isParent(n)) { // this node is the parent of n; add n directly n.setParent(this); @@ -227,12 +228,11 @@ protected InnerNode createParentNode(String parentName) { * @return true if the node is deleted; false otherwise */ boolean remove(Node n) { - String parent = n.getNetworkLocation(); - String currentPath = getPath(this); - if (!isAncestor(n)) + if (!isAncestor(n)) { throw new IllegalArgumentException(n.getName() - +", which is located at " - +parent+", is not a descendent of "+currentPath); + + ", which is located at " + n.getNetworkLocation() + + ", is not a descendent of " + getPath(this)); + } if (isParent(n)) { // this node is the parent of n; remove n directly if (childrenMap.containsKey(n.getName())) { @@ -250,15 +250,8 @@ boolean remove(Node n) { } else { // find the next ancestor node: the parent node String parentName = getNextAncestorName(n); - InnerNode parentNode = null; - int i; - for(i=0; i