Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
eb55554
feat(c-abi): cooperative cancel token for blocking calls
mani-mathur-arch Jul 16, 2026
b55cd9f
feat(c-abi): ABI-version handshake, blocking close, mTLS + CloudFetch…
mani-mathur-arch Jul 16, 2026
72741db
test(c-abi): assert kernel_abi_version matches header macro in C smoke
mani-mathur-arch Jul 17, 2026
fa7962c
feat(c-abi): reverse-call log callback for C-ABI consumers
mani-mathur-arch Jul 16, 2026
714a54d
fix(c-abi): mirror EnvFilter specificity in log-callback level resolver
mani-mathur-arch Jul 17, 2026
72f8159
test(c-abi): tighten log-callback tests; make bridge filter event-only
mani-mathur-arch Jul 18, 2026
d7868ec
fix(c-abi): harden log-callback install ordering, poisoning, and RUST…
mani-mathur-arch Jul 18, 2026
d86c26d
fix(c-abi): per-target RUST_LOG filtering + retryable install for log…
mani-mathur-arch Jul 18, 2026
3f779d1
fix(c-abi): tighten log-callback target routing, RUST_LOG parsing, in…
mani-mathur-arch Jul 18, 2026
95c0c62
fix(c-abi): bump ABI version for log-callback symbols; tighten direct…
mani-mathur-arch Jul 18, 2026
f0465b1
refactor(c-abi): simplify log-callback level filtering and trim docs
mani-mathur-arch Jul 19, 2026
f952044
fix(c-abi): address code-review findings on log-callback + cancel sur…
mani-mathur-arch Jul 19, 2026
c19e5d1
feat(c-abi): add kernel_session_close_blocking_cancellable (F3) + doc…
mani-mathur-arch Jul 19, 2026
12919b3
refactor(c-abi): drop deferred surface, keep mTLS + ABI-version
mani-mathur-arch Jul 20, 2026
d1802db
refactor(c-abi): inline block_on_ffi, drop now-orphaned ffi_prepare_r…
mani-mathur-arch Jul 20, 2026
760625b
Merge origin/main into mani/c-abi-log-callback
mani-mathur-arch Jul 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ changes go in their respective binding's NEXT_CHANGELOG.
value is ignored (default preserved) with a warning rather than failing session
creation. The key is client-only — it is consumed before session creation and never
reaches the SEA wire. Benefits ODBC too.
- C ABI: `kernel_abi_version()` + the `DATABRICKS_KERNEL_ABI_VERSION` header
macro — a consumer that links a prebuilt library can compare the two once at
load time and refuse to run on a mismatch, guarding against a stale
header/`.a` layout drift. Bumped in lockstep on any layout/meaning change.
- C ABI: `kernel_session_config_set_tls_client_certificate()` — expose the
crate's existing mTLS client cert/key (`TlsConfig::client_cert_pem` /
`client_key_pem`) over the C ABI as a single paired setter. Both halves
required together (cert-without-key is unrepresentable); the private key is
never logged.

### Updated

