Skip to documentation
SLOP

tiny.sql.FileTransactionStaging

Reference tiny.sql FileTransactionStaging

Defined in tiny.sql.

API (25)

Actions

Public operations.

Types and contracts

Public types and contracts.

Fields and members

Public fields and members.

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

Source

Source: lib/sql/src/file.zig:3380

zig
pub const TransactionStaging = struct {    pub const storage_alignment: usize = @alignOf(TransactionIndexEntry);    pub const Storage = []align(storage_alignment) u8;    pub const Limits = struct {        frames: usize,    };    pub const Capacity = struct {        frames: usize,        index_slots: usize,        storage_bytes: usize,        pub fn derive(limits: Limits) error{CapacityOverflow}!Capacity {            if (limits.frames > std.math.maxInt(u32)) return error.CapacityOverflow;            const index_slots = std.math.mul(usize, limits.frames, 2) catch return error.CapacityOverflow;            const storage_bytes = std.math.mul(usize, index_slots, @sizeOf(TransactionIndexEntry)) catch return error.CapacityOverflow;            return .{                .frames = limits.frames,                .index_slots = index_slots,                .storage_bytes = storage_bytes,            };        }    };    pub const Exhaustion = error{TransactionTooLarge};    pub const InitError = error{ CapacityOverflow, StorageTooShort };    pub const work_limits: alloc_phase.capacity.WorkLimits = .{        .transition_steps_max = std.math.maxInt(usize),        .cleanup_steps_per_call_max = 0,        .cleanup_calls_at_capacity_max = 0,    };    pub const claim: alloc_phase.capacity.Declaration = .{        .source = .{            .id = "sql.file_transaction_staging",            .kind = .phase_static,            .limit_source = .caller,            .storage = .{                .covered = &.{                    .{                        .id = "exact_dense_page_lookup_index_for_the_borrowed_wal_bd67af59f1b2",                        .lifetime = .steady,                        .detail = "exact dense-page lookup index for the borrowed WAL tail frame bound",                    },                },                .excluded = &.{                    "staged and committed page bytes owned by the phase static WAL writer",                    "database pager frame and page indexes base images read cache and tree roots",                    "file handles persistence effects transaction metadata and trace instrumentation",                },            },            .capacity = .{                .inputs = &.{                    alloc_phase.capacity.bindInput(Limits, "frames", "frames"),                },                .type_selectors = &.{                    alloc_phase.capacity.bindType(TransactionIndexEntry, "transaction_index_entry"),                },                .nodes = &.{                    .{ .input = 0 },                    .{ .scale = .{ .node = 0, .coefficient = .{ .literal = 2 } } },                    .{ .scale = .{ .node = 1, .coefficient = .{ .size_of_concrete_type = 0 } } },                },                .assertions = &.{.{                    .scope = .closure_total,                    .measure = .retained,                    .relation = .exact,                    .expression = 2,                }},            },            .overload = .{                .kind = .reject_before_mutation,                .detail = "a full remaining WAL frame prefix rejects a new page before the reusable lookup index or borrowed WAL tail mutate",            },            .risks = .{                .transitive = .{                    .status = .witnessed,                    .detail = "the transaction stages sorts and transfers page images within WAL owned storage without a second page allocation",                },                .foreign = .{                    .status = .excluded,                    .detail = "WAL file persistence consumes the committed borrowed bytes after the in memory ownership transfer",                },            },            .work = .{                .equation = "begin visits at most twice the admitted frame bound only when the generation wraps; other steady operations take constant steps",            },            .dependencies = &.{"sql.wal_writer"},            .obligations = &.{                .{ .key = "sql_file_transaction_staging_capacity", .role = .capacity_model },                .{ .key = "sql_file_transaction_staging_sealed", .role = .overload },                .{ .key = "sql_file_transaction_staging_work_bound", .role = .work_bound },                .{ .key = "sql_file_transaction_staging_transfer_transitive_risk", .role = .transitive_risk },                .{ .key = "sql_file_transaction_staging_transfer_foreign_risk", .role = .foreign_risk },            },        },        .bindings = .{            .owner = @This(),            .seal = .{                .family = alloc_phase.capacity.selector(@This().activate),                .premise = .{                    .class = .checked_semantic_fact,                    .authority = .checker,                },            },            .teardown = .{                .family = alloc_phase.capacity.selector(@This().deinit),                .premise = .{                    .class = .checked_semantic_fact,                    .authority = .checker,                },            },        },    };    phase: alloc_phase.capacity.Phase,    capacity: Capacity,    storage: Storage,    index: []TransactionIndexEntry,    generation: u32 = 0,    limit_frames: usize = 0,    pages: usize = 0,    active: bool = false,    pub fn init(storage: Storage, limits: Limits) InitError!TransactionStaging {        const capacity = try Capacity.derive(limits);        if (storage.len < capacity.storage_bytes) return error.StorageTooShort;        const borrowed = storage[0..capacity.storage_bytes];        const index = std.mem.bytesAsSlice(TransactionIndexEntry, borrowed);        @memset(index, .{});        return .{            .phase = .initialization,            .capacity = capacity,            .storage = borrowed,            .index = index,        };    }    pub fn activate(self: *TransactionStaging) void {        std.debug.assert(self.phase == .initialization);        std.debug.assert(self.index.len == self.capacity.index_slots);        self.phase = .steady;    }    pub fn deinit(self: *TransactionStaging) Storage {        std.debug.assert(self.phase != .teardown);        std.debug.assert(!self.active);        std.debug.assert(self.storage.len == self.capacity.storage_bytes);        std.debug.assert(self.index.len == self.capacity.index_slots);        std.debug.assert(self.index.ptr == std.mem.bytesAsSlice(            TransactionIndexEntry,            self.storage,        ).ptr);        self.phase = .teardown;        const storage = self.storage;        self.* = undefined;        return storage;    }    pub fn begin(self: *TransactionStaging, frames: usize) void {        std.debug.assert(self.phase == .steady);        std.debug.assert(!self.active);        std.debug.assert(frames <= self.capacity.frames);        self.generation +%= 1;        if (self.generation == 0) {            @memset(self.index, .{});            self.generation = 1;        }        self.limit_frames = frames;        self.pages = 0;        self.active = true;    }    pub fn end(self: *TransactionStaging) void {        std.debug.assert(self.phase == .steady);        std.debug.assert(self.active);        self.limit_frames = 0;        self.pages = 0;        self.active = false;    }    pub fn pageIndex(self: *const TransactionStaging, index: usize) ?usize {        std.debug.assert(self.phase == .steady);        std.debug.assert(self.active);        std.debug.assert(index < self.capacity.index_slots);        const entry = self.index[index];        return if (entry.generation == self.generation) entry.page_index else null;    }    pub fn nextPage(self: *const TransactionStaging) Exhaustion!usize {        std.debug.assert(self.phase == .steady);        std.debug.assert(self.active);        if (self.pages >= self.limit_frames) return error.TransactionTooLarge;        return self.pages;    }    pub fn occupy(self: *TransactionStaging, index: usize, page_index: usize) void {        std.debug.assert(self.phase == .steady);        std.debug.assert(self.active);        std.debug.assert(index < self.capacity.index_slots);        std.debug.assert(self.index[index].generation != self.generation);        std.debug.assert(page_index == self.pages);        std.debug.assert(page_index < self.limit_frames);        self.index[index] = .{            .generation = self.generation,            .page_index = @intCast(page_index),        };        self.pages += 1;    }};

