Repository navigation
[PECOBLR-2096] C ABI follow-up: lazy metadata streaming, empty-filter semantics, session-close delete initiation - #160
Conversation
…unfiltered, initiate session delete on close Follow-up to the merged C ABI PR (#158), addressing gopalldb's three post-merge findings. [MAJOR] Unbounded metadata buffering `drain_metadata` materialised the entire metadata result into a Vec<RecordBatch> up front, justified as "bounded". That is false for `kernel_metadata_list_columns` with a NULL catalog (→ SHOW COLUMNS IN ALL CATALOGS), which returns a row per column of every table in every visible catalog. The owned result-stream handle now holds the `ResultStream` and drives `next_batch` lazily on the runtime (one batch per C call, via `block_on_ffi` — same on-runtime discipline the executed path uses), so a large metadata result streams with bounded memory instead of spiking it for the life of the handle. `run_metadata` now captures only the schema up front and hands the stream to the handle. [MAJOR] Empty-string identifier rejected instead of "unfiltered" `opt_ident` mapped only a NULL pointer to None; a non-null empty string became Some("") → Identifier::new("") → InvalidArgument. ODBC/JDBC drivers routinely pass "" (not NULL) to mean "match all", so list_schemas / list_tables / list_columns rejected a legitimate call. Added `opt_filter_str`, which treats NULL and empty/whitespace-only alike as None; `opt_ident` / `opt_pattern` route through it. (Required identifiers — PK/FK table — still reject empty, correctly.) [MAJOR] session_close didn't initiate DeleteSession with handles open `kernel_session_close` dropped one Arc<SessionInner>; DeleteSession only fires from SessionInner::Drop, i.e. when the LAST Arc drops. A live statement / executed handle holds its own clone, so the delete was deferred until those were released too — contradicting the header's "close initiates the delete" contract and risking a server session lingering to idle-timeout. Added SessionInner::initiate_delete (idempotent via a compare-and-swap on `closed`; Drop now delegates to it), exposed Session::initiate_delete, and call it from kernel_session_close so the delete is initiated immediately regardless of outstanding handles. Header + Rust docs updated to match. Tests: metadata empty→unfiltered unit tests; a C-ABI wiremock test asserting close initiates DELETE with a statement handle still open; the existing owned-stream exhaustion test now builds a lazy ResultStream via MockReader. cargo fmt / clippy --all-targets clean; 673 lib tests + all integration suites + C smoke pass. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
|
💡 [MINOR] · bug · src/c_abi/session.rs:555 Metadata stream driven after kernel_session_close hits a session whose DeleteSession was already initiated Outstanding metadata streams become undefined after kernel_session_close now that close eagerly initiates DeleteSession. kernel_session_close (src/c_abi/session.rs:555) now calls initiate_delete(), which spawns the server-side DeleteSession immediately (src/session.rs:150-168). A metadata ResultStream is built via from_reader_with_close and holds its own Arc clone (src/metadata_v0.rs:302-307), so it outlives the session box and remains drivable. If a caller closes the session while such a stream is still open and then calls kernel_result_stream_next_batch (src/c_abi/result.rs:217), the reader issues chunk-fetch RPCs against a session whose delete has already been initiated, likely surfacing server errors. Before this PR the delete deferred until the last Arc dropped, so a metadata stream obtained before close stayed valid until its own close; the eager-delete change alters that. The header documents only that the session handle becomes invalid after close (src/c_abi/session.rs:530-534) — it says nothing about independently-held result-stream handles, so the required ordering is unspecified. |
Addresses gopalldb's MINOR on #160. Now that kernel_session_close eagerly initiates DeleteSession, an outstanding metadata result stream (which holds its own Arc<SessionInner> and stays drivable) driven after close would issue chunk-fetch RPCs against an already-deleting session and surface server errors. The header only stated the session handle becomes invalid; the required ordering for independently-held handles was unspecified. Document it in databricks_kernel.h and the kernel_session_close doc: close the session LAST — drain/close result streams → executed handles → statements → session. Docs only; no behavior change. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
|
Thanks @gopalldb — addressed in f742ed4. You're right that eager delete-on-close changes the lifetime of an outstanding metadata stream (it holds its own |
Follow-up to #158 (merged), addressing @gopalldb's three post-merge review findings on the v0 C ABI.
[MAJOR] Unbounded metadata buffering → lazy streaming
drain_metadatamaterialized the whole metadata result into aVec<RecordBatch>at construction, justified as "bounded — a handful of batches". That's false forkernel_metadata_list_columnswith a NULL catalog, which becomesSHOW COLUMNS IN ALL CATALOGS— a row per column of every table in every visible catalog. In a large workspace an ODBCgetColumns(null, …)would materialize the entire cross-catalog column inventory at once.The owned result-stream handle now holds the
ResultStreamand drivesnext_batchlazily on the runtime (one batch perkernel_result_stream_next_batch, viablock_on_ffi— the same on-runtime discipline the executed path already uses to avoid driving a CloudFetch reader off a plain C thread).run_metadatanow captures just the schema up front and hands the stream to the handle. Bounded memory, no behavior change for consumers.[MAJOR] Empty-string identifier rejected instead of "unfiltered"
opt_identmapped only a NULL pointer toNone; a non-null empty string becameSome("")→Identifier::new("")→InvalidArgument. ODBC/JDBC drivers commonly pass""(not NULL) to mean "match all", solist_schemas/list_tables/list_columnsrejected a legitimate call. Newopt_filter_strtreats NULL and empty/whitespace-only alike asNone;opt_ident/opt_patternroute through it. Required identifiers (PK/FK table) still correctly reject empty.[MAJOR]
kernel_session_closedidn't initiate DeleteSession when handles outlive the sessionClose dropped one
Arc<SessionInner>;DeleteSessiononly fires fromSessionInner::Drop(last-Arc-drop). A live statement/executed handle holds its own clone, so the delete was deferred until those were released too — contradicting the header's "close initiates the delete" contract and risking the server session lingering to idle-timeout. AddedSessionInner::initiate_delete(idempotent via a compare-and-swap onclosed;Dropnow delegates to it), exposedSession::initiate_delete, and call it fromkernel_session_closeso the delete is initiated immediately regardless of outstanding handles.Docs + tests
databricks_kernel.hand the Rust docs updated to match (metadata NULL/empty semantics; close-initiation contract).opt_filter_str,opt_ident).DELETEwith a statement handle still open.ResultStreamviaMockReader.cargo fmt/clippy --all-targetsclean; 673 lib tests + all integration suites + C smoke pass.The dependent ODBC PR databricks/databricks-odbc#101 will re-pin
KERNEL_REPO_TAGto this PR's merge commit once it lands.This pull request and its description were written by Isaac.