mukulmurthy commented on a change in pull request #26771: [SPARK-30143][SS] Add 
a timeout on stopping a streaming query
URL: https://github.com/apache/spark/pull/26771#discussion_r354588985
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/StreamExecution.scala
 ##########
 @@ -434,6 +434,26 @@ abstract class StreamExecution(
     }
   }
 
+  /**
+   * Interrupts the query execution thread and awaits its termination until the
+   * `spark.sql.streaming.stopTimeout`. A timeout of 0 milliseconds will block 
indefinitely.
+   *
+   * @throws TimeoutException If the thread cannot be stopped within the 
timeout
+   * @throws IllegalArgumentException If the timeout is set as a negative value
+   */
+  protected def interruptAndAwaitExecutionThreadTermination(): Unit = {
+    val timeout = 
sparkSession.sessionState.conf.getConf(SQLConf.STREAMING_STOP_TIMEOUT)
+    queryExecutionThread.interrupt()
+    queryExecutionThread.join(timeout)
+    if (queryExecutionThread.isAlive) {
+      val timeoutException = new TimeoutException(
+        s"Stream Execution thread failed to stop within $timeout milliseconds. 
See stack trace " +
+        "on what was being last executed.")
+      timeoutException.setStackTrace(queryExecutionThread.getStackTrace)
 
 Review comment:
   This is pretty misleading for the exception to have a different stack trace, 
but I guess it's clear from the message... still makes me a tad uneasy.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to