Repository navigation
feat(c-api): add pollable session and metadata operations - #517
aakash-saravanan-db wants to merge 19 commits into
Conversation
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 High · 2 Low
Looks reasonable: 1 medium and 1 low concern. The lifecycle holds up: take-once stream, the cancel/complete race decided under the lock, and abort on close. The main gap is a contract problem: bad arguments to the submit calls are reported later as a Failed status, not rejected at submit.
This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.
463171a to
f913bf5
Compare
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 2 Low
Mostly solid: 3 low concerns. Submit copies its inputs, the operation state is locked with take-once semantics, and abort-guard cleanup is well tested. The concerns are the error code get_result_stream returns, operations continuing after session close, and untested cleanup on the timeout path.
This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge and GPT-6.1 Sol added findings it doesn't mention — see the findings below.
🔀 2 findings considered and dismissed by the judge
- 🔵 Low
src/client/sea.rs:980— For metadata queries, the client-timeout early returns now dropMetadataAbortGuard. That spawns a background cancel and close, where these paths previously di
Judge's evidence:if matches!(state, StatementState::Pending | StatementState::Running) { - 🔵 Low
tests/v0_metadata_wiremock.rs:424— This test closes the session while the submitted statement POST is still in flight, then requires the operation to succeed. That locks in running metadata on a
Judge's evidence:assert_eq!(await_terminal(op), (Status::Succeeded, Code::Success));
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low · 1 Nit
Looks good — 1 low concern. The pollable lifecycle holds up: the cleanup handoff between the abort guard and StatementCloseGuard happens with no await in between, cancel/close races are serialized by the state lock, and outputs are nulled before any fallible work.
This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.
Other findings
- ⚪ Nit — Every access to the state mutex uses
.expect(...), so a poisoned lock turns later status or cancel calls into Internal errors. The guarded sections only assign a plain enum, so poisoning is unlikely and the risk is small. Recover the guard withunwrap_or_else(PoisonError::into_inner). (Found by Claude Opus 5.5 · confirmed by the judge)
|
For the mutex-recovery suggestion in this review, the existing explanation still applies. The guarded work has no await or caller callback, and no supported poisoning trigger was identified. A hypothetical poisoned lock returns Internal through catch_ffi with initialized outputs and a typed last error. No recovery behavior is added. |
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low · 1 Nit
Looks good, with 2 low concerns. The operation state machine, the take-once stream, and cleanup through MetadataAbortGuard and the CancelAndClose guard all read as sound, and the wiremock tests check cleanup ordering. Nit: the MockServer::builder().start() changes in unrelated tests look like noise.
This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge and GPT-6.1 Sol added findings it doesn't mention — see the findings below.
Other findings
- ⚪ Nit — The wire tests have no success case for the columns, foreign keys, procedures or procedure columns submits. A misordered macro argument would go unnoticed. Add a success test for at least one multi-argument submit such as
foreign_keys. (Found by Claude Opus 5.5 · confirmed by the judge)
🔀 1 finding considered and dismissed by the judge
- 🔵 Low
src/c_abi/metadata.rs:166— The worker writes its outcome with.expecton the mutex, outside thecatch_unwindthat wraps the metadata future. If the lock is ever poisoned, the task pan
Judge's evidence:if matches!(*state, MetadataState::Pending) { *state = outcome; }
|
Added a successful foreign-key submit test with six distinct non-null identifiers. It matches the exact foreign-side SQL and verifies that the parent-side filter excludes three rows that each differ in exactly one parent identifier. It takes the result stream after success and checks the single expected parent and foreign key row through end of data. Review |
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks good, with 1 low concern. The pollable metadata operation's lifecycle holds up: take-once stream, cancel and abort, and cleanup guards that cancel and close orphaned statements. The wiremock tests cover failure, cancellation and cleanup ordering.
This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge — see the findings below.
🔀 1 finding considered and dismissed by the judge
- 🔵 Low
tests/v0_metadata_wiremock.rs:509— This ownership test closes the server session before the operation completes, so its successful read relies on the mock accepting work after session deletion ra
Judge's evidence:assert_eq!(kernel_session_close(session), Code::Success); assert_eq!(await_terminal(op), (Status::Succeeded, Code::Succe…
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low · 1 Nit
Looks good: one low concern. The pollable metadata operation state machine, the take-once stream and the cleanup guards hold up. The open question is when statement cleanup actually runs after an abort.
This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.
Other findings
- ⚪ Nit — The test closes the session while the operation is still pending, then expects the operation to succeed and its stream to be consumed. That contradicts the header's close-operations-before-session contract, and the buffered CLOSED response hides any failure. Move
kernel_session_closeafter the operation and stream teardown. (Found by GPT-6.1 Sol · confirmed by the judge)
|
In |
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
✅ No issues identified.
🔀 1 finding considered and dismissed by the judge
- 🔵 Low
src/c_abi/metadata.rs:163— The spawned task callstask_state.lock().expect(...)after thecatch_unwindblock, so a poisoned state mutex panics the task without publishing an outcome,
Judge's evidence:let state = op.state.lock().expect("metadata state lock poisoned");
Submit catalog work with owned arguments and session state. Poll the operation, cancel pending work, and take its lazy result stream after completion. Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Materialize the current catalog and attempt statement close inside the owned metadata task. Return an in-memory result through the existing operation handle. 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>
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>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks solid, with 2 low concerns. The state machine for the pollable operations, the take-once stream and the cleanup guards hold up, and the wiremock tests cover the key lifecycle cases.
This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge — see the findings below.
🔀 1 finding considered and dismissed by the judge
- 🔵 Low
src/client/sea.rs:2222— Both default-timeout tests dropped the.expect(0)on the status GET mock and now answer it with RUNNING, which loosens what the tests check about polling. If
Judge's evidence:.respond_with(ResponseTemplate::new(200).set_body_json(running))
| } | ||
| Err(error) => return Err(error), | ||
| Err(error) => { | ||
| if matches!(cleanup, MidExecuteCleanup::CancelAndClose) { |
There was a problem hiding this comment.
🔵 Low — After a terminal success, self.reader_factory()? returns early without closing the statement. The caller then defuses the CancelAndClose guard on every Err, so the lookup statement is not closed. It is only reachable if the reader factory was never initialised, so the impact is small. Close the orphaned statement before that ?, or defuse only when the transport attempted the close.
🔀 Found by Claude Opus 5.5 · confirmed by the judge
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 2 Low · 1 Nit
Looks solid overall, with 3 low-severity concerns. The take-once state machine, the cancel and close ordering, and the cleanup guards look consistent. The concerns are poisoned-lock robustness in the spawned task, a weakened timeout-test assertion, and thin coverage for three of the submit variants.
Other findings
- ⚪ Nit — Submit variants for list_columns, procedures and procedure_columns have only a NULL-session smoke check. The macro shares one query body with the blocking variants, so the risk is small. Add one wiremock submit→status→take test for one of them. (Found by Claude Opus 5.5 · confirmed by the judge)
| .and(path("/api/2.0/sql/statements/stmt-default-timeout")) | ||
| .respond_with(ResponseTemplate::new(200).set_body_json(json!({}))) | ||
| .expect(0) | ||
| .respond_with(ResponseTemplate::new(200).set_body_json(running)) |
There was a problem hiding this comment.
🔵 Low — The default-timeout and metadata-timeout tests dropped .expect(0) on the status GET mock, so the poll count is no longer asserted. Restore an exact or bounded GET expectation, and document why polling now occurs.
🔀 Found by Claude Opus 5.5 · confirmed by the judge
| }); | ||
| ptr::write( | ||
| out, | ||
| Box::into_raw(Box::new(MetadataOperation { state, task })).cast(), |
There was a problem hiding this comment.
🔵 Low — If the state mutex is poisoned, the spawned task panics before publishing an outcome and the operation stays Pending forever. Poisoning is unlikely. Recover the guard with unwrap_or_else(PoisonError::into_inner) in the task, status, get_result_stream and cancel.
🔀 Found by Claude Opus 5.5 · confirmed by the judge
|
For review 6143722041:
|
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>
…checks Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Description
C callers currently block on session lifecycle, controls and catalog metadata preparation. This PR adds owned handles for polling that work on the existing runtime. Synchronous APIs and default ignore-transactions behavior remain unchanged. These are native C ABI bindings for consumers such as ODBC; the standard ADBC interface does not gain these APIs.
Six session functions submit open, close or a fixed control, poll readiness, take an opened session once and close the operation. Open owns its configuration, copies catalog/schema inputs and applies quoted catalog, schema and autocommit setup in order. Catalog/schema setup is best effort for SQLSTATEs
42704,42P01and42S02, and for NotFound errors without a SQLSTATE. Any other SQLSTATE fails setup, including on HTTP 404. Other setup errors preserve the original diagnostic after best-effort session close. Poll repeats terminal status and copies errors to caller-thread storage. Closing a session operation detaches running work without aborting it; untaken sessions use existing cleanup.Separate metadata operations cover catalogs, schemas, tables, columns, primary/foreign keys, procedures, procedure columns and current catalog. Submit copies strings and retains session state. Status reports readiness and diagnostics; success transfers a lazy result stream once. Current-catalog lookup materializes one
TABLE_CATrow and finishes its close attempt before success; malformed scalar values returnDataLoss. Cancel or close of pending metadata work requests task abortion and best-effort statement cleanup. Cleanup can race session close and cannot address a statement whose ID was never received. Foreground failures await close when an ID exists. Transferred streams outlive their operation while the session remains open.Testing
At kernel
af066b65, all five session-operation cases pass, including explicit SQLSTATE precedence on a mocked HTTP 404 error response, owned setup/order, repeated caller-thread diagnostics, detach cleanup and invalid-output clearing. The full default suite passes 1,387 tests with 66 ignored, including doc tests; Rustfmt and strict all-target Clippy pass. The C ABI smoke and C/C++ header checks pass. Rebuilt debug ADBC provider7fca294dloads through both standard entry points at ADBC 1.0 and 1.1 using unchanged smoke consumerdf6f95d3; each workspace kept its unchanged lockfile and separate output directory. Unchanged ADBC-specific sources retain their earliere81a46c8results: strict Clippy, 99 unit tests and one timezone integration test passed, with six live cases ignored; that suite was not repeated.Independent Databricks SQL passthrough with driver
e1a4f1e8(kernelaf066b65, ODBC build00cc186c) and runnerea45d001from coverage3cdc2ad3passedSessionLifecycleTest.AsynchronousCatalogChangeAndDisconnecton unixODBC 2.3.6: one test ran without failures or skips. It verified connected OFF/ON readback, a pending catalog setter, rejection of child statement allocation while pending, the exactSELECT 1result, pending disconnect, and one session open/close. This validates the connected-control and close paths; it does not validate async connection initiation or environment-wideHY115.Earlier independent Databricks SQL validation used driver
85fc8f91(kernelb0ea0a05, ODBCdfc26320) and runnerca852350from coverage8786a515. Three cases covered all six remote catalog APIs; a separate NULL-catalog cancel/retry verified pending,HY008, exact results through end of data and same-statement reuse afterSQL_CLOSE. These results do not validate the new session operations.Five alternating warm runs per side with Simba 2.14.0.1000 versus earlier ODBC build
05c184c9measured median elapsedSQLTables147.605 → 172.471 ms (+16.85%) andSQLForeignKeys158.058 → 177.897 ms (+12.55%). Same-backend pre-feature controls moved +2.69% and +3.18%. Attribution remains partial; current performance and overall parity remain open.Additional notes
ODBC is a downstream consumer, not a kernel dependency. Its merge needs a kernel main/tag source containing these ABIs; driver release requires compatible native kernel artifacts published first, refreshed dependency pins/floors/locks and installed or bundled pair validation. Full async-connect and environment
HY115live validation still require a compatible ODBC 3.8 Driver Manager, unavailable on this host. Their implementation and owning unit coverage remain in scope. New session-operation installed-pair, scheduled, platform and current-CI checks remain unrun. Close metadata operations and transferred streams before initiating session close; serialize exclusive take/close access.