[
https://issues.apache.org/jira/browse/HADOOP-11387?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14247421#comment-14247421
]
Haohui Mai commented on HADOOP-11387:
-------------------------------------
{code}
- String fqHost = canonicalizeHost(host);
+ String fqHost;
+ try {
+ fqHost = canonicalizedHostCache.get(host);
+ } catch (ExecutionException e) {
+ throw new RuntimeException(e);
+ }
{code}
{code}
+ private static final LoadingCache<String, String> canonicalizedHostCache =
+ CacheBuilder.newBuilder().maximumSize(CANONICAL_CACHE_SIZE).build(
+ new CacheLoader<String, String>() {
+ @Override public String load(String host) throws Exception {
+ return SecurityUtil.getByName(host).getHostName();
+ }
+ }
+ );
{code}
I think it diverges from that original behavior. It might make sense to catch
the {{UnknownHostException}} when populating the cache.
> 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: Li Lu
> Attachments: HADOOP-11387-121514.patch
>
>
> Currently {{NetUtils#canonicalizeHost}} uses a {{ConcurrentHashMap}} to cache
> the canonicalized hostname.
> {code}
> 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;
> }
> {code}
> The code can be simplified using {{CacheMap}}.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)