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. The same crate re-exports the wider layer (key-value, relational, migrations, compile-time SQL) behind features: seedocs/DESIGN-KINDS.mdandROADMAP.md. The main API is async.
Hello
use persistant::blocking::registry;
use persistant::capability::{CapabilityId, choose::Durability, provider::ProviderNeeds};
use persistant::registry::Endpoint;
fn main() {
let ids = ["kv.get", "kv.put"].map(|s| CapabilityId::new(s).unwrap());
let needs = ProviderNeeds::new(ids.to_vec(), Durability::Volatile); // lost at exit is fine
let kv = registry::open_named("memory", &Endpoint::None, &needs).unwrap(); // None: no path
kv.put("hello", b"world".to_vec(), None).unwrap(); // None: never expires
assert_eq!(kv.get("hello").unwrap(), Some(b"world".to_vec()));
}
It states what the program needs (kv.get, kv.put; Volatile means losing the data at exit is fine), asks the
registry for the backend named memory, and uses it. A backend that cannot give what was asked is refused at the
open, by name. This block is the file examples/hello.rs (shown as plain text because it needs the registry feature, which a doc test of the default build does not have): CI builds and runs that file, and tests/readme_hello.rs
fails if the two differ.
Records and the Store
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. A call made from a worker thread of a blocking Store is refused with
Error::Reentrant rather than waiting on itself; no API of this crate runs your code on a worker, so
this guards an invariant and is not a path you can reach today.
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, taken on the code of commit e734735; the facade and the example are unchanged on 0ceb7b1, the 0.4.1 release). 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. Operations: read, write, delete, atomic replace,stat,listandcreate_if_absent.listis paged and sorted (limit,aftercursor) and emulated: OpenDAL lists directories, so a string prefix is a directory scan plus a filter (memory bounded bylimit, time not).create_if_absentis native or refused: onfsit is refused whenatomic_write_diris set, because OpenDAL's atomic path checks then renames and two creators can both pass. So onfsa program cannot have both atomic replace and exclusive create from OpenDAL 0.59.4: declaring both is refused at open. - 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 (on this OpenDAL Store): migrations for non-SQL stores, lock helpers and expiry helpers.
OpenDAL has no TTL and no locks, so those would be emulated, and the documentation would say what is
emulated and where the limits are. (The kind crates have a process lock, leases and expiry on the key-value
backends; see ROADMAP.md.)
Direction
This crate is the blob and record-by-key part of a wider layer. On 2026-10-11 the scope was widened:
PersistAnt is to be the one persistence layer for every kind of persistence, relational databases
included, organised as one capability vocabulary with a crate per kind. The design, with the evidence
behind it and the decisions still open, is
docs/DESIGN-KINDS.md.
Much of it is built since (key-value and relational kinds, SQLite, PostgreSQL, MySQL and MariaDB, migrations, compile-time SQL; ROADMAP.md says what is and is not); the list under "What it does not do" describes the OpenDAL Store of this crate.
What it does not do
- No SQL, queries, joins or secondary indexes, yet. This crate is blob and record-by-key only.
OpenDAL's
postgresql,sqliteandredisservices are key/value tables, not SQL. Relational support is a separate part of this workspace (persistant-relational,persistant-sqlx), reached through therelationalre-export; theStorehere does not use it. - 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). Theblob.max_value_sizeleaf (0.16.0) is tested on a capped in-memory store;memoryandfsrecord it off as missing. 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. - Atomic multi-key batches (
kv.batch_atomic) are on SQLite, PostgreSQL, MySQL and MariaDB only. A blob store (memoryorfsthroughKvOnBlob) has no multi-key atomicity, soKvOnBlobrefuses them at open and the matrix has nokv.batch_atomic.*rows for it; where an embedded backend must batch atomically, use SQLite. - Erased delete (
blob.delete_erased,kv.delete_erased) says "contents overwritten", not "gone from the disk". Onfsthe file is overwritten with zeros, synced, then unlinked; on SQLitesecure_deleteis turned on for the statement and the write-ahead log is truncated (a value an earlier plainputoverwrote may still sit in free space inside a page). Measured limit (30 records of ~700 bytes, raw-file read-back): after erased deletes of all of them,sqliteandsqlite-fullstill hold some of the forgotten text, stale in-page fragments of earlier writes (left by page splits and rebalancing whilesecure_deletewas off) stay in the file; onlysqlite-secure(secure_deleteon for every connection) holds none, so the matrix recordskv.delete_erasedandtext.index.erasedoff (wrong) on the first two and on on the secure profile. Journaling and copy-on-write file systems, SSD wear levelling, snapshots and backups can keep copies. The memory service and PostgreSQL, MySQL and MariaDB record it off as missing: a deleted tuple stays until vacuum or purge, and the log and backups keep it. Each recorded row was read back from the files with a canary and a known-bad control. For a value an earlier plainputordeleteleft behind on SQLite, open the registry idsqlite-secure(SqliteBackend::open_secure:secure_deleteon for every connection, rollback journal): a plain overwrite or delete then leaves no old bytes in the file (storage.secure_delete, read back from the files). It is not WAL (secure_deletedoes not reach a WAL file's earlier page images), sosqlite-fulldoes not claim it.SqliteBackend::open_secure_walis the opt-in WAL form (not in the registry):secure_deleteplus a truncating checkpoint after every write, so a plain delete leaves no bytes in the-waleither (tested, with the default WAL profile as the control). Cost, measured once on a loaded box: about a third of plain WAL's write rate (bench/secure-wal-cost.txt). A reader holding the log defers the truncation to the next write. - A backend version nobody recorded is refused, not guessed at.
open_namedmatches the recorded rows on the version the opened backend reports at run time: the bundled SQLite of the resolvedlibsqlite3-sys, the resolved OpenDAL, the server's own version for PostgreSQL, MySQL and MariaDB. A newer one is refused at open withunverified(no row)for the needs and a message naming what was opened and the nearest recorded version, until rows for it are recorded. A scheduled job re-resolves the lockfile weekly and records the SQLite rows on Linux, Windows and macOS, so the rows follow the bundled SQLite; between a new SQLite landing and the release that carries its rows, a consumer on a fresh lockfile is refused (pinlibsqlite3-systo a recorded version meanwhile). Server and OpenDAL versions are recorded as tested (matrix/), not as ranges. memorycounts as atomic because a value becomes visible in one map insert on close.
The other kinds (opt-in features)
persistant is one name for several crates (design: docs/DESIGN-KINDS.md). Everything above is
unchanged; these features, all off by default, re-export the rest under one module each:
coreaspersistant::capability: capability ids, the checked-in matrix file and the gate lookup.blobaspersistant::blob: theBlobBackendtrait, a memory reference backend, contract tests.kvaspersistant::kv: theKvBackendtrait, key-value over blob or over a relational database, leases, contract tests.relationalaspersistant::relational: a deliberately small database trait and typed errors.opendal-driveraspersistant::opendal_driver: the blob driver andProcessLock.sqlx-driveraspersistant::sqlx_driver: PostgreSQL over sqlx. Needs Rust 1.94, as does every crate here since 0.5.0 (UniSQL 0.24 is 1.94).
Nothing here is on by derivation: a capability is on for a backend and version only where a
recorded test says so (matrix/*.tsv).
Published versions
Releases are on crates.io, and not every version number was published (0.4.5 to 0.4.7 were not). Check the registry, not this file, before depending on one.
Licence
Licensed under either of MIT or Apache-2.0 at your option.