Skip to documentation
SLOP

tiny.sql.history.instrumentation

Reference tiny.sql history instrumentation

Defined in history.

API (10)

Actions

Public operations.

Types and contracts

Public types and contracts.

No direct callersNo direct callshistoryinstrumentation
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsNo direct callshistory.instrumentation.Recorderorderedtest sourcelib.sql.src.history.instrumentationtest: replay recorder rejects incompl...history.instrumentation.Recordercomplete
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.sql.src.history.instrumentationtest: replay recorder rejects incompl...history.instrumentation.Recorderinit
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.sql.src.history.instrumentationtest: replay recorder rejects incompl...history.instrumentation.Recordercompletehistory.instrumentation.Recorderreceiptshistory.instrumentation.Recorderordered
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callshistory.instrumentation.Recorderorderedhistory.instrumentation.Recorderreceipts
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.sql.src.history.instrumentationtest: replay recorder rejects incompl...history.instrumentation.Recorderrecord
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsprivate sourcelib.sql.src.history.recoverrecordPhasehistory.instrumentationelapsed
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/sql/src/history/instrumentation.zig

zig
const std = @import("std");pub const Phase = enum {    batch_load,    hash_verification,    index_rebuild,};pub const Receipt = struct {    sequence: usize,    batch: usize,    phase: Phase,    duration_ns: u64,    bytes: usize,    records: usize,};pub const Recorder = struct {    storage: []Receipt,    len: usize = 0,    required: usize = 0,    pub fn init(storage: []Receipt) Recorder {        return .{ .storage = storage };    }    pub fn reset(self: *Recorder) void {        self.len = 0;        self.required = 0;    }    pub fn record(        self: *Recorder,        batch: usize,        phase: Phase,        duration_ns: u64,        bytes: usize,        records: usize,    ) void {        const sequence = self.required;        self.required += 1;        if (self.len == self.storage.len) return;        self.storage[self.len] = .{            .sequence = sequence,            .batch = batch,            .phase = phase,            .duration_ns = duration_ns,            .bytes = bytes,            .records = records,        };        self.len += 1;    }    pub fn receipts(self: *const Recorder) []const Receipt {        return self.storage[0..self.len];    }    pub fn complete(self: *const Recorder) bool {        return self.len != 0 and self.len == self.required;    }    pub fn ordered(self: *const Recorder) bool {        if (!self.complete() or self.len % 3 != 0) return false;        for (self.receipts(), 0..) |receipt, sequence| {            if (receipt.sequence != sequence) return false;            if (receipt.batch != sequence / 3) return false;            const expected: Phase = switch (sequence % 3) {                0 => .batch_load,                1 => .hash_verification,                2 => .index_rebuild,                else => unreachable,            };            if (receipt.phase != expected) return false;        }        return true;    }};pub fn elapsed(start_ns: i128, end_ns: i128) u64 {    if (end_ns <= start_ns) return 0;    return @intCast(@min(        @as(u128, @intCast(end_ns - start_ns)),        std.math.maxInt(u64),    ));}test "replay recorder rejects incomplete storage and preserves phase order" {    var complete_storage: [6]Receipt = undefined;    var complete = Recorder.init(&complete_storage);    inline for (0..2) |batch| {        complete.record(batch, .batch_load, 1, 16, 2);        complete.record(batch, .hash_verification, 2, 16, 2);        complete.record(batch, .index_rebuild, 3, 16, 2);    }    try std.testing.expect(complete.complete());    try std.testing.expect(complete.ordered());    var short_storage: [2]Receipt = undefined;    var short = Recorder.init(&short_storage);    short.record(0, .batch_load, 1, 16, 2);    short.record(0, .hash_verification, 2, 16, 2);    short.record(0, .index_rebuild, 3, 16, 2);    try std.testing.expect(!short.complete());    try std.testing.expect(!short.ordered());}

Source: lib/sql/src/history/root.zig:10

zig
pub const instrumentation = @import("instrumentation.zig");

Audit

Definitions11
Public names11
Members12
Version26.7.0
Revisiondaab053ee433