HyukjinKwon opened a new pull request, #477: URL: https://github.com/apache/spark-connect-rust/pull/477
### What changes were proposed in this pull request? [SPARK-61388](https://issues.apache.org/jira/browse/SPARK-61388): a follow-up of #455 (SPARK-61259) and #457 (SPARK-61353), from a review of them. A SIGINT in the Python client now interrupts only the execution that the interrupted call waits for, as PySpark does: - The registry of in-flight executions (`crates/spark-connect-core/src/client.rs`) records, for each execution, the thread that started it and the thread that waits for it now. The first RPC of an execution and each `ReattachableResponseStream::message()` mark the execution as waited for while they wait, only on the thread that started it. `running_operation_id()` returns the innermost execution that the calling thread waits for, so an execution that is in flight but not read (a half-consumed iterator, a listener's subscription that its own worker reads) is not interrupted. - The Rust API's prefetching `to_local_iterator(prefetch_partitions = true)` reads its stream in a task. Its `next()` marks the execution as waited for by the caller while the caller waits for the task's batch, through a new `InflightHandle` (`ReattachableResponseStream::inflight_handle()`). - The signal watch (`crates/pyspark-rs/src/interrupt.rs`) no longer latches a signal that arrives while no execution is waited for, such as during the plan compression lookup or an analysis before an execution. It keeps the exception, and interrupts the first execution that the call then waits for, once. An abortable wait (the release of `stop()`) ends at once, as before. ### Why are the changes needed? The registry was keyed by the thread that started an execution, and its innermost entry won: - With a half-consumed `toLocalIterator()` B alive, a SIGINT during `next(A)` interrupted B. A ran to its end (20 s in the review's repro) before `KeyboardInterrupt`. PySpark 4.3.0 interrupts A after about 2 s, and `next(B)` still returns its next row. Now the drop-in does the same. - With such an iterator, or a `StreamingQueryListener` registered from the main thread, a SIGINT during `SparkSession.stop()` interrupted that unrelated execution, and `stop()` then waited for the release (75 s and more with an unreachable server) instead of raising `KeyboardInterrupt` at once, as #457 meant and PySpark does. - A signal during the plan compression lookup (a Config RPC before the first execution of a session) was consumed and latched, so the execution that the call then started ran to its end. Now it is interrupted. ### Does this PR introduce _any_ user-facing change? Yes, in the Python client and the Rust API's waits: `KeyboardInterrupt` interrupts the execution that the interrupted call waits for, promptly, and leaves the other executions and the session alone. ### How was this patch tested? - Rust unit tests: the registry selects only the innermost execution that the calling thread waits for (not an unread one, not another thread's wait), and an `InflightHandle` marks only the waits of the thread that started the execution. - Rust e2e (`e2e_session_catalog.rs`): a watch on the caller interrupts a prefetching iterator's execution during `next()`, an unread prefetching iterator is not selected, and the session works afterwards. - Offline Python tests (mock server): the iterator that waits is interrupted and a held one still yields; SIGINT during `stop()` with an unconsumed iterator and with a registered listener raises at once; a SIGINT during the plan compression lookup interrupts the first execution. Each new test fails without the change. - Live Python e2e: the review's repro with a sleeping partition (`reflect`), against a Spark 4.3.0 server. - `cargo test -p apache-spark-connect -p apache-spark-connect-core --release --lib`, the `--no-run` builds with and without `wasm-udf`, `cargo fmt --check`, the offline and e2e drop-in suites. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 This pull request and its description were written by Isaac. -- 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]
