浏览代码

HDFS-4269. DatanodeManager#registerDatanode rejects all datanode registrations
from localhost in single-node developer setup (Contributed by Chris Nauroth)


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1449256 13f79535-47bb-0310-9956-ffa450edef68

Konstantin Boudnik 12 年之前
父节点
当前提交
8f5c630a58

+ 4 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -31,6 +31,10 @@ Release 2.0.4-beta - UNRELEASED
     HDFS-4482. ReplicationMonitor thread can exit with NPE due to the race 
     HDFS-4482. ReplicationMonitor thread can exit with NPE due to the race 
     between delete and replication of same file. (umamahesh)
     between delete and replication of same file. (umamahesh)
 
 
+    HDFS-4269. DatanodeManager#registerDatanode rejects all datanode
+    registrations from localhost in single-node developer setup  (Chris
+    Nauroth)
+
 Release 2.0.3-alpha - 2013-02-06
 Release 2.0.3-alpha - 2013-02-06
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 19 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java

@@ -624,7 +624,9 @@ public class DatanodeManager {
       // Mostly called inside an RPC, update ip and peer hostname
       // Mostly called inside an RPC, update ip and peer hostname
       String hostname = dnAddress.getHostName();
       String hostname = dnAddress.getHostName();
       String ip = dnAddress.getHostAddress();
       String ip = dnAddress.getHostAddress();
-      if (hostname.equals(ip)) {
+      if (!isNameResolved(dnAddress)) {
+        // Reject registration of unresolved datanode to prevent performance
+        // impact of repetitive DNS lookups later.
         LOG.warn("Unresolved datanode registration from " + ip);
         LOG.warn("Unresolved datanode registration from " + ip);
         throw new DisallowedDatanodeException(nodeReg);
         throw new DisallowedDatanodeException(nodeReg);
       }
       }
@@ -1040,6 +1042,22 @@ public class DatanodeManager {
     }
     }
     return names;
     return names;
   }
   }
+
+  /**
+   * Checks if name resolution was successful for the given address.  If IP
+   * address and host name are the same, then it means name resolution has
+   * failed.  As a special case, the loopback address is also considered
+   * acceptable.  This is particularly important on Windows, where 127.0.0.1 does
+   * not resolve to "localhost".
+   * 
+   * @param address InetAddress to check
+   * @return boolean true if name resolution successful or address is loopback
+   */
+  private static boolean isNameResolved(InetAddress address) {
+    String hostname = address.getHostName();
+    String ip = address.getHostAddress();
+    return !hostname.equals(ip) || address.isLoopbackAddress();
+  }
   
   
   private void setDatanodeDead(DatanodeDescriptor node) {
   private void setDatanodeDead(DatanodeDescriptor node) {
     node.setLastUpdate(0);
     node.setLastUpdate(0);