felipepessoto commented on code in PR #13678:
URL: https://github.com/apache/gluten/pull/13678#discussion_r4653697642


##########
backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/GlutenDeltaStatsLifecycleSuite.scala:
##########
@@ -146,6 +150,151 @@ class GlutenDeltaStatsLifecycleSuite extends 
GlutenQueryTest with SharedSparkSes
     }
   }
 
+  for (failBeforeSubmission <- Seq(true, false)) {
+    val timing = if (failBeforeSubmission) "before" else "during"
+    test(s"newRow releases the batch when statistics fail $timing submission") 
{
+      val before = statisticsThreads
+      val workerReady = new CountDownLatch(1)
+      val failWorker = new CountDownLatch(1)
+      val submitting = new CountDownLatch(1)
+      val closeCompleted = new CountDownLatch(1)
+      val completed = new CountDownLatch(1)
+      val closingThread = new AtomicReference[Thread]()
+      val failures = new ConcurrentLinkedQueue[Throwable]()
+      val completionChecks = new ConcurrentLinkedQueue[() => Unit]()
+      val workerFailure = new IllegalStateException("injected statistics 
worker failure")
+      val aggregate = spark.range(1).selectExpr(
+        "to_json(named_struct('numRecords', count(*))) AS stats")
+        .queryExecution.analyzed.collectFirst { case a: Aggregate => a }.get
+      val failStatistics: String => String = _ => {
+        assert(Thread.currentThread().getName.startsWith("Gluten Delta 
Statistics Writer - "))
+        workerReady.countDown()
+        assert(failWorker.await(30, TimeUnit.SECONDS), "Statistics worker was 
not released")
+        throw workerFailure
+      }
+      val statsExpr = ScalaUDF(
+        failStatistics,
+        StringType,
+        Seq(aggregate.aggregateExpressions.head))
+      val tracker = GlutenDeltaJobStatsTracker(new DeltaJobStatisticsTracker(
+        spark.sessionState.newHadoopConf(),
+        new Path("file:/tmp/gluten-stats-worker-failure"),
+        aggregate.child.output,
+        statsExpr))
+      val conf = spark.sessionState.conf.clone()
+      conf.setConfString(GlutenConfig.BENCHMARK_TASK_STAGEID.key, "0")
+      val thread = new Thread(
+        () => {
+          SparkSession.clearActiveSession()
+          try {
+            SQLConf.withExistingConf(conf) {
+              TaskResources.runUnsafe {
+                val context = TaskContext.get()
+                val usage = TaskResources.getSharedUsage()
+                completionChecks.add(
+                  () => {
+                    assert(context.isCompleted())
+                    assert(usage.current() == 0)
+                  })
+                val taskTracker = tracker.newTaskInstance()
+                val file = "file:/tmp/gluten-stats-worker-failure/part.parquet"
+                taskTracker.newFile(file)
+                // End the empty input to reach a controlled failure in the 
actual worker.
+                val closer = new Thread(
+                  () => {
+                    try {
+                      intercept[ExecutionException] {
+                        taskTracker.closeFile(file)

Review Comment:
   Added a separate mid-stream regression in aef2d8fc3. It sends a valid native 
batch, then a deliberately non-offloaded batch that fails in the worker's input 
iterator. The following `newRow()` must propagate that error and release its 
retained reference. There is no `closeFile()` call or end-of-stream signal, and 
the test also checks cleanup of the worker-owned input.
   
   All six lifecycle tests pass on Delta 3.3 and Delta 4. Temporarily reverting 
the trackers to the original blocking `put()` only in isolated validation 
copies makes the new test hit its bounded 30-second deadline; both JVMs still 
exit cleanly.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to