diff options
author | Stephen Boesch <javadba> | 2014-08-05 18:18:08 -0700 |
---|---|---|
committer | Reynold Xin <rxin@apache.org> | 2014-08-05 18:18:08 -0700 |
commit | 2643e66008cc04074454bb98613c53ba3300e428 (patch) | |
tree | 225b6a463e3ba0dd65c01b4a9e596632ec2a7237 /core | |
parent | 1aad9114c93c5763030c14a2328f6426d9e5bcb6 (diff) | |
download | spark-2643e66008cc04074454bb98613c53ba3300e428.tar.gz spark-2643e66008cc04074454bb98613c53ba3300e428.tar.bz2 spark-2643e66008cc04074454bb98613c53ba3300e428.zip |
SPARK-2869 - Fix tiny bug in JdbcRdd for closing jdbc connection
I inquired on dev mailing list about the motivation for checking the jdbc statement instead of the connection in the close() logic of JdbcRDD. Ted Yu believes there essentially is none- it is a simple cut and paste issue. So here is the tiny fix to patch it.
Author: Stephen Boesch <javadba>
Author: Stephen Boesch <javadba@gmail.com>
Closes #1792 from javadba/closejdbc and squashes the following commits:
363be4f [Stephen Boesch] SPARK-2869 - Fix tiny bug in JdbcRdd for closing jdbc connection (reformat with braces)
6518d36 [Stephen Boesch] SPARK-2689 Fix tiny bug in JdbcRdd for closing jdbc connection
3fb23ed [Stephen Boesch] SPARK-2689 Fix potential leak of connection/PreparedStatement in case of error in JdbcRDD
095b2c9 [Stephen Boesch] Fix tiny bug (likely copy and paste error) in closing jdbc connection
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/scala/org/apache/spark/rdd/JdbcRDD.scala | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/core/src/main/scala/org/apache/spark/rdd/JdbcRDD.scala b/core/src/main/scala/org/apache/spark/rdd/JdbcRDD.scala index a76a070b5b..8947e66f45 100644 --- a/core/src/main/scala/org/apache/spark/rdd/JdbcRDD.scala +++ b/core/src/main/scala/org/apache/spark/rdd/JdbcRDD.scala @@ -96,17 +96,23 @@ class JdbcRDD[T: ClassTag]( override def close() { try { - if (null != rs && ! rs.isClosed()) rs.close() + if (null != rs && ! rs.isClosed()) { + rs.close() + } } catch { case e: Exception => logWarning("Exception closing resultset", e) } try { - if (null != stmt && ! stmt.isClosed()) stmt.close() + if (null != stmt && ! stmt.isClosed()) { + stmt.close() + } } catch { case e: Exception => logWarning("Exception closing statement", e) } try { - if (null != conn && ! stmt.isClosed()) conn.close() + if (null != conn && ! conn.isClosed()) { + conn.close() + } logInfo("closed connection") } catch { case e: Exception => logWarning("Exception closing connection", e) @@ -120,3 +126,4 @@ object JdbcRDD { Array.tabulate[Object](rs.getMetaData.getColumnCount)(i => rs.getObject(i + 1)) } } + |