tiny.sql.FileSnapshot
Defined in tiny.sql.
API (6)
Actions
Public operations.
copyMarkedPage: Copies pagepage_idintoimageand returns the check mark of the stored image it copied, or null when the snapshot holds no such page.copyPagedigestIdentity: Returns the digest of a stored tree identity read through this snapshot.retain
Fields and members
Public fields and members.
Source
Source: lib/sql/src/file.zig:3288
zig
pub const Snapshot = struct { source: SnapshotSource, view: pager.View, /// Returns the digest of a stored tree identity read through this /// snapshot. A leased durable snapshot asks its database's memo, and any /// other snapshot hashes the state directly. pub fn digestIdentity( self: Snapshot, identity_page: u32, state: *const lattice.State, entries: u64, ) [lattice.digest_size]u8 { std.debug.assert(identity_page != 0); return switch (self.source) { .durable => |durable| if (durable.guard) |guard| guard.database.digest_memo.digest(identity_page, state, entries) else state.digest(entries), .sparse => state.digest(entries), }; } pub fn retain(self: Snapshot) Error!?ReadLease { return switch (self.source) { .durable => |durable| if (durable.guard) |guard| try guard.retain() else null, .sparse => null, }; } pub fn copyPage(self: Snapshot, page_id: u32, image: *[page.size]u8) Error!bool { return try self.copyMarkedPage(page_id, image) != null; } /// Copies page `page_id` into `image` and returns the check mark of the /// stored image it copied, or null when the snapshot holds no such page. pub fn copyMarkedPage(self: Snapshot, page_id: u32, image: *[page.size]u8) Error!?PageMark { const phase = trace.scope("file.snapshot.copy_page"); defer phase.end(); switch (self.source) { .durable => |durable| return try copyDurablePage(durable, self.view, page_id, image), .sparse => |sparse| { const found = try sparse.database.impl().copyPage( sparse.generation, page_id, image, ); return if (found) .none else null; }, } } fn copyDurablePage( durable: DurableSnapshot, view: pager.View, page_id: u32, image: *[page.size]u8, ) Error!?PageMark { if (durable.guard) |guard| { if (!guard.valid()) return error.InvalidReadLease; } if (durable.recovery_required) |required| { if (required.*) return error.RecoveryRequired; } if (page_id == 0) return error.InvalidPageId; if (try durable.pager.markedPageAt(page_id, view)) |stored| { image.* = stored.bytes.*; return .{ .flag = stored.checked }; } if (view.base_generation == 0 or page_id > durable.pager.basePageCount()) return null; const key = ReadCacheKey{ .generation = view.base_generation, .page_id = page_id }; if (durable.read_cache.get(key, image)) { return .{ .flag = durable.read_cache.checkMark(key) }; } const base_file = (durable.base_file orelse return error.InvalidDatabaseFile).*; const n = try base_file.readPositionalAll(durable.io, image[0..], pageOffset(page_id)); if (n != page.size) return error.InvalidDatabaseFile; durable.read_cache.put(key, image) catch |err| switch (err) { error.CacheDisabled => return .none, }; return .{ .flag = durable.read_cache.checkMark(key) }; }};Source: lib/sql/src/root.zig:204
zig
pub const FileSnapshot = file.Snapshot;Audit
| Definitions | 5 |
|---|---|
| Public names | 5 |
| Members | 2 |
| Version | 26.7.0 |
| Revision | daab053ee433 |