HDFS-2653. DFSClient should cache whether addrs are non-local when short-circuiting is enabled. Contributed by Eli Collins

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1213586 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eli Collins 2011-12-13 07:51:23 +00:00
parent f611e1d1b1
commit 197634f2f7
2 changed files with 8 additions and 8 deletions

View File

@ -237,6 +237,9 @@ Release 0.23.1 - UNRELEASED
HDFS-2596. TestDirectoryScanner doesn't test parallel scans. (eli) HDFS-2596. TestDirectoryScanner doesn't test parallel scans. (eli)
HDFS-2653. DFSClient should cache whether addrs are non-local when
short-circuiting is enabled. (eli)
Release 0.23.0 - 2011-11-01 Release 0.23.0 - 2011-11-01
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -33,10 +33,8 @@
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.net.SocketFactory; import javax.net.SocketFactory;
@ -532,12 +530,13 @@ static BlockReader getLocalBlockReader(Configuration conf,
} }
} }
private static Set<String> localIpAddresses = Collections private static Map<String, Boolean> localAddrMap = Collections
.synchronizedSet(new HashSet<String>()); .synchronizedMap(new HashMap<String, Boolean>());
private static boolean isLocalAddress(InetSocketAddress targetAddr) { private static boolean isLocalAddress(InetSocketAddress targetAddr) {
InetAddress addr = targetAddr.getAddress(); InetAddress addr = targetAddr.getAddress();
if (localIpAddresses.contains(addr.getHostAddress())) { Boolean cached = localAddrMap.get(addr.getHostAddress());
if (cached != null && cached) {
if (LOG.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOG.trace("Address " + targetAddr + " is local"); LOG.trace("Address " + targetAddr + " is local");
} }
@ -558,9 +557,7 @@ private static boolean isLocalAddress(InetSocketAddress targetAddr) {
if (LOG.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOG.trace("Address " + targetAddr + " is local"); LOG.trace("Address " + targetAddr + " is local");
} }
if (local == true) { localAddrMap.put(addr.getHostAddress(), local);
localIpAddresses.add(addr.getHostAddress());
}
return local; return local;
} }