Expand Down
40 changes: 40 additions & 0 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@
* out exactly as declared here; copy its fields out before the next
* `kernel_*` call on the thread.
*
* Because there is no promise through v0.x, a consumer that links a
* prebuilt library can drift from the header it compiled against (a stale
* header vs a newer `.a`, or vice versa). The `DATABRICKS_KERNEL_ABI_VERSION`
* macro below is the version this header describes; `kernel_abi_version()`
* returns the version compiled into the linked library. A consumer should
* compare the two once at load time and refuse to run on a mismatch —
* otherwise a layout change (e.g. a reordered `KernelStatusCode`) would be
* misread as valid data rather than surfaced as a clean error. The macro is
* bumped in lockstep with the Rust `KERNEL_ABI_VERSION`. It is a COARSE
* pre-1.0 handshake, not bumped per PR: while the surface is still being
* built out, additive symbols land without a bump, and it moves only at a
* deliberate checkpoint (a layout / semantic change, or a stabilisation
* milestone).
*
* ## Lifecycle & threading notes
*
* - **Re-execution invalidates prior handles.** `kernel_statement_execute`
Expand Down Expand Up @@ -90,6 +104,19 @@
extern "C" {
#endif

/* ─── ABI version ─────────────────────────────────────────────────────
*
* The C-ABI version this header describes. `kernel_abi_version()` returns
* the version compiled into the linked library; compare the two once at
* load time and refuse to run on a mismatch (see "ABI versioning" above).
* Bumped in lockstep with the Rust `KERNEL_ABI_VERSION`.
*/
#define DATABRICKS_KERNEL_ABI_VERSION 1

/* Version of the C ABI compiled into the linked library. Infallible and
* side-effect-free. */
uint32_t kernel_abi_version(void);

/* ─── Arrow C Data Interface ──────────────────────────────────────────
*
* Mirrors the canonical `ArrowArray` / `ArrowSchema` from the Arrow C
Expand Down Expand Up @@ -338,6 +365,19 @@ KernelStatusCode kernel_session_config_set_retry_config(KernelSessionConfig* con
uint32_t max_retries,
uint64_t overall_timeout_ms);

/* Configure a client certificate + private key for mutual TLS (mTLS).
* BOTH halves are required and passed together: `cert_pem`/`cert_len` is a
* PEM leaf cert optionally followed by its intermediate chain; `key_pem`/
* `key_len` is the matching PEM private key (use PKCS#8 for portability
* across the tls-native and tls-rustls backends). Taking both at once makes
* cert-without-key unrepresentable. A null buffer or zero length for either
* half returns InvalidArgument. The private key is never rendered in logs. */
KernelStatusCode kernel_session_config_set_tls_client_certificate(KernelSessionConfig* config,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

did we add e2e tests for mtls?

@mani-mathur-arch mani-mathur-arch Jul 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

e2e tests are not added as no warehouse accepts these. only unit tests are added

const uint8_t* cert_pem,
size_t cert_len,
const uint8_t* key_pem,
size_t key_len);

/* ─── Session lifecycle ───────────────────────────────────────────────*/

/*
Expand Down
34 changes: 34 additions & 0 deletions src/c_abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,44 @@ impl From<crate::kernel_error::ErrorCode> for KernelStatusCode {
}
}

/// Current C-ABI version. A coarse pre-1.0 handshake, NOT bumped per PR:
/// while the surface is still being built out, additive symbols land without
/// a bump (a consumer that doesn't reference a new symbol is unaffected, and
/// one that does rebuilds against the matching header anyway). Bump it only at
/// a deliberate checkpoint — a struct-layout change ([`KernelStatusCode`],
/// `KernelError`), a change to the meaning of an existing symbol, or a
/// stabilisation milestone — so a consumer compiled against one header can
/// detect a library built against a different one. Kept in lockstep with the
/// `DATABRICKS_KERNEL_ABI_VERSION` macro in `include/databricks_kernel.h` (the
/// C smoke test asserts the two agree). Pure v0.x aid — there is no ABI
/// stability promise until v1.0.
pub const KERNEL_ABI_VERSION: u32 = 1;

/// Report the C-ABI version compiled into this library. A consumer that
/// linked a header declaring `DATABRICKS_KERNEL_ABI_VERSION` should refuse
/// to run against a library whose `kernel_abi_version()` differs, since a
/// mismatch means the `KernelStatusCode` enum / `KernelError` layout it
/// reads may not match what this library writes. Infallible and
/// side-effect-free, so it takes no config and returns the value directly
/// (no `KernelStatusCode` / last-error dance).
#[no_mangle]
pub extern "C" fn kernel_abi_version() -> u32 {
KERNEL_ABI_VERSION
}

#[cfg(test)]
mod tests {
use super::*;

/// The exported `kernel_abi_version()` returns the crate-level
/// `KERNEL_ABI_VERSION` constant, so the two can't drift. (The C side's
/// `DATABRICKS_KERNEL_ABI_VERSION` macro is checked against this in the
/// C-smoke test, closing the Rust↔header loop.)
#[test]
fn abi_version_is_current() {
assert_eq!(kernel_abi_version(), KERNEL_ABI_VERSION);
}

/// `block_on_ffi` must reject a reentrant call (one made from a thread
/// already inside a Tokio runtime) with a typed `Internal` error and a
/// populated last-error, rather than letting `Runtime::block_on` panic
Expand Down
4 changes: 2 additions & 2 deletions src/c_abi/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ pub unsafe extern "C" fn kernel_result_stream_next_batch(
// Owned (metadata): drive the owned ResultStream lazily on the
// runtime, one batch at a time, so an unbounded result streams
// with bounded memory. Running through block_on_ffi keeps the
// (possibly CloudFetch-backed) reader on the tokio reactor
// rather than off a plain C thread.
// (possibly CloudFetch-backed) reader on the tokio reactor rather
// than off a plain C thread.
ResultStreamInner::Owned { stream, .. } => {
match super::block_on_ffi(move || {
let stream: &mut crate::result_stream::ResultStream = stream;
Expand Down
Loading
Loading