Skip to main content

FileBackend

Struct FileBackend 

Source
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

Source

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.

Source

pub fn with_include_hidden(self, include: bool) -> Self

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

Source

pub fn dir(&self) -> &Path

Backend root directory.

Source

pub fn include_hidden(&self) -> bool

Whether list() includes dot-prefixed filenames.

Trait Implementations§

Source§

impl Debug for FileBackend

Source§

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

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

impl StorageBackend for FileBackend

Source§

fn name(&self) -> &str

Diagnostic name (e.g. "memory", "file:./checkpoints"). Surfaces in error messages and tier Display impls.
Source§

fn read(&self, key: &str) -> Result<Option<Vec<u8>>, StorageError>

Read raw bytes; returns Ok(None) on miss.
Source§

fn write(&self, key: &str, bytes: &[u8]) -> Result<(), StorageError>

Write raw bytes.
Source§

fn delete(&self, key: &str) -> Result<(), StorageError>

Optional delete-by-key. Default is no-op so append-only or read-only backends can stay quiet.
Source§

fn list(&self, prefix: &str) -> Result<Vec<String>, StorageError>

Enumerate keys matching 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).
Source§

fn flush(&self) -> Result<(), StorageError>

Optional drain hook — adapter authors implement when buffering writes. Default no-op; tier flush() does NOT cascade into this by default (the tier owns its own buffer; backend buffering is a separate concern the backend author opts into).

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