ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yus...@apache.org
Subject ambari git commit: AMBARI-14109. Invalid session handle error in hive view when hive server is restarted in http mode. (Gaurav Nagar via yusaku)
Date Wed, 02 Dec 2015 20:01:27 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 6fbda3f4d -> b37ce4121


AMBARI-14109. Invalid session handle error in hive view when hive server is restarted in http
mode. (Gaurav Nagar via yusaku)


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

Branch: refs/heads/branch-2.1
Commit: b37ce4121fe9595de21f811755a2c892d9e3c278
Parents: 6fbda3f
Author: Yusaku Sako <yusaku@hortonworks.com>
Authored: Wed Dec 2 12:00:12 2015 -0800
Committer: Yusaku Sako <yusaku@hortonworks.com>
Committed: Wed Dec 2 12:01:13 2015 -0800

----------------------------------------------------------------------
 .../ambari/view/hive/client/Connection.java     |  7 +++-
 .../ambari/view/hive/client/DDLDelegator.java   |  2 +-
 .../ambari/view/hive/client/HiveCall.java       | 42 ++++++++++++++++++++
 3 files changed, 49 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b37ce412/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java
b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java
index 451f2aa..b64a2a5 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java
@@ -530,6 +530,11 @@ public class Connection {
     sessHandles.remove(tag);
   }
 
+  public void invalidateSessionBySessionHandle(TSessionHandle sessionHandle) throws HiveClientException{
+    sessHandles.values().remove(sessionHandle);
+    closeSession(sessionHandle);
+  }
+
   private synchronized void closeSession(TSessionHandle sessHandle) throws HiveClientException
{
     if (sessHandle == null) return;
     TCloseSessionReq closeReq = new TCloseSessionReq(sessHandle);
@@ -582,7 +587,7 @@ public class Connection {
       final String oneCmd = commands[i];
       final boolean lastCommand = i == commands.length-1;
 
-      TExecuteStatementResp execResp = new HiveCall<TExecuteStatementResp>(this) {
+      TExecuteStatementResp execResp = new HiveCall<TExecuteStatementResp>(this,session)
{
         @Override
         public TExecuteStatementResp body() throws HiveClientException {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b37ce412/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/DDLDelegator.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/DDLDelegator.java
b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/DDLDelegator.java
index eda12ed..e609978 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/DDLDelegator.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/DDLDelegator.java
@@ -118,7 +118,7 @@ public class DDLDelegator {
     else
       like = ".*" + like + ".*";
     final String finalLike = like;
-    TGetColumnsResp resp = new HiveCall<TGetColumnsResp>(connection) {
+    TGetColumnsResp resp = new HiveCall<TGetColumnsResp>(connection,session) {
       @Override
       public TGetColumnsResp body() throws HiveClientException {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b37ce412/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/HiveCall.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/HiveCall.java
b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/HiveCall.java
index 1b565eb..d2a459f 100644
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/HiveCall.java
+++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/HiveCall.java
@@ -19,22 +19,61 @@
 package org.apache.ambari.view.hive.client;
 
 import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.hive.service.cli.thrift.TSessionHandle;
+import org.apache.hive.service.cli.thrift.TStatus;
+import org.apache.hive.service.cli.thrift.TStatusCode;
 import org.apache.thrift.transport.TTransportException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
 public abstract class HiveCall <T> {
   private final static Logger LOG =
       LoggerFactory.getLogger(HiveCall.class);
 
   protected final Connection conn;
+  protected final TSessionHandle sessionHandle;
 
   public HiveCall(Connection connection) {
+    this(connection,null);
+  }
+
+  public HiveCall(Connection connection, TSessionHandle sessionHandle) {
     this.conn = connection;
+    this.sessionHandle = sessionHandle;
   }
 
   public abstract T body() throws HiveClientException;
 
+  public boolean validateSession(T t) throws HiveClientException {
+    //invalidate a session
+    try {
+      Method m = t.getClass().getMethod("getStatus");
+      if (m != null) {
+        TStatus status = (TStatus) m.invoke(t);
+        if (status.getStatusCode().equals(TStatusCode.ERROR_STATUS) &&
+          status.getErrorMessage().startsWith("Invalid SessionHandle: SessionHandle")) {
+          try {
+            conn.invalidateSessionBySessionHandle(sessionHandle);
+          } catch (HiveClientException e) {
+            LOG.error(e.getMessage(),e);
+          }
+          throw new HiveClientException("Please Retry." + status.getErrorMessage(), null);
+          //return false;
+        }
+      }
+    } catch (NoSuchMethodException e) {
+
+    } catch (InvocationTargetException e) {
+
+    } catch (IllegalAccessException e) {
+
+    }
+    return true;
+  }
+
   public T call() throws HiveClientException {
     T result = null;
     boolean needRetry = false;
@@ -60,6 +99,9 @@ public abstract class HiveCall <T> {
 
         synchronized (conn) {
           result = body();
+          if(sessionHandle !=null) {
+            this.validateSession(result);
+          }
         }
 
       } catch (HiveClientException ex) {


Mime
View raw message