tiny.sql.Store
Defined in store.
API (13)
Actions
Public operations.
Fields and members
Public fields and members.
Source
Source: lib/sql/src/store.zig:42
zig
pub const Store = struct { allocator: Allocator, versions: std.ArrayList(Version) = .empty, generation: u64 = 0, pub fn init(allocator: Allocator) Store { return .{ .allocator = allocator }; } pub fn deinit(self: *Store) void { for (self.versions.items) |*version| { freeOwned(self.allocator, version.key); if (!version.deleted) freeOwned(self.allocator, version.value); } self.versions.deinit(self.allocator); self.* = .{ .allocator = self.allocator }; } pub fn currentGeneration(self: *const Store) u64 { return self.generation; } pub fn beginRead(self: *const Store) Snapshot { return .{ .store = self, .generation = self.generation }; } pub fn beginWrite(self: *Store) Write { return .{ .store = self, .snapshot_generation = self.generation }; } pub fn get(self: *const Store, key: []const u8) ?[]const u8 { const phase = trace.scope("store.get"); defer phase.end(); return valueFromIndex(self, latestVisibleIndex(self, key, self.generation)); } pub fn getAt(self: *const Store, key: []const u8, generation: u64) ?[]const u8 { return valueFromIndex(self, latestVisibleIndex(self, key, generation)); } pub fn range(self: *const Store, start: ?[]const u8, end: ?[]const u8) Error!Range { return rangeAt(self, start, end, self.generation); } pub fn rangeAt(self: *const Store, start: ?[]const u8, end: ?[]const u8, generation: u64) Error!Range { if (start) |lower| { if (end) |upper| { if (simd.order(Bytes, lower, upper) == .gt) return error.InvalidRange; } } return .{ .store = self, .start = start, .end = end, .generation = generation, .index = if (start) |lower| lowerBoundKey(self.versions.items, lower) else 0, }; } pub fn compact(self: *Store, oldest_visible_generation: u64) void { const phase = trace.scope("store.compact"); defer phase.end(); var read_index: usize = 0; var write_index: usize = 0; while (read_index < self.versions.items.len) { const key = self.versions.items[read_index].key; var group_end = read_index; var has_oldest_version = false; while (group_end < self.versions.items.len and eqlKey(self.versions.items[group_end].key, key)) : (group_end += 1) { const version = self.versions.items[group_end]; if (version.generation == oldest_visible_generation) has_oldest_version = true; } var keep_floor: ?usize = null; var scan = read_index; while (scan < group_end) : (scan += 1) { const version = self.versions.items[scan]; if (version.generation < oldest_visible_generation) { if (keep_floor == null or self.versions.items[keep_floor.?].generation < version.generation) { keep_floor = scan; } } } scan = read_index; while (scan < group_end) : (scan += 1) { const keep = (!has_oldest_version and keep_floor != null and scan == keep_floor.?) or self.versions.items[scan].generation >= oldest_visible_generation; if (keep) { self.versions.items[write_index] = self.versions.items[scan]; write_index += 1; } else { freeOwned(self.allocator, self.versions.items[scan].key); if (!self.versions.items[scan].deleted) freeOwned(self.allocator, self.versions.items[scan].value); } } read_index = group_end; } self.versions.shrinkRetainingCapacity(write_index); }};Source: lib/sql/src/root.zig:51
zig
pub const Store = store.Store;Complete caller list for Store.deinit
9 direct callers.
lib.sql.src.store.test_committed_writes_are_visible_in_key_order[function] — test source atlib/sql/src/store.zig:455in nearest public ownertiny.sql.storelib.sql.src.store.test_compaction_drops_obsolete_floor_when_oldest_generation_is_present[function] — test source atlib/sql/src/store.zig:576in nearest public ownertiny.sql.storelib.sql.src.store.test_compaction_keeps_floor_when_oldest_generation_falls_between_versions[function] — test source atlib/sql/src/store.zig:593in nearest public ownertiny.sql.storelib.sql.src.store.test_delete_creates_a_tombstone_for_new_readers[function] — test source atlib/sql/src/store.zig:485in nearest public ownertiny.sql.storelib.sql.src.store.test_multi_key_commits_preserve_canonical_version_order[function] — test source atlib/sql/src/store.zig:545in nearest public ownertiny.sql.storelib.sql.src.store.test_range_scan_honors_half_open_bounds_and_tombstones[function] — test source atlib/sql/src/store.zig:530in nearest public ownertiny.sql.storelib.sql.src.store.test_snapshots_preserve_old_values_across_later_commits[function] — test source atlib/sql/src/store.zig:473in nearest public ownertiny.sql.storelib.sql.src.store.test_write_transactions_allow_disjoint_commits_from_the_same_snapshot[function] — test source atlib/sql/src/store.zig:512in nearest public ownertiny.sql.storelib.sql.src.store.test_write_transactions_detect_same_key_conflicts[function] — test source atlib/sql/src/store.zig:497in nearest public ownertiny.sql.store
Complete caller list for Store.init
9 direct callers.
lib.sql.src.store.test_committed_writes_are_visible_in_key_order[function] — test source atlib/sql/src/store.zig:455in nearest public ownertiny.sql.storelib.sql.src.store.test_compaction_drops_obsolete_floor_when_oldest_generation_is_present[function] — test source atlib/sql/src/store.zig:576in nearest public ownertiny.sql.storelib.sql.src.store.test_compaction_keeps_floor_when_oldest_generation_falls_between_versions[function] — test source atlib/sql/src/store.zig:593in nearest public ownertiny.sql.storelib.sql.src.store.test_delete_creates_a_tombstone_for_new_readers[function] — test source atlib/sql/src/store.zig:485in nearest public ownertiny.sql.storelib.sql.src.store.test_multi_key_commits_preserve_canonical_version_order[function] — test source atlib/sql/src/store.zig:545in nearest public ownertiny.sql.storelib.sql.src.store.test_range_scan_honors_half_open_bounds_and_tombstones[function] — test source atlib/sql/src/store.zig:530in nearest public ownertiny.sql.storelib.sql.src.store.test_snapshots_preserve_old_values_across_later_commits[function] — test source atlib/sql/src/store.zig:473in nearest public ownertiny.sql.storelib.sql.src.store.test_write_transactions_allow_disjoint_commits_from_the_same_snapshot[function] — test source atlib/sql/src/store.zig:512in nearest public ownertiny.sql.storelib.sql.src.store.test_write_transactions_detect_same_key_conflicts[function] — test source atlib/sql/src/store.zig:497in nearest public ownertiny.sql.store
Audit
| Definitions | 11 |
|---|---|
| Public names | 22 |
| Members | 3 |
| Version | 26.7.0 |
| Revision | daab053ee433 |