pub struct FileBackend { /* private fields */ }Expand description
Filesystem-backed StorageBackend.
One file per key under dir. Concurrent writers are safe at the
per-key granularity (atomic rename via tempfile); concurrent writers
to the SAME key race in unspecified-but-atomic fashion (last commit wins).
§Filesystem portability
Key→filename encoding preserves ASCII case: Foo and foo encode to
Foo.bin and foo.bin. On case-insensitive filesystems (default macOS
APFS, default Windows NTFS) these collide. graphrefly-internal keys
(tier names, WAL frame paths) are case-consistent by construction, so
the collision is only reachable with adversarial user-supplied keys.
Lift documented in porting-deferred.md “M4.C FileBackend
case-insensitive-filesystem key collision”.
§Example
use std::sync::Arc;
use graphrefly_storage::{file_backend, snapshot_storage, SnapshotStorageOptions};
let backend = file_backend("./checkpoints");
let tier = snapshot_storage(backend, SnapshotStorageOptions::<MyState, _>::default());
tier.save(state).unwrap();Implementations§
Source§impl FileBackend
impl FileBackend
Sourcepub fn new(dir: impl AsRef<Path>) -> Self
pub fn new(dir: impl AsRef<Path>) -> Self
Construct a backend rooted at dir. The directory is created lazily on
first write() — read / list / delete tolerate its absence.
Override whether list() includes filenames beginning with . (D161).
Default false: hidden filenames are skipped. This protects against
in-flight tempfile::NamedTempFile temp files (which are created with
a leading-. prefix) leaking into enumeration results during a
concurrent flush.
Pass true if your application intentionally writes keys whose
percent-encoding produces a leading-. filename and you need them
visible in list().
Whether list() includes dot-prefixed filenames.
Trait Implementations§
Source§impl Debug for FileBackend
impl Debug for FileBackend
Source§impl StorageBackend for FileBackend
impl StorageBackend for FileBackend
Source§fn name(&self) -> &str
fn name(&self) -> &str
"memory", "file:./checkpoints"). Surfaces
in error messages and tier Display impls.Source§fn read(&self, key: &str) -> Result<Option<Vec<u8>>, StorageError>
fn read(&self, key: &str) -> Result<Option<Vec<u8>>, StorageError>
Ok(None) on miss.Source§fn delete(&self, key: &str) -> Result<(), StorageError>
fn delete(&self, key: &str) -> Result<(), StorageError>
Source§fn list(&self, prefix: &str) -> Result<Vec<String>, StorageError>
fn list(&self, prefix: &str) -> Result<Vec<String>, StorageError>
prefix (lex-ASC). Empty prefix enumerates
all keys. Default returns BackendNoListSupport — backends that don’t
support enumeration surface the diagnostic here at first call, NOT at
attach (mirrors TS lazy-throw semantics for list_by_prefix).