InvisibleProgrammer commented on code in PR #6784:
URL: https://github.com/apache/hive/pull/6784#discussion_r4311602148


##########
common/src/java/org/apache/hadoop/hive/common/ServerUtils.java:
##########
@@ -68,15 +70,58 @@ public static InetAddress getHostAddress(String hostname) 
throws UnknownHostExce
     }
     return serverIPAddress;
   }
+
+  /**
+   * Get the IP address string (e.g. "192.168.1.50") for the given host name.
+   * @param hostname The name of the host
+   * @return The network address of the host and UNKNOWN if resolution fails
+   */
+  public static String getHostAddressString(String hostname) {
+    try {
+      return InetAddress.getByName(hostname).getHostAddress();
+    } catch (UnknownHostException e) {
+      LOG.warn("Error trying to get host address for {}: {}", hostname, 
e.getMessage());
+      return "UNKNOWN";
+    }
+  }
+
   /**
    * @return name of current host
    */
   public static String hostname() {
     try {
       return InetAddress.getLocalHost().getHostName();
     } catch (UnknownHostException e) {
-      LOG.error("Unable to resolve my host name " + e.getMessage());
-      throw new RuntimeException(e);
+      LOG.warn("Error fetching hostname! Falling back to localhost.{}", 
e.getMessage());
+      return LOCALHOST;

Review Comment:
   I have second thoughts about changing the behavior this way: Now it is not 
only creating a new utility method to create reusable code but also changing 
the behavior of Hive itself: before that, we threw an Exception if there were 
an issue getting the host name. Now we just give the text, `localhost` instead. 
   
   I would be fine with this change if Hive have a 100% test coverage but I 
have a feeling it is far from that. According to my IDE, it is used in 34 
places. Did you checked all the occurrences and made sure the change of 
behavior won't cause any harm? 
   
   I have the same question around the other two new utility methods. 



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