Trine KV
Trine KV is an embedded Rust key-value database for applications that need ordered local storage without running a separate server. It gives simple code a default bucket, and lets larger applications add named buckets with their own prefix, filter, compression, and large-value settings.
The v0.1.0 crate is implemented and verified by the repository test suite,
benchmark harness, and durability notes. To see the main path work end to end:
cargo run --example quickstart
Then read docs/usage.md for the API path and docs/durability.md for persistence guarantees and limits. Release packaging notes live in docs/release.md.
Common Capabilities
- Async-first default-bucket reads and writes with
Db::put,Db::get,Db::range, andDb::prefix. - Explicit sync adapters with
*_syncnames, such asDb::open_sync,db.put_sync,bucket.get_sync, anddb.flush_sync. - Optional named buckets through
db.bucket("users").await?when data needs logical separation or independent tuning. - Atomic write batches across the default bucket and named buckets.
- MVCC snapshots that keep old reads stable while newer writes commit.
- Snapshot-bound point readers that can avoid copying inline table values when callers can work with borrowed bytes.
- Optimistic transactions with point and range conflict checks.
- Ordered range scans and prefix scans.
- Value-lazy range and prefix scans for large-value workloads that need keys before reading blob bytes.
- Persistent mode with WAL replay, manifest recovery, directory locking, safe native defaults, background maintenance, backpressure, flush, compaction, and read-only open.
- Explicit in-memory mode for tests, examples, and short-lived data that should
disappear when the
Dbis dropped. - Async open/read/write/scan/transaction/maintenance entry points for hosts that need to drive storage cooperatively. Native async persistent APIs enter storage waits through Trine's storage boundary and use runtime task boundaries for synchronous maintenance/WAL internals.
- Block-based SSTables with partitioned index/filter blocks, data-block hash lookup for point reads, high-priority metadata caching, compression, and linear/binary/auto index seek policies.
- Large values can be separated into Titan-like blob files with
BlobIndexrecords in SSTables. - Automatic blob Level Merge can rewrite retained large values into output blob files during compaction when it improves locality or removes stale blob refs.
- Snapshot-safe blob GC rewrites still-live large values out of stale blob files and delays old-file deletion while a read can still reach them.
- Live stats report table, cache, filter, blob read, blob byte, and blob GC counters.
- Explicit WASI and browser persistent options. WASI uses a host-preopened
filesystem path on WASI targets and supports
Db::openthrough the host storage boundary. Browser persistence uses the async API and the browser persistent backend onwasm32-unknown-unknown.
Install
Published releases use Semantic Versioning. The current release is v0.1.0:
[]
= "0.1"
For local development, depend on a path:
[]
= { = "../trine-kv" }
Common API Example
use ;
async
For the runnable async-first persistent path, use:
cargo run --example quickstart
For tests or short-lived data, opt into memory mode explicitly:
use ;
let db = open.await?;
For the explicit sync-adapter path, use:
cargo run --example sync_quickstart
Common Commands
cargo fmt --check
cargo clippy
cargo test
cargo run --example quickstart
cargo run --example sync_quickstart
cargo run --example user_store
cargo run --example event_index
cargo bench --bench v1_bench
Examples
quickstart: first pass throughDb::open, async writes, lazy scans, transaction commit, maintenance, read-only reopen, and storage runtime stats.sync_quickstart: first pass through the explicit sync adapters, including persistent open, buckets, scans, transactions, flush, reopen, and stats.user_store: wraps Trine KV behind a small repository-style API.event_index: stores event payloads and a secondary account index with one atomic write batch.
Documentation
- Usage guide
- Durability notes
- Release packaging
- v0.1.0 benchmark baseline
- Large-value direct read tuning
- Blob maintenance and lazy value benchmark
Current Boundaries
- Persistent mode uses a single local database directory.
- Native persistent open defaults to
SyncAllfor confirmed writes.Bufferedis an explicit advanced mode for data that can tolerate losing recent writes after a crash or power loss. - WASI and browser persistent backends do not claim
SyncDataorSyncAll. - WASI persistent
Db::openuses the host-preopened filesystem on WASI targets; current WASI file work completes inline and does not advertise platform async I/O. - Browser persistence is async-only: use
Db::openplus async mutation and maintenance methods. Synchronous browser persistent open, mutation, and maintenance*_syncAPIs return typed unsupported errors. - Read-only open is for inspecting a stable directory state;
v0.1.0does not define live multi-process reads against an active writer. - Repair is intentionally narrow and only removes known safe temporary files when explicitly requested.