You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/05/04 07:50:57 UTC

[GitHub] [spark] maropu commented on a change in pull request #32222: [SPARK-35126][SQL] Execute jdbc cancellation method when jdbc load job is interrupted

maropu commented on a change in pull request #32222:
URL: https://github.com/apache/spark/pull/32222#discussion_r625576857



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JDBCRDD.scala
##########
@@ -301,10 +306,44 @@ private[jdbc] class JDBCRDD(
         ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)
     stmt.setFetchSize(options.fetchSize)
     stmt.setQueryTimeout(options.queryTimeout)
-    rs = stmt.executeQuery()
+
+    val isFinished = new AtomicBoolean(false)
+    startTheJobInterruptListenerThread(context, stmt, isFinished)
+    try{
+      rs = stmt.executeQuery()
+    } finally {
+      isFinished.set(true)
+    }
     val rowsIterator = JdbcUtils.resultSetToSparkInternalRows(rs, schema, inputMetrics)
 
     CompletionIterator[InternalRow, Iterator[InternalRow]](
       new InterruptibleIterator(context, rowsIterator), close())
   }
+
+  /**
+   * Start the job interruption listener thread, if the job is interrupted and
+   * stmt.executeQuery() is not completed, initiate a stmt.cancel() request.
+   */
+  private def startTheJobInterruptListenerThread(context: TaskContext, stmt: PreparedStatement
+                                                 , isFinished: AtomicBoolean): Unit = {

Review comment:
       I'm still not sure whether this is useful or not. If `fetchSize` is not enough, how about using `queryTimeout` together? 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org