HyukjinKwon opened a new pull request, #457:
URL: https://github.com/apache/spark-connect-rust/pull/457

   ### What changes were proposed in this pull request?
   
   [SPARK-61353](https://issues.apache.org/jira/browse/SPARK-61353): Raise 
`KeyboardInterrupt` promptly on SIGINT during `SparkSession.stop()` and the 
native KMeans fit, in the Python client as PySpark does. This is a follow-up of 
SPARK-61259 (#455).
   
   - `crates/spark-connect-core/src/runtime.rs`: a new `Watch::Abort`, and 
`block_on_abortable`, a `block_on` whose wait ends at once with `None` when its 
watch returns `Watch::Abort`; the future is dropped, unfinished. Any other wait 
treats `Watch::Abort` as `Watch::Continue`, so the waits of SPARK-61259 are 
unchanged.
   - `crates/pyspark-rs/src/interrupt.rs`: when a signal handler raises and no 
execution is in flight to interrupt on the server, the signal watch returns 
`Watch::Abort` (it returned `Watch::Continue`).
   - `crates/spark-connect/src/session.rs`: `SparkSession::stop` waits for the 
release of the session with `block_on_abortable`. An interrupted release leaves 
the session open (not stopped, client not closed), as PySpark's `stop()` does 
when the exception of the signal leaves it, so a later `stop()` releases it.
   - `crates/pyspark-rs/src/session.rs`: `stop()` runs the release first, 
through `interruptible_outcome`, so the exception of the signal is raised 
before anything of the session is torn down.
   - `crates/pyspark-rs/src/ml.rs`: the fit of the native KMeans of 
SPARK-61229, which merged after SPARK-61259 was written, waits through 
`interruptible`, as the other native fits do.
   
   ### Why are the changes needed?
   
   - `stop()` waits for the release of the session and for its retries. Against 
an unreachable server that is about 10 minutes with the default retry policy 
(since SPARK-61319), and a SIGINT did not end it: the release has no execution 
on the server to interrupt, so the wait of SPARK-61259 kept waiting until the 
release ended. PySpark's `stop()` raises `KeyboardInterrupt` at once from its 
sleep between the retries.
   - The native `KMeans().fit(df)` waited without polling the signals, unlike 
the other native fits.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A SIGINT during `SparkSession.stop()` raises `KeyboardInterrupt` at 
once and leaves the session open, as PySpark does, and a SIGINT during a native 
KMeans fit raises it and interrupts the fit on the server, as for the other 
fits. Nothing changes without a signal.
   
   ### How was this patch tested?
   
   - 
`runtime::tests::test_an_abortable_wait_ends_when_its_watch_aborts_and_another_keeps_waiting`
 (offline, placed before `test_with_wait_watch_restores_the_enclosing_watch`): 
an abortable wait ends with `None` when its watch aborts, and gives the output 
of its future otherwise; a `block_on` wait keeps waiting for its future 
whatever the watch returns.
   - 
`test_sigint_during_the_release_of_stop_raises_keyboard_interrupt_and_keeps_the_session`
 (mock server holding the release, placed before 
`test_exception_of_a_signal_handler_is_raised_by_collect_as_pyspark`): `stop()` 
raises `KeyboardInterrupt` within 3 s of a SIGINT, `is_stopped` is false, and a 
later `stop()` stops the session.
   - `test_sigint_during_a_native_kmeans_fit_raises_keyboard_interrupt` (mock 
server holding the execution, same place): the fit raises `KeyboardInterrupt` 
within 3 s, and one `Interrupt` of its operation is sent.
   - The runtime tests of the transport crate (16 passed), the build of all 
tests with no warnings, `cargo fmt --all --check`, and the offline Python tests 
of the signals and of `stop()` (26 passed) with the rebuilt extension.
   
   ### 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]

Reply via email to