spark-test commented on code in PR #60678:
URL: https://github.com/apache/spark/pull/60678#discussion_r4624732116
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ffi/NativeDataSource.scala:
##########
@@ -1118,9 +1129,10 @@ class NativePartitionReader(
if (!closed) {
closed = true
// A thread in next releases the reader once get_next returns, see
stopReading. Otherwise, a
- // consumer may still read the batch that next returned, unless next was
called since.
+ // consumer may still read the batch that next returned, unless next was
called since, or
+ // the reader is closed in a task without a thread that the task does
not wait for.
if (!reading) {
- closeResources(freeBatch = !batchReturned)
+ closeResources(freeBatch = !batchReturned ||
unawaitedInputThread.exists(!_.get()))
Review Comment:
**Nit (P3):** Tasks that run PipedRDD, script transformation or the R runner
still leave the last batch to the Cleaner at this line, so it stays allocated
until a garbage collection. The PR description defers making those operators
stop and wait for their threads to #60641 (SPARK-61195), but nothing in the
code says so. The comment above this condition, the class doc and the
`TaskInputThreads` Scaladoc describe this path as how the reader works, so a
maintainer cannot tell that it is deferred work rather than the final design,
and the follow-up is easy to lose. A TODO here would mark it, for example:
```suggestion
// TODO(SPARK-61195): In a task that runs PipedRDD, script
transformation or the R runner,
// the batch stays allocated until a garbage collection. Once these
operators stop their
// threads and wait for them before the completion listeners close
the readers of the
// task, a reader closed in a task can always free its batch here,
and TaskInputThreads
// can be removed.
closeResources(freeBatch = !batchReturned ||
unawaitedInputThread.exists(!_.get()))
```
**Verification:**
- **Inspection:** Check that the comment at the free condition in
NativePartitionReader.close() names SPARK-61195 and says which tasks still keep
their last batch until a garbage collection. It must also say that once
PipedRDD, script transformation and the R runner wait for their threads, a
reader closed in a task can always free its batch at close, and
TaskInputThreads can be removed. Check also that the comment does not imply
that this alone removes the Cleaner path, which readers created outside of a
task also take, and that the change touches only comments.
--
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]