Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/src/main/scala/org/apache/spark/rdd/JdbcRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class JdbcRDD[T: ClassTag](

override def compute(thePart: Partition, context: TaskContext): Iterator[T] = new NextIterator[T]
{
var closed = false
context.addTaskCompletionListener{ context => closeIfNeeded() }
val part = thePart.asInstanceOf[JdbcPartition]
val conn = getConnection()
Expand Down Expand Up @@ -100,6 +101,7 @@ class JdbcRDD[T: ClassTag](
}

override def close() {
if (closed) return
try {
if (null != rs) {
rs.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding, we could call rs = null after it is closed, also for stmt and conn in the same way to make this function is reenterable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's another approach, though the other implementation opted for a close flag

Expand All @@ -122,6 +124,7 @@ class JdbcRDD[T: ClassTag](
} catch {
case e: Exception => logWarning("Exception closing connection", e)
}
closed = true
}
}
}
Expand Down