comphead commented on code in PR #7804:
URL: https://github.com/apache/datafusion-comet/pull/7804#discussion_r4762657558
##########
native/core/src/execution/jni_api.rs:
##########
@@ -1300,12 +1300,11 @@ unsafe fn export_batch(
Ok(num_rows as i64)
}
-/// Pull the next input from JVM. Note that we cannot pull input batches in
-/// `ScanStream.poll_next` when the execution stream is polled for output.
-/// Because the input source could be another native execution stream, which
-/// will be executed in another tokio blocking thread. It causes JNI throw
-/// Java exception. So we pull input batches here and insert them into scan
-/// operators before polling the stream,
+/// Pulls the next batch from the JVM into every JVM-fed scan whose slot is
empty. `next_batch`
+/// calls it only after a poll of the stream returns `Pending`. It cannot run
inside
+/// `ScanStream.poll_next`, because the input source can be another native
execution stream
+/// running on another tokio blocking thread, and calling into it from there
makes JNI throw.
+/// With two JVM inputs, a poll waiting on one also refills the other if its
slot is empty.
#[inline]
Review Comment:
This doc comment says a poll waiting on one input also refills the other.
That means the title and rationale ("pull only when the native plan waits for
it") hold for a single JVM input but not for joins or unions. Waiting on scan A
on a `Pending` still reads a batch from scan B if its slot is empty. Two
consequences: a limit finished by A can still fail on a read from B, and a join
pins one batch of the other side in JVM off-heap memory before it is needed.
There is no deadlock or starvation risk, because `on_pending` always fills
every empty slot and the stream waker is set by the refill. Could `ScanExec`
and `ShuffleScanExec` record that their `poll_next` returned `Pending` (an
`AtomicBool` next to `waker`, cleared in `get_next_batch`), so
`pull_input_batches` only pulls scans the plan is actually waiting on? If that
is out of scope for this PR, the test could at least cover the two-input case,
or the PR description could say the guarantee is per input. The
`shuffle_scan.rs` doc
on `get_next_batch` ("Called externally before poll_next()") also still
describes the old order.
--
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]