HyukjinKwon opened a new pull request, #469: URL: https://github.com/apache/spark-connect-rust/pull/469
### What changes were proposed in this pull request? [SPARK-61362](https://issues.apache.org/jira/browse/SPARK-61362): low-priority transport findings of a review of the Rust core, each checked against PySpark 4.3.0 and grpc-python 1.76. - **Codes and retries** (`crates/spark-connect-core/src/retries.rs`, `error.rs`): - The new `retries::grpc_python_code` gives a failed call the code that grpc-python reports for it. - A status that the server sent keeps its code. - A dropped connection, a GOAWAY that processed no stream, and a call that a closing connection canceled before sending are `UNAVAILABLE`. - A stream reset of a reason that tonic leaves `UNKNOWN` (`STREAM_CLOSED`, `FRAME_SIZE_ERROR`, `HTTP_1_1_REQUIRED`) is `INTERNAL`. - `RetryPolicy::can_retry` and `SparkError::from_grpc_status` (so `grpc_code()`, and the drop-in's `getGrpcStatusCode()`) use this code. - **The transport seam** (`crates/pyspark-rs/src/transport.rs`), which the pandas-parity gate runs official PySpark over, reports the per-message errors of a stream with that code too. - **Request fields** (`client.rs`), as PySpark sets them per request type: - `client_type` on ExecutePlan, AnalyzePlan, Config, Interrupt, FetchErrorDetails, ReattachExecute, ReleaseExecute and ReleaseSession; `"python"` on CloneSession. - No `client_observed_server_side_session_id` on ReleaseExecute, CloneSession, AddArtifacts and ArtifactStatus. It is set on the first ExecutePlan of a session, after the lookup that gives the server-side session ID. - No `user_id` gRPC header: PySpark sends the user ID in the user context only. - **Channel** (`channel.rs`): - With the keepalive enabled, a `grpc_keepalive_time_ms` or `grpc_keepalive_timeout_ms` that Python's `int()` does not read raises PySpark's `ValueError` ("invalid literal for int() with base 10: 'abc'") when the client connects. The values are read as `int()` reads them. - The user agent names the OS as Python's `platform.uname().system.lower()` does: `darwin`, not `macos`. - **Plan compression** (`client.rs`): - Plans are sized with `encoded_len()` and encoded only when over the threshold. - The plan of an execution is compressed again after an `on_execute_plan` hook ran. The drop-in's hook resolves there the placeholder of a DataFrame that a hook put in. ### Why are the changes needed? - grpc-python reports a stream reset with `STREAM_CLOSED`, `FRAME_SIZE_ERROR` or `HTTP_1_1_REQUIRED` as `INTERNAL`, which PySpark does not retry. Ours retried it 15 times, over about 10 minutes. - A GOAWAY that processed no stream was retried only when tonic happened to report it as `UNKNOWN`: in most runs it was `INTERNAL` or `RESOURCE_EXHAUSTED`. grpc-python reports `UNAVAILABLE`, and PySpark retries it. - The Rust transport passed a dropped connection on as `UNKNOWN`, so official PySpark over it did not reattach. Through a proxy that resets a `range(3_000_000).collect()` mid-result, it now reattaches and returns all rows. Before, it raised `UNKNOWN`. - PySpark sends no `user_id` header and no observed session ID on these requests, and sends `client_type` on all of them. A bad keepalive parameter was ignored, and the OS name differed. - Plans were encoded only to be measured. And the plan of a DataFrame that a hook put in went uncompressed over the threshold, where PySpark's hook puts in the plan of `to_proto`, which compresses it. ### Does this PR introduce _any_ user-facing change? Yes: - `SparkError::grpc_code` and the drop-in's `getGrpcStatusCode()` give the codes of grpc-python for transport failures: `UNAVAILABLE` where they were `UNKNOWN` or `CANCELLED`, and `INTERNAL` for the stream resets above. These resets are no longer retried, and GOAWAYs always are. `docs/compatibility.md` notes it. - The request fields and the user agent above change. - A non-integer keepalive parameter raises `ValueError` at connect. - The new public function `spark_connect_core::retries::grpc_python_code`. ### How was this patch tested? - Rust unit tests, each failing without its change: - `retries.rs`: `test_cannot_retry_a_stream_the_server_resets_as_grpc_python` and `test_can_retry_a_connection_the_server_ends_with_a_goaway_as_grpc_python`. A raw HTTP/2 server answers a call with RST_STREAM or GOAWAY frames of each reason. Asserts are added to the existing reset, CANCELLED and server-status tests. - `client.rs` `request_fields_tests`: - `requests_carry_the_client_type_and_the_observed_session_of_pyspark`: a recording server, over every RPC; - `requests_carry_no_user_id_header_as_pyspark`; - `connect_raises_for_a_keepalive_param_that_is_not_an_integer_as_pyspark`; - `the_plan_that_a_hook_puts_in_is_compressed_as_pyspark`. - `channel.rs`: `keepalive_params_are_read_with_python_int_as_pyspark` and `user_agent_names_the_os_as_pyspark`. - Offline Python (`python/tests/test_dropin_offline.py`, placed before `test_broadcast_type_check`): - `test_the_transport_reports_a_dropped_connection_as_unavailable_as_grpc_python`; - `test_create_raises_for_a_keepalive_param_that_is_not_an_integer_as_pyspark`; - `test_the_plan_of_a_dataframe_that_a_hook_puts_in_is_compressed_as_pyspark`. `_sent_relation` takes the kind of its request now: an ExecutePlan request has `client_type` as its field 4. - Live: - `test_the_server_runs_the_compressed_plans_of_a_session_as_pyspark_sends_them` (`crates/spark-connect/tests/e2e_integration.rs`): under a threshold of 1000, a statement, a schema analysis, a collect and a temp view run compressed on a local Spark 4.3.0 server. - `e2e_reattach_drop` passes. - A wire probe (fake server) of official PySpark and of ours now gives the same fields per request. Two exceptions: the `client_type` of AddArtifacts and ArtifactStatus, which the Scala client sends and the server reads nowhere, and the `python/rust` of the user agent, a documented difference. - Checks: - lib tests of both crates (739 passed); - the build of all tests, also with `wasm-udf` and `datafusion,polars`, without warnings; - `cargo fmt --all --check`, and clippy with no diagnostics on the changed lines; - offline Python suites (3039 passed, 8 skipped, before the helper fix of the one failing test); - live drop-in, Arrow and ML suites against a local Spark 4.3.0 server (265 passed). ### 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]
