Skip to content

feat(c-api): add pollable session and metadata operations - #517

Open
aakash-saravanan-db wants to merge 19 commits into
mainfrom
aakash-saravanan_data/feat/odbc-async-interface-20261130
Open

aakash-saravanan-db wants to merge 19 commits into
mainfrom
aakash-saravanan_data/feat/odbc-async-interface-20261130

Conversation

@aakash-saravanan-db

@aakash-saravanan-db aakash-saravanan-db commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

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, 42P01 and 42S02, 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_CAT row and finishes its close attempt before success; malformed scalar values return DataLoss. 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 provider 7fca294d loads through both standard entry points at ADBC 1.0 and 1.1 using unchanged smoke consumer df6f95d3; each workspace kept its unchanged lockfile and separate output directory. Unchanged ADBC-specific sources retain their earlier e81a46c8 results: 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 (kernel af066b65, ODBC build 00cc186c) and runner ea45d001 from coverage 3cdc2ad3 passed SessionLifecycleTest.AsynchronousCatalogChangeAndDisconnect on 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 exact SELECT 1 result, pending disconnect, and one session open/close. This validates the connected-control and close paths; it does not validate async connection initiation or environment-wide HY115.

Earlier independent Databricks SQL validation used driver 85fc8f91 (kernel b0ea0a05, ODBC dfc26320) and runner ca852350 from coverage 8786a515. 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 after SQL_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 05c184c9 measured median elapsed SQLTables 147.605 → 172.471 ms (+16.85%) and SQLForeignKeys 158.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 HY115 live 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.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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.

Comment thread tests/v0_metadata_wiremock.rs Resolved
Comment thread src/c_abi/metadata.rs Resolved
Comment thread src/c_abi/metadata.rs Resolved
@aakash-saravanan-db
aakash-saravanan-db force-pushed the aakash-saravanan_data/feat/odbc-async-interface-20261130 branch from 463171a to f913bf5 Compare December 1, 2026 00:32
@aakash-saravanan-db aakash-saravanan-db changed the title feat(metadata): add pollable catalog operations to the C ABI # feat(metadata): add pollable catalog operations to the C ABI Dec 1, 2026
@aakash-saravanan-db aakash-saravanan-db changed the title # feat(metadata): add pollable catalog operations to the C ABI feat(metadata): add pollable catalog operations to the C ABI Dec 1, 2026

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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 drop MetadataAbortGuard. 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));

Comment thread src/c_abi/metadata.rs Resolved
Comment thread src/metadata_v0.rs Resolved

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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 with unwrap_or_else(PoisonError::into_inner). (Found by Claude Opus 5.5 · confirmed by the judge)

Comment thread src/c_abi/metadata.rs Resolved
@aakash-saravanan-db

aakash-saravanan-db commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

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.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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 .expect on the mutex, outside the catch_unwind that wraps the metadata future. If the lock is ever poisoned, the task pan
    Judge's evidence: if matches!(*state, MetadataState::Pending) { *state = outcome; }

Comment thread src/statement/mutable.rs Resolved
@aakash-saravanan-db

aakash-saravanan-db commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

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

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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…

Comment thread src/c_abi/metadata.rs Resolved

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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_close after the operation and stream teardown. (Found by GPT-6.1 Sol · confirmed by the judge)

Comment thread src/c_abi/metadata.rs Resolved
@aakash-saravanan-db

Copy link
Copy Markdown
Collaborator Author

In submit_snapshots_inputs_and_returns_an_owned_take_once_stream, kernel_session_close now follows kernel_result_stream_close(stream). The operation still closes before the transferred stream is read, with the session open. The exact Wiremock case passed on Linux with native TLS. Review nit

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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 calls task_state.lock().expect(...) after the catch_unwind block, 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>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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))

Comment thread src/statement/mutable.rs
}
Err(error) => return Err(error),
Err(error) => {
if matches!(cleanup, MidExecuteCleanup::CancelAndClose) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 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)

Comment thread src/client/sea.rs
.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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Comment thread src/c_abi/metadata.rs
});
ptr::write(
out,
Box::into_raw(Box::new(MetadataOperation { state, task })).cast(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

@aakash-saravanan-db

Copy link
Copy Markdown
Collaborator Author

For review 6143722041:

  • Mutex poisoning: The metadata future is caught before the state mutex is acquired. No supported panic-under-lock path was found in the state/error/abort operations. A poisoned-lock panic at an FFI entry maps to Internal; recovering the guard alone would not publish a missing task outcome. State transition, FFI boundary.

  • Timeout GET count: The loop checks elapsed() > poll_timeout, so a zero-elapsed boundary poll is permitted. The valid RUNNING reply preserves the timeout/error and cleanup assertions. A 0..=1 bound would catch some finite extra-poll regressions, but assumes that one local round trip advances Instant; its resolution is platform dependent. The ten-second completion bound and DELETE expectations remain. Loop, tests.

  • Submit coverage: One macro argument list and query body generate both entry forms. The three symbols have NULL-session/output-clearing C smoke checks; shared lifecycle tests and ODBC catalog cases exercise non-NULL submissions. Another enumeration-only wire case would repeat the shared path. Macro, C smoke.

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>

This branch was successfully deployed

1 active (outdated) deployment
azure-prod — 8e7e3569 Deployed Dec 2, 2026 by oss-reviewer-bot[bot] via followup #4875
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant