zsxwing commented on a change in pull request #24382: [SPARK-27330][SS] support 
task abort in foreach writer
URL: https://github.com/apache/spark/pull/24382#discussion_r314470645
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/sources/ForeachWriterTable.scala
 ##########
 @@ -141,17 +144,32 @@ class ForeachDataWriter[T](
       writer.process(rowConverter(record))
     } catch {
       case t: Throwable =>
-        writer.close(t)
+        closeWriter(t)
         throw t
     }
   }
 
   override def commit(): WriterCommitMessage = {
-    writer.close(null)
+    closeWriter(null)
     ForeachWriterCommitMessage
   }
 
-  override def abort(): Unit = {}
+  override def abort(): Unit = {
+    closeWriter(new SparkException("Foreach writer has been aborted due to a 
task failure"))
+  }
+
+  private def closeWriter(errorOrNull: Throwable): Unit = {
+    if (!closeCalled) {
+      try {
+        writer.close(errorOrNull)
+      } catch {
+        case t: Throwable =>
 
 Review comment:
   nit: could you remove
   ```
   case t: Throwable =>
     throw t
   ```

----------------------------------------------------------------
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