Repository navigation
feat(session): add session routing headers - #357
aakash-saravanan-db wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — a clean, well-tested change that threads SessionAttribution through the reader/link-fetcher/inline paths and negotiates routing headers correctly. The hardcoded Current attribution in cancel_statement/close_statement is safe because those are only reached on owning handles, and the execute_impl header-skip correctly blocks caller override without dropping the kernel's own routing headers. One low-severity maintainability note about the cross-direction header-name mapping.
|
|
||
| impl SessionRoutingHeaders { | ||
| fn from_response(headers: &HeaderMap) -> Self { | ||
| let direct_routing_enabled = headers |
There was a problem hiding this comment.
🔵 Low — The direct_routing_enabled flag is derived from the response header x-databricks-realtime-session (REALTIME_SESSION_HEADER), but the flag then gates emitting a differently-named request header x-databricks-realtime-direct-routing (REALTIME_DIRECT_ROUTING_HEADER) in follow_up_request (line 237). Reading only from_response, it looks like the field should map to the direct-routing header of the same stem. This is intentional per the Fast Path design (the server acknowledges direct routing via realtime-session, and the client echoes realtime-direct-routing on follow-ups), but the three near-identical header names crossing between request and response directions make the mapping easy to misread during future edits. Consider a one-line comment on the field or from_response noting that the realtime-session response header is what activates sending realtime-direct-routing on subsequent requests.
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — one low readability note. The routing/session-ID header negotiation is threaded cleanly: attribution flows through readers, lazy CloudFetch link fetches, and inline continuation; detached statements correctly suppress session-owned routing headers; cancel/close hardcoding Current is safe given attached handles refuse those operations; and the managed-header skip prevents caller override without duplicating the kernel's negotiated values. Test coverage (wiremock lifecycle, independent-header cases, detached suppression, unit-level attribution preservation) is thorough. The only nit is the uncommented request/response header asymmetry in SessionRoutingHeaders::from_response.
|
|
||
| impl SessionRoutingHeaders { | ||
| fn from_response(headers: &HeaderMap) -> Self { | ||
| let direct_routing_enabled = headers |
There was a problem hiding this comment.
🔵 Low — The direct_routing_enabled flag is derived from the response's x-databricks-realtime-session header, yet in follow_up_request it gates emission of a different header, x-databricks-realtime-direct-routing: true. This request/response header asymmetry (server acknowledges via realtime-session, kernel then echoes direct-routing on follow-ups) is the intended handshake per the design doc, but it is entirely uncommented here. A future maintainer reading from_response will reasonably expect the flag to be sourced from the direct-routing header and may "fix" the perceived mismatch, breaking routing. Consider a one-line comment on the direct_routing_enabled assignment explaining that the server signals acceptance via REALTIME_SESSION_HEADER while follow-ups must send REALTIME_DIRECT_ROUTING_HEADER.
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — a clean, well-tested implementation of session routing headers. All session-owned request sites (create/delete session, execute, status polling, chunk fetches, cancel/close, metadata) correctly attach the negotiated headers via follow_up_request, detached paths correctly suppress them, and the removed blanket InlineChunkSource impl has no remaining users. One low note about the cancel/close attribution asymmetry (safe today, but worth documenting).
| .http_client | ||
| .inner() | ||
| .request(Method::POST, &url) | ||
| .follow_up_request(Method::POST, &url, SessionAttribution::Current) |
There was a problem hiding this comment.
🔵 Low — cancel_statement and close_statement hardcode SessionAttribution::Current while every other follow-up RPC (get_statement_status, get_result_chunks, get_inline_chunk, fetch_completed_result, statement_status) threads attribution through the trait. This is safe today: per the detached-adopt contract in session.rs (a non-owning attach never fires close_statement, doesn't drop-cancel, and cancel() returns an error), only session-owned statements ever reach these two methods, so Current is always correct. Flagging as a latent inconsistency: if detached statements ever gain close/cancel capability, these paths would attach the negotiated x-databricks-dbsql-session-id / direct-routing headers to a statement that may belong to a different session. Consider a brief comment documenting why Current is hardcoded here, or threading attribution for symmetry.
1cae322 to
4c09043
Compare
There was a problem hiding this comment.
Verdict: 1 Medium · 1 Low
Solid, well-tested change — routing-header propagation is verified across the full session-owned lifecycle (execute/status/chunks/inline/cancel/close/delete), detached statements are verified to omit the headers, and caller-override protection is covered. Two minor points: (1) medium — the PR description says x-databricks-realtime-session is "propagated" on follow-ups, but the code only uses it as a boolean gate and re-sends x-databricks-realtime-direct-routing instead; worth confirming the header contract against the design doc. (2) low — the dbsql-session-id emptiness check trims but the stored value doesn't.
|
|
||
| if let Some(headers) = self.session_routing_headers.get() { | ||
| if headers.direct_routing_enabled { | ||
| builder = builder.header(REALTIME_DIRECT_ROUTING_HEADER, "true"); |
There was a problem hiding this comment.
🟡 Medium — The PR description says the negotiated x-databricks-realtime-session header is propagated on follow-up requests, but the implementation never echoes that header's value. Instead, from_response collapses x-databricks-realtime-session to a boolean gate (eq_ignore_ascii_case("true")) and follow-ups re-send x-databricks-realtime-direct-routing: true — a different header. Only x-databricks-dbsql-session-id is propagated verbatim.
If the server-issued x-databricks-realtime-session value is actually a routing token that must be echoed back (not merely a boolean ack), the current code silently drops it and direct routing would break. Please confirm against the Drivers Fast Path design that (a) x-databricks-realtime-session is a boolean acknowledgement, and (b) re-asserting x-databricks-realtime-direct-routing: true on follow-ups (rather than echoing the negotiated header) is the intended contract. If the intent is truly to echo the header, the value is being lost here.
| .and_then(|value| value.to_str().ok()) | ||
| .is_some_and(|value| value.eq_ignore_ascii_case("true")); | ||
| let dbsql_session_id = headers | ||
| .get(DBSQL_SESSION_ID_HEADER) |
There was a problem hiding this comment.
🔵 Low — The empty-check trims (!value.trim().is_empty()) but the stored/propagated value is the untrimmed value.cloned(). A server response whose x-databricks-dbsql-session-id carries leading/trailing whitespace would pass the non-empty check and then be forwarded with the whitespace intact on every follow-up request, which could produce a mismatched routing key. Consider storing the trimmed value (build a fresh HeaderValue from value.to_str().trim()) so the check and the stored value agree. Minor — reqwest rarely surfaces OWS-padded header values — but the check/store asymmetry is worth tightening.
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
e69f2e5 to
9726b92
Compare
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — one low-severity note. The session-routing-header contract (negotiate on CreateSession, echo x-databricks-dbsql-session-id, gate x-databricks-realtime-direct-routing on the server ack, keep detached statement requests off the route, and reject caller overrides) is implemented consistently across all current-session request sites and backed by solid wiremock coverage. The only observation is that the new fallible steps in create_session run after the server has minted the session, slightly widening an existing orphan-on-error window (F1).
| "Failed to parse session response: {e} - body: {body}" | ||
| )) | ||
| })?; | ||
| let dbsql_session_id = HeaderValue::try_from(session_response.session_id.as_str()) |
There was a problem hiding this comment.
🔵 Low — Two new fallible steps run after the server has already minted the session (the POST /sessions succeeded): HeaderValue::try_from(session_id) (line 1122) and session_routing_headers.set(...) (returns Err on line 1135). If either returns Err, create_session propagates the error and the just-created server-side session is orphaned — the caller in Session::build never receives a session_id, so it cannot issue a DeleteSession to clean it up.
In practice both are effectively unreachable (session IDs are UUID-shaped ASCII, so HeaderValue::try_from won't fail; set() only fails on a second create, which Session::build never does), and the pre-existing text()/serde_json parsing steps already sit on this same error path — so this widens an existing orphan-on-error window rather than introducing a new failure class. Worth a note only: consider deriving/validating dbsql_session_id before or immediately from the response without failing the whole call (e.g. store None and skip the header) so a session mint is never wasted.
Summary
x-databricks-realtime-direct-routing: trueon CreateSessionx-databricks-realtime-session: trueas the server acknowledgement that enablesx-databricks-realtime-direct-routing: trueon current-session follow-up requestsx-databricks-dbsql-session-idfromCreateSessionResponse.session_idand attach it to current-session follow-up requestsTesting
cargo +stable fmt --all -- --checkcargo +stable clippy --all-targets -- -D warningscargo +stable test(964 unit tests plus all non-ignored integration and doc tests)