Repository navigation
feat(c-abi): add kernel_abi_version() for dynamic-linking consumers - #285
msrathore-db wants to merge 1 commit into
Conversation
Consumers that load the kernel as a shared library (.so/.dylib/.dll) at run time — the Go SQL driver and ODBC — need to detect an ABI mismatch (a wrong or stale shared library dropped next to the binary) at load rather than crashing on the first mismatched struct/function. A statically-linked consumer is protected by the compiler; a dynamically linked one is not. kernel_abi_version() returns a monotonic C-ABI version (starts at 1, bumped on any breaking C ABI change — added/removed/renumbered function, changed struct layout or signature). It is intentionally NOT the crate semver; it tracks only the C ABI shape. This matters most while the C ABI is pre-1.0, where the header itself states the ABI 'may change freely.' Takes no pointers and reads no shared state, so it is always safe to call immediately after dlopen. Exported in both the cdylib and staticlib; declared in include/databricks_kernel.h next to kernel_init_logging. Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
There was a problem hiding this comment.
Verdict: 2 Low
Looks good — clean, purely-additive C-ABI accessor with correct extern "C"/#[no_mangle] and no unsafe (takes no pointers). Two low-severity notes: the header exposes no compile-time constant for consumers to compare the runtime value against, and no unit test accompanies the new symbol.
| * Bumped on every breaking C ABI change (added/removed/renumbered function, | ||
| * changed struct layout or signature). Not the crate semver — tracks only | ||
| * the C ABI shape. Starts at 1. Takes no pointers; always safe to call. */ | ||
| uint32_t kernel_abi_version(void); |
There was a problem hiding this comment.
🔵 Low — The header declares the runtime accessor kernel_abi_version() but exposes no companion compile-time constant (e.g. #define DATABRICKS_KERNEL_ABI_VERSION 1). The documented usage is to compare the runtime value against "the version it was built against", but a C/ODBC consumer building against this header has nothing in the header to compare against — it must hardcode the literal 1 itself, which is exactly the drift the check is meant to prevent (a stale header would keep comparing against a stale hardcoded constant).
Consider emitting the constant into the header alongside the declaration so consumers can write if (kernel_abi_version() != DATABRICKS_KERNEL_ABI_VERSION) { ... }. The Rust side already has KERNEL_C_ABI_VERSION; keeping the header macro in lockstep with it (the same way the KernelStatusCode enum is kept in lockstep) closes the loop for the header's own consumers.
| /// # Safety | ||
| /// None — takes no pointers and reads no shared state. | ||
| #[no_mangle] | ||
| pub extern "C" fn kernel_abi_version() -> u32 { |
There was a problem hiding this comment.
🔵 Low — No test accompanies the new symbol. A one-line unit test asserting kernel_abi_version() == KERNEL_C_ABI_VERSION (and == 1) is cheap and guards against an accidental value/type regression and confirms the symbol links — mirroring the napi version() test at napi/src/lib.rs:72. Very minor given the function just returns a const, but the repo convention is that new src/ behavior carries coverage.
|
Closing: the Go driver dropped the ABI-version check (databricks/databricks-sql-go#440), so kernel_abi_version() is not needed right now. The per-platform bindings archive is version-pinned via go.mod. Can revisit if a dynamic-linking consumer later needs a load-time ABI guard. |
What
Adds a single C-ABI function,
kernel_abi_version(), to the kernel's C ABI:Exported from both the
cdylibandstaticlib, declared ininclude/databricks_kernel.h. ~35 lines, purely additive — no existing symbol, struct, or signature changes.Why
Consumers that link the kernel from a separately-distributed prebuilt archive — the Go SQL driver (via the new
databricks-sql-kernel-bindingsper-platform Go modules) and eventually the OSS ODBC driver — need to detect an ABI mismatch (a wrong or stale archive) at connect time rather than crashing on the first mismatched struct/function call.kernel_abi_version()is a monotonic C-ABI version (starts at 1, bumped on any breaking C-ABI change — added/removed/renumbered function, changed struct layout/signature). It is intentionally not the crate semver; it tracks only the C-ABI shape. It takes no pointers and reads no shared state, so it's always safe to call immediately after load.Consumer
The Go driver's kernel backend calls it once at
OpenSession(checkKernelABIVersion()), failing with a clear error on mismatch. This is the missing piece that lets the driver ship the kernel as prebuilt per-platform archives (see databricks/databricks-sql-go PR #440 and the databricks-sql-kernel-bindings repo).Testing
Compiles cleanly on latest main (
cargo check --no-default-features --features tls-rustls). The function has been exercised end-to-end: the Go driver links archives built with this symbol and runs real queries (SELECT 1 + full data-type suite) against a live warehouse on all 5 target platforms (darwin arm64/amd64, linux amd64/arm64, windows amd64) — the ABI check returns 1 and connect proceeds.This pull request and its description were written by Isaac.