Skip to main content

MemoryWriter

Struct MemoryWriter 

Source
pub struct MemoryWriter { /* private fields */ }
Expand description

Memory file writer — wraps an AtomicWriter so the staged file is renamed onto the destination on commit.

Implementations§

Source§

impl MemoryWriter

Source

pub fn open( dest: &Path, ram_size: u64, page_size: u64, ) -> Result<Self, SnapshotError>

Open a memory writer for the destination path.

ram_size is the logical size; for Full snapshots the file ends up exactly this large, for Diff it ends up sparse with the same logical extent. page_size is the memory-file page size — typically the host page (16 KiB on Apple Silicon) so the file aligns with pwrite granularity.

§Errors

As AtomicWriter::open.

Source

pub fn ram_size(&self) -> u64

The on-disk extent the file represents.

Source

pub fn page_size(&self) -> u64

The memory-file page size in bytes.

Source

pub fn write_full<R: PageReader>( &mut self, reader: &R, ) -> Result<(), SnapshotError>

Write a Full dump: every byte of [0, ram_size) from reader is written.

We chunk in page_size units so the writer never holds the whole memory in a buffer; this matches the production path where applevisor::Memory::read is the upstream of read_at.

§Errors

SnapshotError::MemoryIo for any read or write failure.

Source

pub fn write_diff<R: PageReader>( &mut self, reader: &R, dirty: &DirtyBitmap, ) -> Result<u64, SnapshotError>

Write a Diff dump: only the pages in dirty are pwritten at their offsets.

The file’s logical extent ends up at ram_size. Filesystem-level holes will cover the unmodified pages on APFS, HFS+, and exFAT (per § 7 — “sparse file cross-FS”); on NFS we still produce the right bytes, just dense.

dirty must cover the same [ram_start, ram_size) range as the writer, but may have a different page_size: we re-chunk the writes accordingly so the memory file stays at self.page_size granularity even when the bitmap was rebuilt under the adaptive heuristic.

§Errors

SnapshotError::MemoryIo for any read or write failure.

Source

pub fn commit(self) -> Result<(), SnapshotError>

fsync + rename the memory file onto the destination.

§Errors

As AtomicWriter::commit.

Trait Implementations§

Source§

impl Debug for MemoryWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

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<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, 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<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