From fd8a783027aa0e8f2c2c84f44b1b9ec479647e2c Mon Sep 17 00:00:00 2001 From: yangjie01 Date: Mon, 23 Nov 2026 21:06:38 +0800 Subject: [PATCH 1/2] [spark] Let the interrupted CTAS test input end on a lost task interrupt --- .../sql/V2WriteRequireDistributionTest.scala | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/V2WriteRequireDistributionTest.scala b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/V2WriteRequireDistributionTest.scala index 69cbfa97bebf..f61c12779c01 100644 --- a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/V2WriteRequireDistributionTest.scala +++ b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/V2WriteRequireDistributionTest.scala @@ -24,7 +24,7 @@ import org.apache.paimon.spark.catalog.WithPaimonCatalog import org.apache.paimon.spark.commands.FixedBucketExpression import org.apache.paimon.utils.ExceptionUtils -import org.apache.spark.SparkConf +import org.apache.spark.{SparkConf, TaskContext, TaskKilledException} import org.apache.spark.scheduler.{SparkListener, SparkListenerStageSubmitted, SparkListenerTaskStart} import org.apache.spark.sql.{Row, SparkSession} import org.apache.spark.sql.connector.catalog.{Identifier, TableCapability, TableCatalog} @@ -526,9 +526,21 @@ class V2WriteRequireDistributionTest extends PaimonSparkTestBase with AdaptiveSp session.udf.register( "ctas_interrupt_input", (id: Long) => { - Thread.sleep(30000) + // Before Spark 4.0 (SPARK-44818), a kill that arrives before Task.run records the + // task thread only marks the TaskContext and never interrupts the thread. Poll the + // mark as well, otherwise the cancelled task keeps a local[2] slot and can starve + // the later cases. + val context = TaskContext.get() + val deadline = System.currentTimeMillis() + 30000 + while (System.currentTimeMillis() < deadline) { + if (context.isInterrupted()) { + throw new TaskKilledException("ctas_interrupt_input was cancelled") + } + Thread.sleep(20) + } id.toInt - }) + } + ) val driver = new Thread("interrupted-ctas-driver") { override def run(): Unit = { SparkSession.setActiveSession(session) From 17f4cbdf0ccf806363514b7bfa037c05e52b1fcb Mon Sep 17 00:00:00 2001 From: yangjie01 Date: Mon, 23 Nov 2026 21:44:33 +0800 Subject: [PATCH 2/2] Narrow the lost-interrupt window in the comment --- .../paimon/spark/sql/V2WriteRequireDistributionTest.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/V2WriteRequireDistributionTest.scala b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/V2WriteRequireDistributionTest.scala index f61c12779c01..2c7d1788e134 100644 --- a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/V2WriteRequireDistributionTest.scala +++ b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/V2WriteRequireDistributionTest.scala @@ -526,10 +526,10 @@ class V2WriteRequireDistributionTest extends PaimonSparkTestBase with AdaptiveSp session.udf.register( "ctas_interrupt_input", (id: Long) => { - // Before Spark 4.0 (SPARK-44818), a kill that arrives before Task.run records the - // task thread only marks the TaskContext and never interrupts the thread. Poll the - // mark as well, otherwise the cancelled task keeps a local[2] slot and can starve - // the later cases. + // Before Spark 4.0 (SPARK-44818), a kill that lands after the executor's kill check + // but before Task.run records the task thread only marks the TaskContext: the thread + // is never interrupted and the task keeps running. Poll the mark as well, otherwise + // the cancelled task keeps a local[2] slot and can starve the later cases. val context = TaskContext.get() val deadline = System.currentTimeMillis() + 30000 while (System.currentTimeMillis() < deadline) {