Source: lib/sql/src/root.zig:307

zig
pub const FileTransactionStaging = file.TransactionStaging;
Called byCallsNo direct callsFileDatabaseWorkspace.CapacityderiveFileDatabaseWorkspaceacquireTransactionStagingtest sourcelib.sql.src.filetest: file transaction staging capaci...test sourcelib.sql.src.filetest: file transaction staging is sea...test sourcelib.sql.src.filetest: file transaction staging reject...FileTransactionStaging.Capacityderive
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.sql.src.filetest: file transaction staging bounds...test sourcelib.sql.src.filetest: file transaction staging is sea...test sourcelib.sql.src.filetest: file transaction staging reject...FileTransactionStagingactivate
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsFileDatabasebeginWritetest sourcelib.sql.src.filetest: file transaction staging bounds...test sourcelib.sql.src.filetest: file transaction staging is sea...FileTransactionStagingbegin
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.sql.src.filetest: file transaction staging bounds...test sourcelib.sql.src.filetest: file transaction staging is sea...test sourcelib.sql.src.filetest: file transaction staging reject...FileTransactionStagingdeinit
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsFileDatabasebeginWriteprivate sourcelib.sql.src.file.Transactionclosetest sourcelib.sql.src.filetest: file transaction staging bounds...test sourcelib.sql.src.filetest: file transaction staging is sea...FileTransactionStagingend
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsFileDatabaseWorkspaceacquireTransactionStagingtest sourcelib.sql.src.filetest: file transaction staging bounds...test sourcelib.sql.src.filetest: file transaction staging capaci...test sourcelib.sql.src.filetest: file transaction staging is sea...test sourcelib.sql.src.filetest: file transaction staging reject...FileTransactionStaginginit
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallsNo direct callsFileTransactionputPagetest sourcelib.sql.src.filetest: file transaction staging is sea...FileTransactionStagingnextPage
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsFileTransactionputPagetest sourcelib.sql.src.filetest: file transaction staging is sea...FileTransactionStagingoccupy
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsprivate sourcelib.sql.src.file.TransactionfindSlottest sourcelib.sql.src.filetest: file transaction staging is sea...FileTransactionStagingpageIndex
Static calls · unresolved targets: 0 · external targets: 0.

Audit

Definitions18
Public names18
Members15
Version26.7.0
Revisiondaab053ee433