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

   ### What changes were proposed in this pull request?
   
   This PR is #508 by viirya (commit cf0aa70, unchanged) plus one commit so 
that CI passes. `with_retry` now awaits its attempt through `FutureExt::map` 
instead of an async block that captures the future of the RPC and awaits it. 
Such a block keeps that future twice, which made every call future of the 
client about half again as large (`analyze_plan` 75 KB -> 110 KB in a release 
build). That overflowed the stack of `deep_request_stack_tests` (SPARK-61400) 
and of the debug test threads of `request_fields_tests` and `array_literal`, 
which is what failed CI on #508. With the combinator the futures are as large 
as on master; see 
https://github.com/apache/spark-connect-rust/pull/508#issuecomment-6809693828. 
#508 will be closed in favor of this PR, and viirya stays the primary author of 
the merge.
   
   The rest of this description is #508's:
   
   The Rust client retried its calls in four hand-written loops in 
`crates/spark-connect-core/src/client.rs`: the unary and stream-opening calls 
(`with_retry`), the artifact upload, the background `ReleaseExecute`, and the 
reattach of a result stream. Each had its own copy of the decision "can the 
policy retry this failure, is a retry left, wait its backoff".
   
   That decision is now `retries::Retrying`, as PySpark's `Retrying`:
   
   - `Retrying::backoff(status)`: a failure that the policy can retry is an 
attempt of the policy. It waits the backoff of the attempt (or the `RetryInfo` 
delay of the server) and is bounded by `max_retries`.
   - `Retrying::retry_at_once()`: what PySpark raises as a `RetryException` is 
retried without a wait and outside the attempts of the policy, for up to 
`max_retry_exception_elapsed_time_ms` from the first of them. This was 
`retry_exception_bound_passed` in `client.rs`.
   - `retries::retrying(retrying, before_retry, attempt)`: the loop over the 
attempts of a call. `with_retry`, the artifact upload and `ReleaseExecute` use 
it.
   
   The four loops were not the same, and the differences are on purpose. They 
are kept, as parameters:
   
   - The calls of a client check that the client is still open after the wait 
of each retry (`before_retry`), as PySpark's `_stub` raises `NO_ACTIVE_SESSION` 
for a closed client. `ReleaseExecute` checks nothing, as PySpark sends it 
through the stub of its iterator, and its failure is only logged.
   - The backoffs of the calls that a caller waits for end with a signal that 
the wait of the caller takes (SPARK-61407), as the sleep of PySpark's 
`Retrying` raises `KeyboardInterrupt`: `Retrying::ending_with_abort`, and 
`backoff` answers `Backoff::Aborted`. Those of `ReleaseExecute`, in the 
background, are waited whole. Only `with_retry` also ends an attempt that is 
not answered, as before.
   - An attempt of the artifact upload can fail with an error that is not a 
failed RPC, such as a source that cannot be read. It ends the call and is not 
retried: `RetryError::Aborted`.
   - The reader of a reattachable stream does not make one call for each 
attempt. A stream that fails and the reattach after it share the attempts of 
one `Retrying` for each response (SPARK-61415), and a deadline or an unknown 
operation is retried at once. It keeps its own loop, and asks `backoff` and 
`retry_at_once` for every decision.
   
   Two related fixes in the same code:
   
   - `Instant::now() + deadline`, at the three places that set the deadline of 
a stream, panics for a deadline too large to add to the time. It is now 
`checked_add` in `stream_deadline_in`, and a deadline that cannot be a time is 
none, as it is never reached.
   - PySpark recognizes `INVALID_CURSOR.DISCONNECTED` (`in str(e)` in 
`DefaultPolicy.can_retry`) and `INVALID_HANDLE.OPERATION_NOT_FOUND` / 
`SESSION_NOT_FOUND` (`in status.message` in 
`ExecutePlanResponseReattachableIterator`) by their name in the message, not by 
the `ErrorInfo` of the status. So the client still matches on the message, 
through one function, `retries::condition_in_message`, behind 
`cursor_disconnected` and `unknown_operation`.
   
   ### Why are the changes needed?
   
   A change to how the client retries had to be made in four places, and the 
loops could drift apart: SPARK-61415 had to change the reattach path alone. 
With one implementation, which errors are retried, the backoff, the number of 
retries and the elapsed-time bound are each decided in one place, next to the 
policy.
   
   ### Does this PR introduce _any_ user-facing change?
   
   A reattachable execution whose `RpcDeadlines` are too large to add to the 
current time (such as `Duration::MAX`) no longer panics; its streams have no 
deadline. Nothing else changes.
   
   ### How was this patch tested?
   
   - New unit tests in `retries.rs` for `retrying` (a retryable failure until 
an attempt succeeds, a failure that is not retryable, the retries spent, 
`no_retries`, a call past its deadline, an attempt that fails with an error 
that is not a failed RPC, the check before a retry that fails), for 
`Retrying::backoff` (it waits, a failure that is not retried spends no retry, 
and a signal ends the backoff of the retries that end with an abort and not of 
the others), for `Retrying::retry_at_once` (bounded by the elapsed time from 
the first of them, and not by the attempts), and for the two matchers of the 
message. A new unit test in `client.rs` for a stream deadline of 
`Duration::MAX`.
   - `cargo test -p apache-spark-connect-core --release`: 258 passed, 0 failed, 
3 ignored (the tests of a live server). The existing loopback tests 
(`deadlines`, `reattach_cleanup`, `artifact_uploads`, `server_session`, 
`user_context`) cover each of the four call sites and pass unchanged.
   - `cargo test -p apache-spark-connect --release --no-run` compiles.
   - `cargo fmt --all --check` is clean.
   - `cargo clippy -p apache-spark-connect-core --all-targets` reports nothing 
in `retries.rs`, and one new advisory `result_large_err` warning in 
`client.rs`, of the kind that the file already has for `SparkError`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (claude-fable-5-2)
   
   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