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

   ### What changes were proposed in this pull request?
   
   [SPARK-61319](https://issues.apache.org/jira/browse/SPARK-61319): Close 
three connection-layer gaps: the ChannelBuilder keepalive and userAgent 
members, the retry of `release_session`, and the token in connection-string 
errors.
   
   - **ChannelBuilder (drop-in shim)**: adds the `keepalive_enabled`, 
`keepalive_time_ms`, `keepalive_timeout_ms` and `keepalive_without_calls` 
properties, the `userAgent` property, the `PARAM_USER_AGENT` / 
`PARAM_GRPC_KEEPALIVE_*` and `GRPC_DEFAULT_KEEPALIVE_*` constants, 
`GRPC_MAX_MESSAGE_LENGTH_DEFAULT`, `GRPC_DEFAULT_OPTIONS`, and 
`_effective_channel_options()`. Defaults and semantics are those of `core.py` 
in PySpark 4.3.0: the keepalive is on with 60000 ms / 20000 ms / without-calls, 
a non-`true` value is false, the integers are `int(...)` (so a bad value raises 
`ValueError`), and `userAgent` is `<user_agent or SPARK_CONNECT_USER_AGENT or 
_SPARK_CONNECT_PYTHON> spark/4.3.0 os/<os> python/<version>`, raising 
`SparkConnectException` above 2048 escaped characters. 
`_effective_channel_options()` returns the options the Rust channel applies 
(the message lengths, and the keepalive unless it is disabled).
   - **`pyspark/sql/connect/client/core.py`**: a thin re-export of 
`ChannelBuilder`, `DefaultChannelBuilder` and `SparkConnectClient`, the names 
that official code and tests import from there. The rest of `core` is still 
absent.
   - **`release_session` (Rust core)**: now goes through `with_retry`, as 
`interrupt`, `config` and `analyze` do, and as PySpark's `release_session` does 
with `self._retrying()`. `SparkSession::stop()` is unchanged: it releases first 
and closes the client after the release, whether or not the release succeeded, 
so a retry never runs on a closed client.
   - **Connection-string errors (Rust `ChannelBuilder::parse`)**: a bad port 
gives `Port could not be cast to integer value as '<port>'`, urllib's wording 
(PySpark raises it as a plain `ValueError`; ours keeps the 
`INVALID_CONNECT_URL` class), with no URL. A malformed parameter names its key 
only. A missing host quotes the URL with the value of `token` and 
`authorization` replaced by `<redacted>`, the same rule as the `Debug` of 
`ChannelBuilder`. The Python shim's `DefaultChannelBuilder` keeps PySpark's 
messages, which quote the URL, for parity with official.
   - **Official suite**: `test_connect_channel.py` was skipped as a whole file. 
It now runs against the drop-in: 10 of its 14 tests pass; the other four are 
per-test entries in `scripts/dropin_known_failures.txt` for `channelOptions` 
(`NOT_IMPLEMENTED` by design, two tests), `toChannel` (the gRPC channel is the 
Rust transport's, one test), and a client built from a channel builder (one 
test).
   - **Dead-port sessions in tests**: a session on a refused port now waits for 
the retry policy when it is stopped, as PySpark's does (measured: a `stop()` on 
official PySpark against `sc://127.0.0.1:1` did not finish within 170 s). The 
offline suites therefore set `release_session_on_close = False` on the sessions 
they build on a dead port, and the Rust unit tests 
`stop_is_idempotent_and_marks_stopped` and 
`requests_of_a_stopped_session_raise_no_active_session` close those sessions 
instead of stopping them.
   - `dev/parity/known-differences.md`: the keepalive properties and 
`userAgent` are no longer listed as absent. `userAgent` reports PySpark's 
`python/<version>`; the transport sends `python/rust` as the client type, which 
is the identifiability change of SPARK-59136.
   
   ### Why are the changes needed?
   
   - 
`DefaultChannelBuilder("sc://localhost/;grpc_keepalive_time_ms=30000").keepalive_time_ms`
 raised `AttributeError` on the drop-in; PySpark returns `30000`. `userAgent` 
was missing too (PySpark returns `abc spark/4.3.0 os/darwin python/3.11.8` for 
`user_agent=abc`).
   - A transient `UNAVAILABLE` at `stop()` was not retried, so the server 
