From 8f5c630a588c8b28ba24d35cdb11b65cc4c2d65b Mon Sep 17 00:00:00 2001 From: Konstantin Boudnik Date: Fri, 22 Feb 2013 23:53:56 +0000 Subject: [PATCH] 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 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 4 ++++ .../blockmanagement/DatanodeManager.java | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index e4f5d5b7df0..19e6db41237 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/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 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 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java index dad756dc2d9..8a63922b117 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java +++ b/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 String hostname = dnAddress.getHostName(); 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); throw new DisallowedDatanodeException(nodeReg); } @@ -1040,6 +1042,22 @@ public class DatanodeManager { } 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) { node.setLastUpdate(0);