tiny.glom.SearchStorage
Defined in tiny.glom.
API (23)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
capacityin_usephasepresentation_workspacepresentation_workspace_high_water_bytesquery_workspacequery_workspace_high_water_bytesquery_workspace_used_bytesvalue
Source
Source: tools/glom/src/search/storage.zig:35
zig
pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: capacity_mod.Capacity, value: sql.TableValueStorage, query_workspace: []u8, presentation_workspace: []u8, in_use: bool = false, query_workspace_used_bytes: usize = 0, query_workspace_high_water_bytes: usize = 0, presentation_workspace_high_water_bytes: usize = 0, pub const Limits: type = capacity_mod.Limits; pub const Capacity: type = capacity_mod.Capacity; pub const Exhaustion: type = @import("storage.zig").Exhaustion; pub const InitError: type = sql.TableValueStorage.InitError || capacity_mod.DeriveError; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "glom.search_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "one_reusable_encoded_glom_document_row_selected_by_25ef94074221", .lifetime = .steady, .detail = "one reusable encoded Glom document row selected by a native search hit", }, .{ .id = "one_synchronous_sql_query_parse_ranking_snippet_res_bea48b4237d8", .lifetime = .steady, .detail = "one synchronous SQL query parse ranking snippet result and page workspace", }, .{ .id = "one_result_dependent_json_full_or_table_presentatio_d1b34987da91", .lifetime = .steady, .detail = "one result-dependent JSON full or table presentation workspace selected by the command", }, }, .excluded = &.{ "context document loading and context row storage", "database WAL pager read cache file handles operating-system page cache and trace instrumentation", "search-index corruption recovery search reference persistence checkpoint effects terminal writes and error diagnostics", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "document_value_bytes", "document_value_bytes"), alloc_phase.capacity.bindInput(Limits, "query_workspace_bytes", "query_workspace_bytes"), alloc_phase.capacity.bindInput(Limits, "presentation_workspace_bytes", "presentation_workspace_bytes"), }, .type_selectors = &.{}, .nodes = &.{ .{ .input = 0 }, .{ .input = 1 }, .{ .input = 2 }, .{ .add = .{ .left = 0, .right = 1 } }, .{ .add = .{ .left = 3, .right = 2 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 4, }}, }, .overload = .{ .kind = .terminal, .detail = "an oversized document or exhausted query or presentation region terminates the finite request before publication and release restores both workspaces", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "query preparation ranking candidate materialization snippets result placement and presentation use only the three sealed regions", }, .foreign = .{ .status = .excluded, .detail = "database file reads and operating-system cache state remain outside Glom search storage", }, }, .dependencies = &.{"sql.table_value_storage"}, .obligations = &.{ .{ .key = "glom_search_storage_capacity", .role = .capacity_model }, .{ .key = "glom_search_storage_boundary", .role = .overload }, .{ .key = "glom_search_storage_sealed", .role = .transitive_risk }, .{ .key = "glom_search_storage_workspace_boundary", .role = .overload }, .{ .key = "glom_search_storage_oom_retry", .role = .overload }, .{ .key = "glom_search_storage_semantics", .role = .foreign_risk }, .{ .key = "glom_search_storage_root", .role = .custom }, }, }, .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, }, }, }, }; pub fn init(allocator: std.mem.Allocator, limits: Limits) InitError!Storage { const capacity = try Capacity.derive(limits); const query_workspace = if (capacity.query_workspace_bytes == 0) @as([]u8, &.{}) else try allocator.alloc(u8, capacity.query_workspace_bytes); errdefer if (query_workspace.len != 0) allocator.free(query_workspace); const presentation_workspace = if (capacity.presentation_workspace_bytes == 0) @as([]u8, &.{}) else try allocator.alloc(u8, capacity.presentation_workspace_bytes); errdefer if (presentation_workspace.len != 0) allocator.free(presentation_workspace); return .{ .phase = .initialization, .capacity = capacity, .value = try sql.TableValueStorage.init(allocator, .{ .max_value_bytes = capacity.document_value_bytes, }), .query_workspace = query_workspace, .presentation_workspace = presentation_workspace, }; } pub fn activate(self: *Storage) void { std.debug.assert(self.phase == .initialization); self.value.activate(); self.phase = .steady; } pub fn get( self: *Storage, table: *const sql.RowIdTable, rowid: i64, ) !?[]const u8 { std.debug.assert(self.phase == .steady); return self.value.get(table, rowid) catch |err| switch (err) { error.ValueCapacityExceeded => error.SearchRowCapacityExceeded, else => err, }; } pub fn preflight( self: *const Storage, document_value_bytes: usize, query_workspace_bytes: usize, presentation_workspace_bytes: usize, ) Storage.Exhaustion!void { std.debug.assert(self.phase == .steady); if (self.in_use) return error.SearchStorageInUse; if (document_value_bytes > self.capacity.document_value_bytes) { return error.SearchRowCapacityExceeded; } if (query_workspace_bytes > self.capacity.query_workspace_bytes) { return error.SearchQueryCapacityExceeded; } if (presentation_workspace_bytes > self.capacity.presentation_workspace_bytes) { return error.SearchPresentationCapacityExceeded; } } pub fn execute( self: *Storage, database: anytype, query: []const u8, filters: data.SearchFilters, comptime execute_fn: anytype, ) anyerror!data.SearchPage { std.debug.assert(self.phase == .steady); if (self.in_use) return error.SearchStorageInUse; self.in_use = true; var fixed = alloc_fixed.Tracked.init(self.query_workspace); errdefer { const workspace_status = fixed.status(); self.query_workspace_used_bytes = workspace_status.used_bytes; self.query_workspace_high_water_bytes = @max( self.query_workspace_high_water_bytes, workspace_status.peak_bytes, ); self.release(); } const page = execute_fn( database, fixed.allocator(), self, query, filters, ) catch |err| switch (err) { error.OutOfMemory => return error.SearchQueryCapacityExceeded, else => return err, }; const workspace_status = fixed.status(); self.query_workspace_used_bytes = workspace_status.used_bytes; self.query_workspace_high_water_bytes = @max( self.query_workspace_high_water_bytes, workspace_status.peak_bytes, ); return page; } pub fn complete( self: *Storage, context: anytype, comptime complete_fn: anytype, ) anyerror!Completion { std.debug.assert(self.phase == .steady); std.debug.assert(self.in_use); var fixed = alloc_fixed.Tracked.init(self.presentation_workspace); defer { const workspace_status = fixed.status(); self.presentation_workspace_high_water_bytes = @max( self.presentation_workspace_high_water_bytes, workspace_status.peak_bytes, ); } var completion = complete_fn(fixed.allocator(), context) catch |err| switch (err) { error.OutOfMemory => return error.SearchPresentationCapacityExceeded, else => return err, }; const workspace_status = fixed.status(); completion.render_budget_bytes = self.capacity.presentation_workspace_bytes; completion.render_high_water_bytes = workspace_status.peak_bytes; return completion; } pub fn release(self: *Storage) void { std.debug.assert(self.phase == .steady); std.debug.assert(self.in_use); self.query_workspace_high_water_bytes = @max( self.query_workspace_high_water_bytes, self.query_workspace_used_bytes, ); self.query_workspace_used_bytes = 0; self.in_use = false; } pub fn status(self: *const Storage) Status { return .{ .phase = self.phase, .document_value_bytes = self.capacity.document_value_bytes, .query_workspace_bytes = self.capacity.query_workspace_bytes, .presentation_workspace_bytes = self.capacity.presentation_workspace_bytes, .storage_bytes = self.capacity.storage_bytes, .storage_pointer = @intFromPtr(self.value.bytes.ptr), .query_workspace_pointer = @intFromPtr(self.query_workspace.ptr), .presentation_workspace_pointer = @intFromPtr(self.presentation_workspace.ptr), .query_workspace_high_water_bytes = self.query_workspace_high_water_bytes, .presentation_workspace_high_water_bytes = self.presentation_workspace_high_water_bytes, .in_use = self.in_use, }; } pub fn deinit(self: *Storage, allocator: std.mem.Allocator) void { std.debug.assert(self.phase != .teardown); std.debug.assert(!self.in_use); self.phase = .teardown; self.value.deinit(allocator); if (self.presentation_workspace.len != 0) allocator.free(self.presentation_workspace); if (self.query_workspace.len != 0) allocator.free(self.query_workspace); self.* = undefined; }};Source: tools/glom/src/root.zig:30
zig
pub const SearchStorage = search.Storage;Also reachable as
Audit
| Definitions | 14 |
|---|---|
| Public names | 28 |
| Members | 9 |
| Version | 26.7.0 |
| Revision | daab053ee433 |