|
54 | 54 | * compare the two once at load time and refuse to run on a mismatch — |
55 | 55 | * otherwise a layout change (e.g. a reordered `KernelStatusCode`) would be |
56 | 56 | * misread as valid data rather than surfaced as a clean error. The macro is |
57 | | - * bumped in lockstep with the Rust `KERNEL_ABI_VERSION` on any layout or |
58 | | - * semantic change AND on any change to the exported symbol set (a |
59 | | - * consumer built against a header declaring a newer symbol would otherwise |
60 | | - * link an older library missing it and fail only at load/run time). |
| 57 | + * bumped in lockstep with the Rust `KERNEL_ABI_VERSION`. It is a COARSE |
| 58 | + * pre-1.0 handshake, not bumped per PR: while the surface is still being |
| 59 | + * built out, additive symbols land without a bump, and it moves only at a |
| 60 | + * deliberate checkpoint (a layout / semantic change, or a stabilisation |
| 61 | + * milestone). |
61 | 62 | * |
62 | 63 | * ## Lifecycle & threading notes |
63 | 64 | * |
@@ -110,7 +111,7 @@ extern "C" { |
110 | 111 | * load time and refuse to run on a mismatch (see "ABI versioning" above). |
111 | 112 | * Bumped in lockstep with the Rust `KERNEL_ABI_VERSION`. |
112 | 113 | */ |
113 | | -#define DATABRICKS_KERNEL_ABI_VERSION 2 |
| 114 | +#define DATABRICKS_KERNEL_ABI_VERSION 1 |
114 | 115 |
|
115 | 116 | /* Version of the C ABI compiled into the linked library. Infallible and |
116 | 117 | * side-effect-free. */ |
@@ -318,56 +319,42 @@ KernelStatusCode kernel_init_logging(const char* level, const char* file_path); |
318 | 319 | * reaching stderr via kernel_init_logging. |
319 | 320 | * |
320 | 321 | * The callback fires from the kernel's log-drain thread (NOT a query worker), |
321 | | - * so it MUST be thread-safe. It SHOULD NOT unwind: the kernel guards each call |
322 | | - * with catch_unwind (the callback pointer uses Rust's C-unwind ABI), so a |
323 | | - * panicking callback poisons the sink and stops delivering rather than aborting |
324 | | - * the process — but subsequent logs are then silently dropped, so a well-behaved |
325 | | - * callback must still not throw across the boundary. It MUST NOT call back into |
326 | | - * any kernel_* entry point: a reentrant blocking kernel_* call from this thread |
327 | | - * is NOT rejected (that guard only covers calls from a kernel worker) — it would |
328 | | - * stall the drain thread and drop queued logs. `ctx` |
329 | | - * is passed back verbatim on every call and must stay valid for the process |
330 | | - * lifetime. `level` (the callback arg) is 1=ERROR..5=TRACE; `target` and |
331 | | - * `message` are valid only for the duration of the call — copy them out. |
332 | | - * Records are enqueued on a bounded channel and DROPPED on overflow (logs are |
333 | | - * advisory and never back-pressure a kernel hot path); the drop count is |
334 | | - * observable via kernel_logging_stats (exact cumulative count) and a synthetic |
335 | | - * "N dropped" line the drain thread emits through the callback on recovery |
336 | | - * (throttled to at most once per second so it can't amplify a slow callback). |
| 322 | + * so it MUST be thread-safe. It SHOULD NOT unwind: the kernel contains a panic |
| 323 | + * with catch_unwind (the pointer uses Rust's C-unwind ABI) and poisons the sink |
| 324 | + * rather than aborting, but subsequent logs are then dropped. It MUST NOT call |
| 325 | + * back into any kernel_* entry point — a blocking reentrant call would stall the |
| 326 | + * drain thread (that reentrancy guard only covers query workers). `ctx` is |
| 327 | + * passed back verbatim and must stay valid for the process lifetime; `level` is |
| 328 | + * 1=ERROR..5=TRACE; `target` and `message` are valid only for the call — copy |
| 329 | + * them out. Records are enqueued on a bounded channel and DROPPED on overflow |
| 330 | + * (logs never back-pressure a kernel hot path); the drop count is observable via |
| 331 | + * kernel_logging_stats. |
337 | 332 | * |
338 | 333 | * The `level` PARAMETER (OFF/ERROR/WARN/INFO/DEBUG/TRACE, case-insensitive, or |
339 | 334 | * NULL) sets the forward threshold with the SAME precedence as |
340 | | - * kernel_init_logging: an explicit recognised level wins, else RUST_LOG. A host |
341 | | - * that maps its own logger level (Go's DATABRICKS_LOG_LEVEL) passes it here so |
342 | | - * the callback filters on that one knob rather than only RUST_LOG. When neither |
343 | | - * resolves (NULL/unrecognised AND no matching RUST_LOG) the current threshold |
344 | | - * is left UNCHANGED — the warn default on the first call, or the |
345 | | - * previously-set level on a re-registration. |
346 | | - * |
347 | | - * Mutually exclusive with kernel_init_logging: both install the one |
348 | | - * process-global tracing subscriber. kernel_set_log_callback returns Internal |
349 | | - * (with a stored last error) if a global subscriber was already installed, or |
350 | | - * if it won the subscriber but the log-drain thread could not be started (the |
351 | | - * two cases carry distinct error messages); install exactly ONE of the two. |
352 | | - * Passing a NULL `cb` returns InvalidArgument (there is no detach in v0). */ |
| 335 | + * kernel_init_logging: an explicit recognised level wins, else RUST_LOG (so a |
| 336 | + * host maps its own logger level, e.g. Go's DATABRICKS_LOG_LEVEL). When neither |
| 337 | + * resolves, the current threshold is left UNCHANGED — the warn default on the |
| 338 | + * first call, or the previously-set level on a re-registration. |
| 339 | + * |
| 340 | + * Mutually exclusive with kernel_init_logging (both install the one |
| 341 | + * process-global subscriber): returns Internal, with distinct error messages, |
| 342 | + * if a subscriber was already installed or the drain thread could not start — |
| 343 | + * install exactly ONE. A NULL `cb` returns InvalidArgument (no detach in v0). */ |
353 | 344 | typedef void (*kernel_log_callback)(void* ctx, int level, const char* target, |
354 | 345 | const char* message); |
355 | 346 | KernelStatusCode kernel_set_log_callback(kernel_log_callback cb, void* ctx, |
356 | 347 | const char* level); |
357 | 348 |
|
358 | 349 | /* Report the log-callback bridge's health, so a host can distinguish "kernel |
359 | | - * logs are quiet" from "kernel logs are being dropped / the sink died / never |
360 | | - * installed". Writes to each non-NULL out-param (a NULL out-param is skipped): |
| 350 | + * logs are quiet" from "being dropped / sink died / never installed". Writes |
| 351 | + * each non-NULL out-param (a NULL one is skipped): |
361 | 352 | * - `installed`: true iff kernel logs are CURRENTLY delivering — the callback |
362 | | - * won the process-global subscriber AND the sink is not poisoned. A callback |
363 | | - * that unwinds poisons the sink (delivery stops), which reads false here even |
364 | | - * though the subscriber is still installed; registering a new callback clears |
365 | | - * the poison and flips this back to true. |
366 | | - * - `dropped`: cumulative kernel log records dropped AFTER install — because |
367 | | - * the bounded delivery channel was full (slow callback) or the sink was |
368 | | - * poisoned by a callback that unwound. Does NOT count the drain-thread-never- |
369 | | - * started case (a spawn failure leaves no channel to overflow); there |
370 | | - * `installed` reads false and kernel_set_log_callback returned Internal. |
| 353 | + * won the subscriber AND the sink is not poisoned. A callback that unwinds |
| 354 | + * poisons the sink (reads false); registering a new callback clears it. |
| 355 | + * - `dropped`: cumulative records dropped AFTER install (channel full or sink |
| 356 | + * poisoned). Excludes the spawn-failure case (no channel), where `installed` |
| 357 | + * reads false and kernel_set_log_callback returned Internal. |
371 | 358 | * Never fails; safe to poll at any time. */ |
372 | 359 | void kernel_logging_stats(bool* installed, uint64_t* dropped); |
373 | 360 |
|
|
0 commit comments