pub struct StorageSnapshotManager { /* private fields */ }Expand description
Copy-on-Write storage snapshot manager.
§Copy-on-Write semantics
When create_snapshot is called,
all pages in the current state are shared with the new snapshot by
incrementing their ref_count. No byte is copied at that point.
The first time write_page is called
on a page that is shared (i.e. ref_count > 1), the old version is
retained for the snapshot(s) that reference it (its ref_count is
decremented) and a fresh copy is created for the current state. This is
the CoW copy event counted in SnapshotStats::cow_copies_made.
Implementations§
Source§impl StorageSnapshotManager
impl StorageSnapshotManager
Sourcepub fn new(config: SnapshotConfig) -> Self
pub fn new(config: SnapshotConfig) -> Self
Create a new manager with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a manager with default configuration.
Sourcepub fn write_page(
&mut self,
page_id: PageId,
data: Vec<u8>,
) -> Result<u64, SnapshotError>
pub fn write_page( &mut self, page_id: PageId, data: Vec<u8>, ) -> Result<u64, SnapshotError>
Write data to page_id in the current state.
If the page is currently shared with any snapshot (ref_count > 1), a
CoW copy is performed:
- The old version’s
ref_countis decremented. - A new page version is inserted.
Returns the new version number.
Sourcepub fn read_page(&self, page_id: PageId) -> Result<&Page, SnapshotError>
pub fn read_page(&self, page_id: PageId) -> Result<&Page, SnapshotError>
Read the current-state page for page_id.
Sourcepub fn read_page_from_snapshot(
&self,
snapshot_id: SnapshotId,
page_id: PageId,
) -> Result<&Page, SnapshotError>
pub fn read_page_from_snapshot( &self, snapshot_id: SnapshotId, page_id: PageId, ) -> Result<&Page, SnapshotError>
Read a page as it existed at the time of snapshot_id.
Sourcepub fn create_snapshot(
&mut self,
name: String,
tags: Vec<String>,
current_ts: u64,
parent: Option<SnapshotId>,
) -> Result<SnapshotId, SnapshotError>
pub fn create_snapshot( &mut self, name: String, tags: Vec<String>, current_ts: u64, parent: Option<SnapshotId>, ) -> Result<SnapshotId, SnapshotError>
Freeze the current page set into a new snapshot.
All pages in the current state are shared with the new snapshot (their
ref_count is incremented). No data is copied.
§Parameters
name— human-readable label for the snapshot.tags— arbitrary string tags.current_ts— caller-supplied timestamp (e.g. Unix seconds).parent— optional parent snapshot id for hierarchical chains.
Sourcepub fn delete_snapshot(&mut self, id: SnapshotId) -> Result<(), SnapshotError>
pub fn delete_snapshot(&mut self, id: SnapshotId) -> Result<(), SnapshotError>
Delete a snapshot, decrementing ref-counts of all its pages.
If auto_gc is configured, pages that reach ref_count == 0 are
immediately removed.
Sourcepub fn restore_snapshot(&mut self, id: SnapshotId) -> Result<(), SnapshotError>
pub fn restore_snapshot(&mut self, id: SnapshotId) -> Result<(), SnapshotError>
Replace the current state with the contents of snapshot id.
The old current-state pages have their ref_counts decremented; the snapshot pages have their ref_counts incremented (now shared with the new current state).
Sourcepub fn diff_snapshots(
&self,
a: SnapshotId,
b: SnapshotId,
) -> Result<SnapshotDiff, SnapshotError>
pub fn diff_snapshots( &self, a: SnapshotId, b: SnapshotId, ) -> Result<SnapshotDiff, SnapshotError>
Compute the difference between two snapshots a and b.
added_pages— present inbbut not ina.modified_pages— present in both but at different versions.removed_pages— present inabut not inb.size_delta—size(b) − size(a).
Sourcepub fn gc_pages(&mut self) -> usize
pub fn gc_pages(&mut self) -> usize
Remove all page versions whose ref_count has dropped to zero.
Returns the number of pages removed.
Sourcepub fn list_snapshots(&self) -> Vec<&SnapshotMetadata>
pub fn list_snapshots(&self) -> Vec<&SnapshotMetadata>
Return metadata for all snapshots in creation order.
Sourcepub fn verify_snapshot(
&self,
id: SnapshotId,
) -> Result<Vec<PageId>, SnapshotError>
pub fn verify_snapshot( &self, id: SnapshotId, ) -> Result<Vec<PageId>, SnapshotError>
Verify the checksum of every page in snapshot id.
Returns a (possibly empty) list of PageIds whose checksums did not
match, or an error if the snapshot does not exist.
Sourcepub fn stats(&self) -> SnapshotStats
pub fn stats(&self) -> SnapshotStats
Collect aggregate statistics.
Sourcepub fn config(&self) -> &SnapshotConfig
pub fn config(&self) -> &SnapshotConfig
Return a reference to the configuration.
Sourcepub fn snapshot_count(&self) -> usize
pub fn snapshot_count(&self) -> usize
Return the number of snapshots currently held.
Sourcepub fn page_store_size(&self) -> usize
pub fn page_store_size(&self) -> usize
Return the number of page versions in the page store.
Auto Trait Implementations§
impl Freeze for StorageSnapshotManager
impl RefUnwindSafe for StorageSnapshotManager
impl Send for StorageSnapshotManager
impl Sync for StorageSnapshotManager
impl Unpin for StorageSnapshotManager
impl UnsafeUnpin for StorageSnapshotManager
impl UnwindSafe for StorageSnapshotManager
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more