You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by am...@apache.org on 2016/03/05 15:03:25 UTC

hive git commit: HIVE-13188 : Add close transport to RetryingThriftClient (Rajat Khandelwal, reviwed by Amareshwari Sriramadasu)

Repository: hive
Updated Branches:
  refs/heads/master cc6d29ff3 -> 6f828383d


HIVE-13188 : Add close transport to RetryingThriftClient (Rajat Khandelwal, reviwed by Amareshwari Sriramadasu)


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

Branch: refs/heads/master
Commit: 6f828383d840156c70eb93e6b8c8089bf72e3774
Parents: cc6d29f
Author: Rajat Khandelwal <pr...@apache.org>
Authored: Sat Mar 5 19:32:55 2016 +0530
Committer: Amareshwari Sriramadasu <am...@apache.org>
Committed: Sat Mar 5 19:32:55 2016 +0530

----------------------------------------------------------------------
 .../thrift/RetryingThriftCLIServiceClient.java  | 26 ++++++++++++--------
 .../cli/TestRetryingThriftCLIServiceClient.java | 15 +++++------
 2 files changed, 24 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/6f828383/service/src/java/org/apache/hive/service/cli/thrift/RetryingThriftCLIServiceClient.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/thrift/RetryingThriftCLIServiceClient.java b/service/src/java/org/apache/hive/service/cli/thrift/RetryingThriftCLIServiceClient.java
index a81c600..14191e5 100644
--- a/service/src/java/org/apache/hive/service/cli/thrift/RetryingThriftCLIServiceClient.java
+++ b/service/src/java/org/apache/hive/service/cli/thrift/RetryingThriftCLIServiceClient.java
@@ -71,9 +71,11 @@ public class RetryingThriftCLIServiceClient implements InvocationHandler {
 
   public static class CLIServiceClientWrapper extends CLIServiceClient {
     private final ICLIService cliService;
+    private TTransport tTransport;
 
-    public CLIServiceClientWrapper(ICLIService icliService) {
+    public CLIServiceClientWrapper(ICLIService icliService, TTransport tTransport) {
       cliService = icliService;
+      this.tTransport = tTransport;
     }
 
     @Override
@@ -201,6 +203,10 @@ public class RetryingThriftCLIServiceClient implements InvocationHandler {
                                FetchType fetchType) throws HiveSQLException {
       return cliService.fetchResults(opHandle, orientation, maxRows, fetchType);
     }
+
+    public void closeTransport() {
+      tTransport.close();
+    }
   }
 
   protected RetryingThriftCLIServiceClient(HiveConf conf) {
@@ -210,24 +216,23 @@ public class RetryingThriftCLIServiceClient implements InvocationHandler {
       TimeUnit.SECONDS);
   }
 
-  public static CLIServiceClient newRetryingCLIServiceClient(HiveConf conf) throws HiveSQLException {
+  public static CLIServiceClientWrapper newRetryingCLIServiceClient(HiveConf conf) throws HiveSQLException {
     RetryingThriftCLIServiceClient retryClient = new RetryingThriftCLIServiceClient(conf);
-    retryClient.connectWithRetry(conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_CONNECTION_RETRY_LIMIT));
+    TTransport tTransport = retryClient
+      .connectWithRetry(conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_CONNECTION_RETRY_LIMIT));
     ICLIService cliService =
       (ICLIService) Proxy.newProxyInstance(RetryingThriftCLIServiceClient.class.getClassLoader(),
         CLIServiceClient.class.getInterfaces(), retryClient);
-    return new CLIServiceClientWrapper(cliService);
+    return new CLIServiceClientWrapper(cliService, tTransport);
   }
 
-  protected void connectWithRetry(int retries) throws HiveSQLException {
+  protected TTransport connectWithRetry(int retries) throws HiveSQLException {
+    TTransportException exception = null;
     for (int i = 0 ; i < retries; i++) {
       try {
-        connect(conf);
-        break;
+        return connect(conf);
       } catch (TTransportException e) {
-        if (i + 1 == retries) {
-          throw new HiveSQLException("Unable to connect after " + retries + " retries", e);
-        }
+        exception = e;
         LOG.warn("Connection attempt " + i, e);
       }
       try {
@@ -236,6 +241,7 @@ public class RetryingThriftCLIServiceClient implements InvocationHandler {
         LOG.warn("Interrupted", e);
       }
     }
+    throw new HiveSQLException("Unable to connect after " + retries + " retries", exception);
   }
 
   protected synchronized TTransport connect(HiveConf conf) throws HiveSQLException, TTransportException {

http://git-wip-us.apache.org/repos/asf/hive/blob/6f828383/service/src/test/org/apache/hive/service/cli/TestRetryingThriftCLIServiceClient.java
----------------------------------------------------------------------
diff --git a/service/src/test/org/apache/hive/service/cli/TestRetryingThriftCLIServiceClient.java b/service/src/test/org/apache/hive/service/cli/TestRetryingThriftCLIServiceClient.java
index 3798053..3bd82e6 100644
--- a/service/src/test/org/apache/hive/service/cli/TestRetryingThriftCLIServiceClient.java
+++ b/service/src/test/org/apache/hive/service/cli/TestRetryingThriftCLIServiceClient.java
@@ -51,14 +51,14 @@ public class TestRetryingThriftCLIServiceClient {
       super(conf);
     }
 
-    public static CLIServiceClient newRetryingCLIServiceClient(HiveConf conf) throws HiveSQLException {
+    public static CLIServiceClientWrapper newRetryingCLIServiceClient(HiveConf conf) throws HiveSQLException {
       handlerInst = new RetryingThriftCLIServiceClientTest(conf);
-      handlerInst.connectWithRetry(conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_RETRY_LIMIT));
-
+      TTransport tTransport
+        = handlerInst.connectWithRetry(conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_RETRY_LIMIT));
       ICLIService cliService =
         (ICLIService) Proxy.newProxyInstance(RetryingThriftCLIServiceClientTest.class.getClassLoader(),
           CLIServiceClient.class.getInterfaces(), handlerInst);
-      return new CLIServiceClientWrapper(cliService);
+      return new CLIServiceClientWrapper(cliService, tTransport);
     }
 
     @Override
@@ -108,8 +108,8 @@ public class TestRetryingThriftCLIServiceClient {
     // Reset port setting
     hiveConf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT, 15000);
     // Create client
-    CLIServiceClient cliServiceClient =
-      RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
+    RetryingThriftCLIServiceClient.CLIServiceClientWrapper cliServiceClient
+      = RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
     System.out.println("## Created client");
 
     // kill server
@@ -127,7 +127,8 @@ public class TestRetryingThriftCLIServiceClient {
       assertTrue(exc.getCause() instanceof TException);
       assertEquals(1, RetryingThriftCLIServiceClientTest.handlerInst.callCount);
       assertEquals(3, RetryingThriftCLIServiceClientTest.handlerInst.connectCount);
+    } finally {
+      cliServiceClient.closeTransport();
     }
-
   }
 }