Skip to main content

AtomicChunked

Struct AtomicChunked 

Source
pub struct AtomicChunked<R: ResourceExt> { /* private fields */ }
Expand description

Decorator for crash-safe chunked writes.

During the write phase the inner resource is mmapped at <canonical>.tmp. On commit() the data is durably flushed (sync_data), the temp file is atomically renamed to canonical, and the inner is reopened on the canonical path — guaranteeing that any external observer of the canonical path either sees no file or sees the fully durable committed bytes, and that the inner’s internal fs operations all target the file that actually exists on disk.

Implementations§

Source§

impl<R: ResourceExt> AtomicChunked<R>

Source

pub fn canonical_path(&self) -> &Path

Path the resource will land at on a successful commit.

Source

pub fn open<F>(canonical_path: PathBuf, factory: F) -> StorageResult<Self>
where F: Fn(&Path, OpenIntent) -> StorageResult<R> + Send + Sync + 'static,

Open a fresh chunked-atomic resource at canonical_path. The provided factory opens the inner at a given filesystem path; it is called once with the temp path during this constructor and once more with the canonical path after the atomic rename in ResourceExt::commit.

Atomically claims <canonical>.tmp via OpenOptions::create_new — the filesystem rejects the second concurrent open of the same tmp path. Returns StorageError::TmpClaimed if another AssetStore instance (or another process) is already writing the same canonical path; the caller should poll until the holder releases (commit or drop) and either retry or take a passthrough view of the canonical once committed.

Stale temp left from a prior crashed run is not auto-wiped: liveness is signalled by tmp existence alone, and a leftover from a kill -9 would block subsequent opens until cleaned up explicitly. Maintenance task is the caller’s responsibility (a future enhancement may add PID-aware cleanup).

§Errors
Source

pub fn passthrough(inner: R, canonical_path: PathBuf) -> Self

Wrap an already-opened inner with no atomicity (pass-through). Used for memory-backed inners that have no filesystem to protect, or for re-opens of files that are already committed on disk.

Trait Implementations§

Source§

impl<R: ResourceExt> Debug for AtomicChunked<R>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<R: ResourceExt> Drop for AtomicChunked<R>

Source§

fn drop(&mut self)

Clean up the orphaned temp file when a writer is dropped without a successful commit. Best-effort: a kill -9 skips Drop entirely, in which case the next AtomicChunked::open over the same canonical path wipes the stale temp.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl From<AtomicChunked<Resource<MmapDriver>>> for StorageResource

Available on non-WebAssembly only.
Source§

fn from(r: AtomicChunked<MmapResource>) -> Self

Converts to this type from the input type.
Source§

impl<R: ResourceExt> ResourceExt for AtomicChunked<R>

Source§

fn commit(&self, final_len: Option<u64>) -> StorageResult<()>

Mark the resource as fully written. Read more
Source§

fn contains_range(&self, range: Range<u64>) -> bool

Check if the given byte range is fully covered by available data (non-blocking). Read more
Source§

fn fail(&self, reason: String)

Mark the resource as failed.
Source§

fn len(&self) -> Option<u64>

Get the committed length, if known.
Source§

fn next_gap(&self, from: u64, limit: u64) -> Option<Range<u64>>

Find the first gap in available data starting from from, up to limit. Read more
Source§

fn path(&self) -> Option<&Path>

Get the file path, if backed by a file. Read more
Source§

fn reactivate(&self) -> StorageResult<()>

Reactivate a committed resource for continued writing. Read more
Source§

fn read_at(&self, offset: u64, buf: &mut [u8]) -> StorageResult<usize>

Read data at the given offset into buf. Read more
Source§

fn status(&self) -> ResourceStatus

Get resource status.
Source§

fn wait_range(&self, range: Range<u64>) -> StorageResult<WaitOutcome>

Wait until the given byte range is available. Read more
Source§

fn write_at(&self, offset: u64, data: &[u8]) -> StorageResult<()>

Write data at the given offset. Read more
Source§

fn is_empty(&self) -> bool

Returns true if the resource has been committed with zero length.
Source§

fn read_into(&self, buf: &mut Vec<u8>) -> StorageResult<usize>

Read the entire resource contents into a caller-provided buffer. Read more
Source§

fn write_all(&self, data: &[u8]) -> StorageResult<()>

Write entire contents and commit atomically. Read more

Auto Trait Implementations§

§

impl<R> !Freeze for AtomicChunked<R>

§

impl<R> !RefUnwindSafe for AtomicChunked<R>

§

impl<R> Send for AtomicChunked<R>

§

impl<R> Sync for AtomicChunked<R>

§

impl<R> Unpin for AtomicChunked<R>

§

impl<R> UnsafeUnpin for AtomicChunked<R>

§

impl<R> !UnwindSafe for AtomicChunked<R>

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,