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
This commit is contained in:
Konstantin Boudnik 2013-02-22 23:53:56 +00:00
parent 90e4d62cec
commit 8f5c630a58
2 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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);