zeppelin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cloverhea...@apache.org
Subject zeppelin git commit: [hotfix] JDBC connection does not release when got exception.
Date Tue, 12 Sep 2017 05:23:16 GMT
Repository: zeppelin
Updated Branches:
  refs/heads/master 84ac43328 -> 3fb67f9cc


[hotfix] JDBC connection does not release when got exception.

### What is this PR for?
This PR fixes JDBC connection release problem.

for example whenever i run not executable command like following
![image](https://user-images.githubusercontent.com/3348133/30206892-8248d1ae-94c8-11e7-9eae-a495be075892.png)

new JDBC connection is made like following.
```
$ netstat -an |grep EST |grep 3306 |wc -l
       1
$ netstat -an |grep EST |grep 3306 |wc -l
       2
$ netstat -an |grep EST |grep 3306 |wc -l
       3
```

### What type of PR is it?
Bug Fix

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Shim <yoojinfa@gmail.com>

Closes #2576 from astroshim/fix/jdbcConnectionRelease and squashes the following commits:

d32425cc [Shim] changed to Throwable
3ae59e9f [Shim] fixed exception codes
88d3edb9 [Shim] fix jdbc connection relase issue.


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

Branch: refs/heads/master
Commit: 3fb67f9cc5a497ee3b1b566b745bc1af349871e0
Parents: 84ac433
Author: Shim <yoojinfa@gmail.com>
Authored: Mon Sep 11 12:47:15 2017 +0900
Committer: CloverHearts <cloverheartsdev@gmail.com>
Committed: Tue Sep 12 14:23:09 2017 +0900

----------------------------------------------------------------------
 .../apache/zeppelin/jdbc/JDBCInterpreter.java   | 34 ++++++++++++--------
 1 file changed, 20 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3fb67f9c/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
index f3f4326..4bb4f0f 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
@@ -653,7 +653,7 @@ public class JDBCInterpreter extends KerberosInterpreter {
 
   private InterpreterResult executeSql(String propertyKey, String sql,
       InterpreterContext interpreterContext) {
-    Connection connection;
+    Connection connection = null;
     Statement statement;
     ResultSet resultSet = null;
     String paragraphId = interpreterContext.getParagraphId();
@@ -668,11 +668,21 @@ public class JDBCInterpreter extends KerberosInterpreter {
     InterpreterResult interpreterResult = new InterpreterResult(InterpreterResult.Code.SUCCESS);
     try {
       connection = getConnection(propertyKey, interpreterContext);
-      if (connection == null) {
-        return new InterpreterResult(Code.ERROR, "Prefix not found.");
+    } catch (Exception e) {
+      String errorMsg = Throwables.getStackTraceAsString(e);
+      try {
+        closeDBPool(user, propertyKey);
+      } catch (SQLException e1) {
+        logger.error("Cannot close DBPool for user, propertyKey: " + user + propertyKey,
e1);
       }
+      interpreterResult.add(errorMsg);
+      return new InterpreterResult(Code.ERROR, interpreterResult.message());
+    }
+    if (connection == null) {
+      return new InterpreterResult(Code.ERROR, "Prefix not found.");
+    }
 
-
+    try {
       List<String> sqlArray;
       if (splitQuery) {
         sqlArray = splitSqlQueries(sql);
@@ -734,6 +744,12 @@ public class JDBCInterpreter extends KerberosInterpreter {
           }
         }
       }
+    } catch (Throwable e) {
+      logger.error("Cannot run " + sql, e);
+      String errorMsg = Throwables.getStackTraceAsString(e);
+      interpreterResult.add(errorMsg);
+      return new InterpreterResult(Code.ERROR, interpreterResult.message());
+    } finally {
       //In case user ran an insert/update/upsert statement
       if (connection != null) {
         try {
@@ -744,16 +760,6 @@ public class JDBCInterpreter extends KerberosInterpreter {
         } catch (SQLException e) { /*ignored*/ }
       }
       getJDBCConfiguration(user).removeStatement(paragraphId);
-    } catch (Throwable e) {
-      logger.error("Cannot run " + sql, e);
-      String errorMsg = Throwables.getStackTraceAsString(e);
-      try {
-        closeDBPool(user, propertyKey);
-      } catch (SQLException e1) {
-        logger.error("Cannot close DBPool for user, propertyKey: " + user + propertyKey,
e1);
-      }
-      interpreterResult.add(errorMsg);
-      return new InterpreterResult(Code.ERROR, interpreterResult.message());
     }
     return interpreterResult;
   }


Mime
View raw message