Repository: hive
Updated Branches:
  refs/heads/master 930b66b25 -> 109a3a3c1


HIVE-13209 : metastore get_delegation_token fails with null ip address (Thejas 
Nair, reviewed by Sushanth Sowmyan)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/109a3a3c
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/109a3a3c
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/109a3a3c

Branch: refs/heads/master
Commit: 109a3a3c1760c9bbb0085804a1e0ebaea9f1b567
Parents: 930b66b
Author: Thejas Nair <the...@hortonworks.com>
Authored: Mon Mar 7 08:49:51 2016 -0800
Committer: Thejas Nair <the...@hortonworks.com>
Committed: Mon Mar 7 08:49:51 2016 -0800

----------------------------------------------------------------------
 .../hadoop/hive/metastore/HiveMetaStore.java    | 34 ++++++++++++--------
 .../hive/metastore/TSetIpAddressProcessor.java  |  2 +-
 .../hive/metastore/IpAddressListener.java       |  2 +-
 3 files changed, 22 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/109a3a3c/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java 
b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
index 984e3fc..50b38fa 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
@@ -284,14 +284,7 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       final Formatter fmt = auditFormatter.get();
       ((StringBuilder) fmt.out()).setLength(0);
 
-      String address = null;
-      if (useSasl) {
-        if (saslServer != null && saslServer.getRemoteAddress() != null) {
-          address = String.valueOf(saslServer.getRemoteAddress());
-        }
-      } else {
-        address = getIpAddress();
-      }
+      String address = getIPAddress();
       if (address == null) {
         address = "unknown-ip-addr";
       }
@@ -300,6 +293,18 @@ public class HiveMetaStore extends ThriftHiveMetastore {
           address, cmd).toString());
     }
 
+    String getIPAddress() {
+      if (useSasl) {
+        if (saslServer != null && saslServer.getRemoteAddress() != null) {
+          return saslServer.getRemoteAddress().getHostAddress();
+        }
+      } else {
+        // if kerberos is not enabled
+        return getThreadLocalIpAddress();
+      }
+      return null;
+    }
+
     private static int nextSerialNum = 0;
     private static ThreadLocal<Integer> threadLocalId = new 
ThreadLocal<Integer>() {
       @Override
@@ -310,7 +315,7 @@ public class HiveMetaStore extends ThriftHiveMetastore {
 
     // This will only be set if the metastore is being accessed from a 
metastore Thrift server,
     // not if it is from the CLI. Also, only if the TTransport being used to 
connect is an
-    // instance of TSocket.
+    // instance of TSocket. This is also not set when kerberos is used.
     private static ThreadLocal<String> threadLocalIpAddress = new 
ThreadLocal<String>() {
       @Override
       protected String initialValue() {
@@ -318,13 +323,14 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       }
     };
 
-    public static void setIpAddress(String ipAddress) {
+    public static void setThreadLocalIpAddress(String ipAddress) {
       threadLocalIpAddress.set(ipAddress);
     }
 
     // This will return null if the metastore is not being accessed from a 
metastore Thrift server,
-    // or if the TTransport being used to connect is not an instance of 
TSocket.
-    public static String getIpAddress() {
+    // or if the TTransport being used to connect is not an instance of 
TSocket, or if kereberos
+    // is used
+    public static String getThreadLocalIpAddress() {
       return threadLocalIpAddress.get();
     }
 
@@ -727,7 +733,7 @@ public class HiveMetaStore extends ThriftHiveMetastore {
 
     private String startFunction(String function, String extraLogInfo) {
       incrementCounter(function);
-      logInfo((getIpAddress() == null ? "" : "source:" + getIpAddress() + " ") 
+
+      logInfo((getThreadLocalIpAddress() == null ? "" : "source:" + 
getThreadLocalIpAddress() + " ") +
           function + extraLogInfo);
       if (MetricsFactory.getInstance() != null) {
         try {
@@ -5242,7 +5248,7 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       try {
         ret =
             HiveMetaStore.getDelegationToken(token_owner,
-                renewer_kerberos_principal_name, getIpAddress());
+                renewer_kerberos_principal_name, getIPAddress());
       } catch (IOException e) {
         ex = e;
         throw new MetaException(e.getMessage());

http://git-wip-us.apache.org/repos/asf/hive/blob/109a3a3c/metastore/src/java/org/apache/hadoop/hive/metastore/TSetIpAddressProcessor.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/java/org/apache/hadoop/hive/metastore/TSetIpAddressProcessor.java
 
b/metastore/src/java/org/apache/hadoop/hive/metastore/TSetIpAddressProcessor.java
index 4a56bfa..38b0875 100644
--- 
a/metastore/src/java/org/apache/hadoop/hive/metastore/TSetIpAddressProcessor.java
+++ 
b/metastore/src/java/org/apache/hadoop/hive/metastore/TSetIpAddressProcessor.java
@@ -57,6 +57,6 @@ public class TSetIpAddressProcessor<I extends Iface> extends 
ThriftHiveMetastore
   }
 
   protected void setIpAddress(final Socket inSocket) {
-    HMSHandler.setIpAddress(inSocket.getInetAddress().getHostAddress());
+    
HMSHandler.setThreadLocalIpAddress(inSocket.getInetAddress().getHostAddress());
   }
 }

http://git-wip-us.apache.org/repos/asf/hive/blob/109a3a3c/metastore/src/test/org/apache/hadoop/hive/metastore/IpAddressListener.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/test/org/apache/hadoop/hive/metastore/IpAddressListener.java 
b/metastore/src/test/org/apache/hadoop/hive/metastore/IpAddressListener.java
index d8ec281..e40edca 100644
--- a/metastore/src/test/org/apache/hadoop/hive/metastore/IpAddressListener.java
+++ b/metastore/src/test/org/apache/hadoop/hive/metastore/IpAddressListener.java
@@ -50,7 +50,7 @@ public class IpAddressListener extends MetaStoreEventListener{
   private void checkIpAddress() {
     try {
       String localhostIp = InetAddress.getByName(LOCAL_HOST).getHostAddress();
-      Assert.assertEquals(localhostIp, HMSHandler.getIpAddress());
+      Assert.assertEquals(localhostIp, HMSHandler.getThreadLocalIpAddress());
     } catch (UnknownHostException e) {
       Assert.assertTrue("InetAddress.getLocalHost threw an exception: " + 
e.getMessage(), false);
     }

Reply via email to