smengcl commented on code in PR #9027:
URL: https://github.com/apache/hadoop/pull/9027#discussion_r4717772571


##########
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/CombinedHostFileManager.java:
##########
@@ -192,12 +216,27 @@ private void refresh(final String hostsFile, final int 
readTimeout) throws IOExc
       InetSocketAddress addr = parseEntry(hostsFile,
           properties.getHostName(), properties.getPort());
       if (addr != null) {
-        hostProps.add(addr.getAddress(), properties);
+        hostProps.add(addr.getAddress(), properties,
+            otherAddressesOf(addr.getAddress()));
       }
     }
     refresh(hostProps);
   }
 
+  /**
+   * @return the host's other addresses, e.g. its IPv6 address for an entry
+   *     given as an IPv4 literal.
+   */
+  private static Collection<InetAddress> otherAddressesOf(InetAddress addr) {
+    try {
+      return 
Arrays.stream(InetAddress.getAllByName(addr.getCanonicalHostName()))
+          .filter(a -> !a.equals(addr)).collect(Collectors.toList());

Review Comment:
   Thanks for the review.
   
   On the lock: `DatanodeManager#refreshNodes` re-reads the hosts file in 
`refreshHostsReader` before it takes the namesystem write lock, and 
`CombinedHostFileManager#refresh` builds the new `HostProperties` without 
holding any lock (only the final swap is synchronized). So the lookups do not 
run under the global lock, but they do add to `refreshNodes` latency, and I 
agree we should keep that small.
   
   Updated: for an entry given as a host name, the aliases now come from the 
forward lookup `parseEntry` already did (normally served from the JVM address 
cache), so there is no reverse lookup. Only entries given as IP literals need 
one reverse and one forward lookup, and a failed lookup just leaves that entry 
without aliases.
   
   On loopback: good point. Loopback addresses do not identify a host, so they 
are never added as aliases now, and loopback entries skip the lookups entirely. 
Added `testCombinedHostsLoopbackHasNoAliases`.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to