session stayed until its idle timeout. The failure is only logged, so nothing 
showed it.
   - A bad port put the whole URL into the error, including `;token=...`: 
`sc://localhost:notaport/;token=SECRET` gave `Port 'notaport' in URL 
'sc://localhost:notaport/;token=SECRET' is not a valid integer.` A missing host 
and a malformed parameter echoed the token value too. The Debug output already 
redacted it, so the errors were inconsistent with that.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes.
   - The keepalive properties, `userAgent`, the constants and 
`_effective_channel_options()` exist on the drop-in's `ChannelBuilder` and 
`DefaultChannelBuilder`, with PySpark's values.
   - `pyspark.sql.connect.client.core` imports, with the three re-exported 
names.
   - `stop()` of a session whose server is unreachable waits for the retries of 
`release_session` before it returns, as PySpark's `stop()` does (the default 
policy allows about 11 minutes). Before, it returned after one failed call. A 
session whose server is reachable is released as before.
   - The bad-port and missing-host messages no longer contain the token; the 
port message text changes to PySpark's wording.
   
   ### How was this patch tested?
   
   - New Rust unit tests, which fail on the base code and pass with the fix:
     - `channel::tests::parse_errors_do_not_echo_the_token` (before 
`scheme_is_tls_for_a_token_on_any_host_but_localhost`): the port message names 
only the port, a malformed parameter names only its key, and the missing-host 
message shows `token=<redacted>`.
     - 
`client::tests::release_session_is_retried_on_unavailable_as_the_reference` 
(before `test_add_artifacts_request_structure`): a loopback ReleaseSession 
server answers UNAVAILABLE once; the release is retried and the second call 
succeeds. It fails on the base `release_session` with the UNAVAILABLE error.
   - New offline test 
`test_dropin_offline.py::test_channel_builder_keepalive_and_user_agent_as_pyspark`
 (before `test_spatial_types_take_the_srids_that_pyspark_knows`): defaults, 
tuned parameters, the disabled keepalive, the bad integer, the user-agent 
override by parameter and by environment, the 2049-character error, and the 
`_effective_channel_options()` lists. The expected values were taken from 
official PySpark 4.3.0 on the same inputs. It fails on the base shim 
(`AttributeError`) and passes under pytest 8.3 and under pytest 9.2 
(`PYTEST_DISABLE_PLUGIN_AUTOLOAD=1`).
   - Official `test_connect_channel.py` against the drop-in 
(`run_official_tests.py --dropin --only ...`): 10 passed, 4 deselected by 
design; the drift check reports no test that now passes among the deselected 
ones.
   - Rust: `apache-spark-connect-core` lib 152 passed; `apache-spark-connect` 
lib 528 passed; core integration tests `artifact_uploads` 6, `deadlines` 15, 
`reattach_cleanup` 15, `server_session` 4, `user_context` 4 passed 
(`integration_test`: 3 pre-existing `#[ignore]`d); `cargo test -p 
apache-spark-connect --release --no-run` compiles all targets; `cargo fmt --all 
--check` clean.
   - Clippy (`--workspace --all-targets`): the run stops on pre-existing lints 
of the current toolchain (`approx_constant`, `needless_borrow`, 
`empty_line_after_outer_attr`) in files this PR does not touch; no warning in 
the changed lines except `field_reassign_with_default` in `release_session`, 
which is the request construction that predates this change.
   - Offline Python suites (`test_dropin_offline.py`, `test_arrow_handoff.py`, 
`test_ml_offline.py`): 2928 passed, 8 skipped.
   - Live (`test_dropin_e2e.py -k "stop or session"` on a Spark Connect 
server): 11 passed.
   - The lib tests of both crates (152 and 528 passed), the transport crate's 
integration tests, the build of all tests, the offline Python suites (2928 
passed, 8 skipped) with the rebuilt extension, the new offline test also under 
pytest 9.2, the official `test_connect_channel.py` through the drop-in gate (10 
passed, 4 deselected by design), and the live drop-in tests `-k "stop or 
session"` (11 passed) against a local Spark 4.3.0 server. Clippy reports no new 
diagnostics in the changed lines.
   
   ### 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