You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2018/08/20 07:00:16 UTC

zeppelin git commit: [ZEPPELIN-3712] Add `maxConnLifetime` parameter to JDBC Interpreter

Repository: zeppelin
Updated Branches:
  refs/heads/master 6854bdd7d -> 6fac6cd15


[ZEPPELIN-3712] Add `maxConnLifetime` parameter to JDBC Interpreter

### What is this PR for?
This parameter is necessary in that case:
1) Zeppelin open connection and keep it in pool;
2) Database close this connection after some time of inactivity;
3) User get an error and necessity to restart interpreter when he runs a paragraph.

The default value of this parameter is `-1` which means the connection has an infinite lifetime.

### What type of PR is it?
Improvement

### What is the Jira issue?
[ZEPPELIN-3712](https://issues.apache.org/jira/browse/ZEPPELIN-3712)

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

Author: oxygen311 <al...@mail.ru>

Closes #3139 from oxygen311/DW-17882 and squashes the following commits:

cbf6c8681 [oxygen311] Add `zeppelin.jdbc.maxConnLifetime` property description to docs
c86241147 [oxygen311] Add `maxConnLifetime` property


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

Branch: refs/heads/master
Commit: 6fac6cd157a71c68f280efe7fd70793dd1f650c1
Parents: 6854bdd
Author: oxygen311 <al...@mail.ru>
Authored: Wed Aug 15 17:00:55 2018 +0200
Committer: Jeff Zhang <zj...@apache.org>
Committed: Mon Aug 20 15:00:12 2018 +0800

----------------------------------------------------------------------
 docs/interpreter/jdbc.md                                      | 4 ++++
 .../main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java   | 4 ++++
 jdbc/src/main/resources/interpreter-setting.json              | 7 +++++++
 3 files changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/6fac6cd1/docs/interpreter/jdbc.md
----------------------------------------------------------------------
diff --git a/docs/interpreter/jdbc.md b/docs/interpreter/jdbc.md
index 5a8ffc9..b0f5d6b 100644
--- a/docs/interpreter/jdbc.md
+++ b/docs/interpreter/jdbc.md
@@ -201,6 +201,10 @@ There are more JDBC interpreter properties you can specify like below.
     <td>zeppelin.jdbc.interpolation</td>
     <td>Enables ZeppelinContext variable interpolation into paragraph text. Default value is false.</td>
   </tr>
+  <tr>
+    <td>zeppelin.jdbc.maxConnLifetime</td>
+    <td>Maximum of connection lifetime in milliseconds. A value of zero or less means the connection has an infinite lifetime.</td>
+  </tr>
 </table>
 
 You can also add more properties by using this [method](http://docs.oracle.com/javase/7/docs/api/java/sql/DriverManager.html#getConnection%28java.lang.String,%20java.util.Properties%29).

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/6fac6cd1/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 c0c48aa..93d2344 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
@@ -389,6 +389,10 @@ public class JDBCInterpreter extends KerberosInterpreter {
 
     PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
             connectionFactory, null);
+    final String maxConnectionLifetime =
+        StringUtils.defaultIfEmpty(getProperty("zeppelin.jdbc.maxConnLifetime"), "-1");
+    poolableConnectionFactory.setMaxConnLifetimeMillis(Long.parseLong(maxConnectionLifetime));
+
     ObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
 
     poolableConnectionFactory.setPool(connectionPool);

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/6fac6cd1/jdbc/src/main/resources/interpreter-setting.json
----------------------------------------------------------------------
diff --git a/jdbc/src/main/resources/interpreter-setting.json b/jdbc/src/main/resources/interpreter-setting.json
index 3f3e672..a1853ef 100644
--- a/jdbc/src/main/resources/interpreter-setting.json
+++ b/jdbc/src/main/resources/interpreter-setting.json
@@ -115,6 +115,13 @@
         "defaultValue": false,
         "description": "Enable ZeppelinContext variable interpolation into paragraph text",
         "type": "checkbox"
+      },
+      "zeppelin.jdbc.maxConnLifetime": {
+        "envName": null,
+        "propertyName": "zeppelin.jdbc.maxConnLifetime",
+        "defaultValue": "-1",
+        "description": "Maximum of connection lifetime in milliseconds. A value of zero or less means the connection has an infinite lifetime.",
+        "type": "number"
       }
     },
     "editor": {