PersistAnt
A thin persistence layer over Apache OpenDAL, for blobs and records stored by key. Programs declare the storage guarantees they need; PersistAnt refuses a backend that cannot give them, instead of silently doing something weaker.
Status: pre-1.0 (the API may change between minor versions). It has capability declaration with refusal, atomic replace on the
fsandmemorybackends, typed records with schema versions, and in-memory, capability-masking and fault-injecting fakes, and a blocking facade (persistant::blocking) for synchronous code. Migrations, locks and expiry are still to come. The main API is async.
Usage
use ;
use ;
#
# async
Synchronous callers
persistant::blocking::Store has the same operations (open, read, replace, delete, put_record,
get_record) without async. It runs the work on a worker thread of its own with a private runtime, so
it is safe to call from plain code, from inside another tokio runtime of either flavour, and from many
threads. (OpenDAL's own blocking operator needs to be created inside a running runtime and panics when
called from within one, so it is not used.) Inside an async task the call still blocks that task's thread:
use the async Store there.
use ;
let store = open?;
store.replace?;
assert_eq!;
# Ok::
Cost. Each call crosses to the worker and back: about 40 to 60 microseconds on the memory backend
(median, 1 byte to 4 KiB, one Windows 11 machine). On fs the larger cost is OpenDAL's file path: for a
4 KiB value a read took about 1.5 ms against 0.1 ms for std::fs::read, and an atomic replace about 5 ms
against 0.7 ms for a plain, non-atomic std::fs::write (the sync before the rename). For multi-MiB values the
ratio falls to roughly 1.2 to 1.7 times std::fs. cargo run --release --example blocking_cost measures it on
your machine; measure before putting it on a hot path.
Testing your own failure handling
Config::Memory is a fake store. Config::Faulty makes writes fail (or be interrupted half-way) after
a count you choose, and Config::Masked makes a backend report that it lacks some needs, so a test can
show that a program refuses a weaker production backend. Wrappers nest.
Scope
Shipped:
- Capability declaration with refusal at open. A program says what it needs (
Need: read, write, delete, stat, list, create-if-absent, atomic replace, maximum value size). Opening a store on a backend that cannot provide every need returns a typed error naming all that are missing. No silent downgrade. Only read, write, delete and atomic replace have operations so far;stat,list,create-if-absentand the size ceiling are checked at open but not yet usable throughStore. - Atomic replace. OpenDAL's
fsservice writes atomically only whenatomic_write_diris configured; PersistAnt refusesfswithout it when atomic replace is declared, and tests the real service. - Typed records with schema versions, and test fakes: in-memory, capability-masking and fault-injecting.
- A blocking facade for synchronous code.
- OpenDAL types stay out of the public API, so OpenDAL's breaking changes land in this crate.
Not yet: migrations for non-SQL stores, lock helpers and expiry helpers. OpenDAL has no TTL and no locks, so those will be emulated, and the documentation will say what is emulated and where the limits are.
What it does not do
- No SQL, queries, joins or secondary indexes. Relational code stays on sqlx and the database. OpenDAL's
postgresql,sqliteandredisservices are key/value tables, not SQL. - No multi-key transactions. OpenDAL has none, so PersistAnt does not pretend to.
- No OS file locks, directory trees handed to other tools, or memory-mapped model files.
Limits
- Maximum value size cannot be refused on
memoryorfs. OpenDAL reportswrite_total_max_size: Nonefor them, meaning unlimited, not unknown.Need::MaxValueSize(n)is refused only by a backend that advertises a smaller ceiling (for example Cloudflare D1, 1 MB). atomic_write_dirmust be on the same filesystem as the root and outside it. PersistAnt checks that it is set, not where it is.- An abandoned replace leaves its temporary file in
atomic_write_dironfs; the old value is intact but the scratch directory should be swept at startup. Durability across power loss is not claimed: OpenDAL syncs the file, not the parent directory, before the rename. memorycounts as atomic because a value becomes visible in one map insert on close.
Licence
Licensed under either of MIT or Apache-2.0 at your option.