hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Haohui Mai (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HADOOP-11387) Simplify NetUtils#canonicalizeHost()
Date Wed, 10 Dec 2014 07:25:12 GMT
Haohui Mai created HADOOP-11387:

             Summary: Simplify NetUtils#canonicalizeHost()
                 Key: HADOOP-11387
                 URL: https://issues.apache.org/jira/browse/HADOOP-11387
             Project: Hadoop Common
          Issue Type: Bug
            Reporter: Haohui Mai
            Assignee: Haohui Mai

Currently {{NetUtils#canonicalizeHost}} uses a {{ConcurrentHashMap}} to cache the canonicalized

  private static String canonicalizeHost(String host) {
    // check if the host has already been canonicalized
    String fqHost = canonicalizedHostCache.get(host);
    if (fqHost == null) {
      try {
        fqHost = SecurityUtil.getByName(host).getHostName();
        // slight race condition, but won't hurt
        canonicalizedHostCache.put(host, fqHost);
      } catch (UnknownHostException e) {
        fqHost = host;
    return fqHost;

The code can be simplified using {{CacheMap}}.

This message was sent by Atlassian JIRA

View raw message