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

   ### What changes were proposed in this pull request?
   
   [SPARK-61218](https://issues.apache.org/jira/browse/SPARK-61218): a session 
whose server-side session changed is stopped, as PySpark's `is_stopped` is the 
client's `is_closed`.
   [SPARK-61219](https://issues.apache.org/jira/browse/SPARK-61219): 
`spark.stop()` releases the server session before it cancels the listener bus, 
so the terminated events of the running queries reach the listeners.
   
   - `SparkSession::is_stopped` is true when the client is closed, as after a 
server-side session change (SPARK-61184). So `is_stopped`, `getActiveSession()` 
and `getOrCreate()` no longer return the dead session, and `getOrCreate()` 
makes a working session, as in PySpark.
   - `SparkSession::stop` releases the server session only while the client is 
open, as PySpark's `stop()` checks `if not self.is_stopped`. Then it cancels 
the listener bus and closes the client, so the server's terminated events of 
the queries still running are dispatched. The stop stays idempotent.
   
   ### Why are the changes needed?
   
   After a server restart, the observed server-side session ID changes and the 
client closes, so every call raises `NO_ACTIVE_SESSION`. But `spark.is_stopped` 
stayed `False`, `SparkSession.getActiveSession()` returned that session, and 
`SparkSession.builder.getOrCreate()` returned it again, so the error's own 
recovery ("create a new Spark Session") did not work. `stop()` also sent 
ReleaseSession to the restarted server.
   
   `spark.stop()` cancelled the listener bus before ReleaseSession, so a 
listener of a query still running at stop got `onQueryStarted` and never 
`onQueryTerminated`. Official PySpark 4.3.0 gives the terminated event 
(`['start', 'term']` in the probe).
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. After a server-side session change, `is_stopped` is `True`, 
`getActiveSession()` is `None` and `getOrCreate()` creates a new session. 
`stop()` of such a session sends no ReleaseSession. `spark.stop()` delivers 
`onQueryTerminated` to the listeners of the queries running at stop.
   
   ### How was this patch tested?
   
   - `test_a_server_side_session_change_stops_the_session_as_pyspark` (offline, 
mock gRPC server whose server-side ID changes): the session is stopped after 
the change, `getActiveSession()` is `None`, `getOrCreate()` returns a new 
working session, and `stop()` of the closed session sends no ReleaseSession. 
Official PySpark 4.3.0 gives the same results (`is_stopped` True, 
`getActiveSession()` None, a new session works).
   - 
`test_a_query_running_at_stop_sends_its_terminated_event_to_the_listeners_as_pyspark`
 (live): a rate query with a listener on a new session, `stop()` of the 
session, then the terminated event within 120 s. Official PySpark 4.3.0 gives 
the same event.
   - 
`session::tests::a_session_whose_client_closed_is_stopped_and_is_not_released` 
(Rust): a closed client makes the session stopped and shared by clones, and 
`stop()` does not release it (the port has no server, so a release that reached 
the wire would fail).
   - Both Python tests fail without the change (the terminated test times out, 
the offline test fails at `is_stopped`).
   - The tests of both crates against a local Spark 4.3.0 Connect server (791 
and 185 passed), the build of all tests, also with `wasm-udf`, the offline 
Python suites (2704 passed, 8 skipped), and the live drop-in, Arrow and ML 
suites (225 passed) and live cases (12 passed). rustfmt passes, and clippy 
reports no diagnostics in the changed lines. The new live test passed in 10 of 
10 runs under a machine load of about 45.
   
   ### 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