nookcreed opened a new pull request, #60465:
URL: https://github.com/apache/spark/pull/60465

   ### What changes were proposed in this pull request?
   
   Close temporary spill-backed iterators when their consumers finish early or 
throw an exception.
   
   1. Close match iterators in interpreted and generated sort-merge semi, anti, 
and existence joins.
   2. Evaluate generated streamed-side guards before allocating a match 
iterator.
   3. Close temporary iterators in unbounded-following window frames and 
segment-tree aggregate/block construction.
   4. Add 26 regression cases for early exits, skipped scans, and repeated 
caught predicate/aggregate failures.
   
   The changes close iterators only. They do not clear caller-owned row arrays 
or change full-producing inner/outer join iterator lifetimes.
   
   ### Why are the changes needed?
   
   [SPARK-61251](https://issues.apache.org/jira/browse/SPARK-61251) tracks 
callers that abandon readers before task cleanup. Spill-backed iterators can 
open several files per scan. Repeating an early-terminated scan leaves those 
files open until the task completes.
   
   The regression fixtures measure additional open files inside the task, 
before completion listeners hide the problem. On the original baseline, 
residual joins retained 56 extra files, generated guarded joins retained 64, 
and repeated caught failures retained 64. The patched fixtures retained none in 
these cases.
   
   Following-window counts changed from 117 to 3, and segment-tree counts from 
23 to 6. The remaining files belong to legitimate live cursors. The tests also 
check output equality, positive spilling, and segment-tree execution without 
fallback.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Affected joins and windows no longer retain abandoned spill-file 
readers until task completion. Query results and public APIs are unchanged.
   
   The behavior was reproduced against master commit 
`06a62a35216175f5a49b33c035bd2132bdea4590`. The patch was subsequently rebased 
onto `a61393e569683c886b84121e3a64b484673fd923` without conflicts or behavioral 
changes. Released-branch applicability was not tested.
   
   Existing task-completion listeners can still retain reader record buffers. 
This patch does not resolve that separate memory-retention problem.
   
   ### How was this patch tested?
   
   Added `SpillReaderClosureSuite` with 26 cases. The tests force spilling, 
disable spill read-ahead, and measure file counts inside tasks. They cover 
generated and interpreted execution, result multisets, guarded scans, 
duplicate-key windows, segment-tree use, and repeated caught failures.
   
   Validation uses Java 21 and serial local test suites. The following SBT 
tasks are used:
   
   ```text
   sql/testOnly *SpillReaderClosureSuite *ExistenceJoinSuite *OuterJoinSuite 
*WindowFunctionFrameSuite *WindowSegmentTreeSuite 
*UnboundedFollowingSegmentTreeSuite *SortMergeAsOfJoinScannerSuite 
*SplitStreamedSideJoinConditionSuite
   sql/Compile/scalastyle
   sql/Test/scalastyle
   sql/testOnly *SortMergeAsOfJoinSuite -- -z "in-memory group followed by a 
spill-backed one"
   ```
   
   The main task passed 646 tests across eight suites. The separate 
retained-row regression passed one test. Both Scala style checks reported zero 
errors and warnings. Total: 647 passing tests, including all 26 new 
regressions, on the refreshed base `a61393e569683c886b84121e3a64b484673fd923`.
   
   Independent source review checked iterator ownership, row lifetimes, 
generated variable scopes, guard placement, and preservation of original 
predicate/aggregate exceptions.
   
   The full Spark test suite was not run. The tree aggregate-failure test 
covers initial construction, not a separately injected query-time 
block-construction failure. Iterator-construction cleanup remains outside this 
patch.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Metamate (agentcloud native harness; exact tool/model version 
is not exposed).
   


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