Skip to main content

StorageSnapshotManager

Struct StorageSnapshotManager 

Source
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

Source

pub fn new(config: SnapshotConfig) -> Self

Create a new manager with the given configuration.

Source

pub fn with_defaults() -> Self

Create a manager with default configuration.

Source

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_count is decremented.
  • A new page version is inserted.

Returns the new version number.

Source

pub fn read_page(&self, page_id: PageId) -> Result<&Page, SnapshotError>

Read the current-state page for page_id.

Source

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.

Source

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.
Source

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.

Source

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).

Source

pub fn diff_snapshots( &self, a: SnapshotId, b: SnapshotId, ) -> Result<SnapshotDiff, SnapshotError>

Compute the difference between two snapshots a and b.

  • added_pages — present in b but not in a.
  • modified_pages — present in both but at different versions.
  • removed_pages — present in a but not in b.
  • size_deltasize(b) − size(a).
Source

pub fn gc_pages(&mut self) -> usize

Remove all page versions whose ref_count has dropped to zero.

Returns the number of pages removed.

Source

pub fn list_snapshots(&self) -> Vec<&SnapshotMetadata>

Return metadata for all snapshots in creation order.

Source

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.

Source

pub fn stats(&self) -> SnapshotStats

Collect aggregate statistics.

Source

pub fn config(&self) -> &SnapshotConfig

Return a reference to the configuration.

Source

pub fn snapshot_count(&self) -> usize

Return the number of snapshots currently held.

Source

pub fn page_store_size(&self) -> usize

Return the number of page versions in the page store.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more