You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2019/03/28 14:00:54 UTC

[kylin] branch master updated: KYLIN-3908 KylinClient's HttpRequest.releaseConnection is not needed in retrieveMetaData & executeKylinQuery (#551)

This is an automated email from the ASF dual-hosted git repository.

shaofengshi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ab6c2f  KYLIN-3908 KylinClient's HttpRequest.releaseConnection is not needed in retrieveMetaData & executeKylinQuery (#551)
9ab6c2f is described below

commit 9ab6c2f12bbddd5b402a373f37afca3c8ec9aafe
Author: leonliao <xi...@gmail.com>
AuthorDate: Thu Mar 28 22:00:48 2019 +0800

    KYLIN-3908 KylinClient's HttpRequest.releaseConnection is not needed in retrieveMetaData & executeKylinQuery (#551)
    
    KYLIN-3908 httpRequest.releaseConnection enclosed with a finally block
---
 .../java/org/apache/kylin/jdbc/KylinClient.java    | 39 ++++++++++++----------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/jdbc/src/main/java/org/apache/kylin/jdbc/KylinClient.java b/jdbc/src/main/java/org/apache/kylin/jdbc/KylinClient.java
index daf01bd..f59c374 100644
--- a/jdbc/src/main/java/org/apache/kylin/jdbc/KylinClient.java
+++ b/jdbc/src/main/java/org/apache/kylin/jdbc/KylinClient.java
@@ -298,20 +298,21 @@ public class KylinClient implements IRemoteClient {
         addHttpHeaders(get);
 
         HttpResponse response = httpClient.execute(get);
+        try {
+            if (response.getStatusLine().getStatusCode() != 200 && response.getStatusLine().getStatusCode() != 201) {
+                throw asIOException(get, response);
+            }
 
-        if (response.getStatusLine().getStatusCode() != 200 && response.getStatusLine().getStatusCode() != 201) {
-            throw asIOException(get, response);
+            List<TableMetaStub> tableMetaStubs = jsonMapper.readValue(response.getEntity().getContent(),
+                    new TypeReference<List<TableMetaStub>>() {
+                    });
+            List<KMetaTable> tables = convertMetaTables(tableMetaStubs);
+            List<KMetaSchema> schemas = convertMetaSchemas(tables);
+            List<KMetaCatalog> catalogs = convertMetaCatalogs(schemas);
+            return new KMetaProject(project, catalogs);
+        } finally {
+           get.releaseConnection(); 
         }
-
-        List<TableMetaStub> tableMetaStubs = jsonMapper.readValue(response.getEntity().getContent(),
-                new TypeReference<List<TableMetaStub>>() {
-                });
-
-        List<KMetaTable> tables = convertMetaTables(tableMetaStubs);
-        List<KMetaSchema> schemas = convertMetaSchemas(tables);
-        List<KMetaCatalog> catalogs = convertMetaCatalogs(schemas);
-        get.releaseConnection();
-        return new KMetaProject(project, catalogs);
     }
 
     private List<KMetaCatalog> convertMetaCatalogs(List<KMetaSchema> schemas) {
@@ -426,14 +427,16 @@ public class KylinClient implements IRemoteClient {
         post.setEntity(requestEntity);
 
         HttpResponse response = httpClient.execute(post);
+        try {
+            if (response.getStatusLine().getStatusCode() != 200 && response.getStatusLine().getStatusCode() != 201) {
+                throw asIOException(post, response);
+            }
 
-        if (response.getStatusLine().getStatusCode() != 200 && response.getStatusLine().getStatusCode() != 201) {
-            throw asIOException(post, response);
+            SQLResponseStub stub = jsonMapper.readValue(response.getEntity().getContent(), SQLResponseStub.class);
+            return stub;
+        } finally {
+            post.releaseConnection();
         }
-
-        SQLResponseStub stub = jsonMapper.readValue(response.getEntity().getContent(), SQLResponseStub.class);
-        post.releaseConnection();
-        return stub;
     }
 
     private List<ColumnMetaData> convertColumnMeta(SQLResponseStub queryResp) {