Skip to content

Commit fef8758

Browse files
refactor(c-abi): simplify log-callback level filtering and trim docs
Collapse the per-target RUST_LOG EnvFilter machinery to a single resolved level and drop the synthetic drop-notice, keeping the reverse-call bridge's behavior (explicit level > RUST_LOG > warn default; drop count still surfaced via kernel_logging_stats) while removing ~240 lines of accreted complexity: - parse_rust_log now returns one Option<u8> (most-verbose kernel-applicable level); should_emit reads a single atomic LEVEL with no per-event lock. A mixed RUST_LOG resolves to a superset threshold; a host wanting exact per-target control uses kernel_init_logging. Removes DIRECTIVES/RwLock, HAS_DIRECTIVES, MAX_LEVEL, threshold_for_target, resolve_threshold, ResolvedFilter. - drain_loop no longer emits a throttled "N dropped" record through the callback; the exact cumulative count stays available via kernel_logging_stats. Also revert the per-PR ABI-version bump (KERNEL_ABI_VERSION and DATABRICKS_KERNEL_ABI_VERSION back to 1) with a coarse pre-1.0 handshake policy, keeping the C-smoke lockstep assertion; and trim verbose doc/comment blocks across logging.rs and the header. Sink generations and the retryable install are kept. make check green. Co-authored-by: Isaac Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
1 parent a0200c9 commit fef8758

3 files changed

Lines changed: 263 additions & 692 deletions

File tree

‎include/databricks_kernel.h‎

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@
5454
* compare the two once at load time and refuse to run on a mismatch —
5555
* otherwise a layout change (e.g. a reordered `KernelStatusCode`) would be
5656
* 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).
6162
*
6263
* ## Lifecycle & threading notes
6364
*
@@ -110,7 +111,7 @@ extern "C" {
110111
* load time and refuse to run on a mismatch (see "ABI versioning" above).
111112
* Bumped in lockstep with the Rust `KERNEL_ABI_VERSION`.
112113
*/
113-
#define DATABRICKS_KERNEL_ABI_VERSION 2
114+
#define DATABRICKS_KERNEL_ABI_VERSION 1
114115

115116
/* Version of the C ABI compiled into the linked library. Infallible and
116117
* side-effect-free. */
@@ -318,56 +319,42 @@ KernelStatusCode kernel_init_logging(const char* level, const char* file_path);
318319
* reaching stderr via kernel_init_logging.
319320
*
320321
* 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.
337332
*
338333
* The `level` PARAMETER (OFF/ERROR/WARN/INFO/DEBUG/TRACE, case-insensitive, or
339334
* 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). */
353344
typedef void (*kernel_log_callback)(void* ctx, int level, const char* target,
354345
const char* message);
355346
KernelStatusCode kernel_set_log_callback(kernel_log_callback cb, void* ctx,
356347
const char* level);
357348

358349
/* 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):
361352
* - `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.
371358
* Never fails; safe to poll at any time. */
372359
void kernel_logging_stats(bool* installed, uint64_t* dropped);
373360

0 commit comments

Comments
 (0)