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>
impl<R: ResourceExt> AtomicChunked<R>
Sourcepub fn canonical_path(&self) -> &Path
pub fn canonical_path(&self) -> &Path
Path the resource will land at on a successful commit.
Sourcepub fn open<F>(canonical_path: PathBuf, factory: F) -> StorageResult<Self>
pub fn open<F>(canonical_path: PathBuf, factory: F) -> StorageResult<Self>
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
StorageError::Failed— canonical path has no parent / non-utf8 file name.StorageError::TmpClaimed— tmp path already exists.StorageError::Io/StorageError::Mmap— propagated from the OS or from the supplied factory.
Sourcepub fn passthrough(inner: R, canonical_path: PathBuf) -> Self
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>
impl<R: ResourceExt> Debug for AtomicChunked<R>
Source§impl<R: ResourceExt> Drop for AtomicChunked<R>
impl<R: ResourceExt> Drop for AtomicChunked<R>
Source§impl From<AtomicChunked<Resource<MmapDriver>>> for StorageResource
Available on non-WebAssembly only.
impl From<AtomicChunked<Resource<MmapDriver>>> for StorageResource
Source§fn from(r: AtomicChunked<MmapResource>) -> Self
fn from(r: AtomicChunked<MmapResource>) -> Self
Source§impl<R: ResourceExt> ResourceExt for AtomicChunked<R>
impl<R: ResourceExt> ResourceExt for AtomicChunked<R>
Source§fn commit(&self, final_len: Option<u64>) -> StorageResult<()>
fn commit(&self, final_len: Option<u64>) -> StorageResult<()>
Source§fn contains_range(&self, range: Range<u64>) -> bool
fn contains_range(&self, range: Range<u64>) -> bool
Source§fn reactivate(&self) -> StorageResult<()>
fn reactivate(&self) -> StorageResult<()>
Source§fn read_at(&self, offset: u64, buf: &mut [u8]) -> StorageResult<usize>
fn read_at(&self, offset: u64, buf: &mut [u8]) -> StorageResult<usize>
buf. Read more