You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mi...@apache.org on 2017/09/13 10:07:21 UTC
zeppelin git commit: fixed jdbc connection issue.
Repository: zeppelin
Updated Branches:
refs/heads/branch-0.7 c4f208e92 -> 361844c5c
fixed jdbc connection issue.
### 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 <yo...@gmail.com>
Closes #2582 from astroshim/feat/fixJdbcIssue and squashes the following commits:
9807172a [Shim] fixed close pool issue.
5d534e67 [Shim] a1
2335adf5 [Shim] initialize the variable
9b99d21e [Shim] fixed jdbc connection issue.
Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/361844c5
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/361844c5
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/361844c5
Branch: refs/heads/branch-0.7
Commit: 361844c5c12de752e477e9b43e87583a9d97be79
Parents: c4f208e
Author: Shim <yo...@gmail.com>
Authored: Wed Sep 13 15:26:44 2017 +0900
Committer: Mina Lee <mi...@apache.org>
Committed: Wed Sep 13 19:07:11 2017 +0900
----------------------------------------------------------------------
.../apache/zeppelin/jdbc/JDBCInterpreter.java | 53 +++++++++++++-------
.../zeppelin/jdbc/JDBCUserConfigurations.java | 6 ---
2 files changed, 35 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/361844c5/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 ad456be..c94b959 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
@@ -230,11 +230,17 @@ public class JDBCInterpreter extends Interpreter {
}
private void initConnectionPoolMap() {
- for (JDBCUserConfigurations configurations : jdbcUserConfigurationsMap.values()) {
+ for (String key : jdbcUserConfigurationsMap.keySet()) {
+ try {
+ closeDBPool(key, DEFAULT_KEY);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
try {
+ JDBCUserConfigurations configurations = jdbcUserConfigurationsMap.get(key);
configurations.initConnectionPoolMap();
- } catch (Exception e) {
- logger.error("Error while closing initConnectionPoolMap...", e);
+ } catch (SQLException e) {
+ e.printStackTrace();
}
}
}
@@ -357,7 +363,7 @@ public class JDBCInterpreter extends Interpreter {
public Connection getConnection(String propertyKey, InterpreterContext interpreterContext)
throws ClassNotFoundException, SQLException, InterpreterException, IOException {
final String user = interpreterContext.getAuthenticationInfo().getUser();
- Connection connection;
+ Connection connection = null;
if (propertyKey == null || basePropretiesMap.get(propertyKey) == null) {
return null;
}
@@ -553,20 +559,30 @@ public class JDBCInterpreter extends Interpreter {
private InterpreterResult executeSql(String propertyKey, String sql,
InterpreterContext interpreterContext) {
- Connection connection;
+ Connection connection = null;
Statement statement;
ResultSet resultSet = null;
String paragraphId = interpreterContext.getParagraphId();
String user = interpreterContext.getAuthenticationInfo().getUser();
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 {
ArrayList<String> multipleSqlArray = splitSqlQueries(sql);
for (int i = 0; i < multipleSqlArray.size(); i++) {
String sqlToExecute = multipleSqlArray.get(i);
@@ -612,16 +628,6 @@ public class JDBCInterpreter extends Interpreter {
}
}
}
- //In case user ran an insert/update/upsert statement
- if (connection != null) {
- try {
- if (!connection.getAutoCommit()) {
- connection.commit();
- }
- connection.close();
- } catch (SQLException e) { /*ignored*/ }
- }
- getJDBCConfiguration(user).removeStatement(paragraphId);
} catch (Throwable e) {
if (e.getCause() instanceof TTransportException &&
Throwables.getStackTraceAsString(e).contains("GSS") &&
@@ -638,6 +644,17 @@ public class JDBCInterpreter extends Interpreter {
interpreterResult.add(errorMsg);
return new InterpreterResult(Code.ERROR, interpreterResult.message());
}
+ } finally {
+ //In case user ran an insert/update/upsert statement
+ if (connection != null) {
+ try {
+ if (!connection.getAutoCommit()) {
+ connection.commit();
+ }
+ connection.close();
+ } catch (SQLException e) { /*ignored*/ }
+ }
+ getJDBCConfiguration(user).removeStatement(paragraphId);
}
return interpreterResult;
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/361844c5/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCUserConfigurations.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCUserConfigurations.java b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCUserConfigurations.java
index d00e1e9..0579380 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCUserConfigurations.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCUserConfigurations.java
@@ -48,12 +48,6 @@ public class JDBCUserConfigurations {
}
public void initConnectionPoolMap() throws SQLException {
- Iterator<String> it = poolingDriverMap.keySet().iterator();
- while (it.hasNext()) {
- String driverName = it.next();
- poolingDriverMap.get(driverName).closePool(driverName);
- it.remove();
- }
poolingDriverMap.clear();
isSuccessful.clear();
}