nexir-mvcc-core
A standalone, deterministic Multi-Version Concurrency Control (MVCC) core library used by Nexir.
nexir-mvcc-core provides the versioning, intent, guarded-write, batch mutation, and history-retention primitives required to build a transactional key-value storage layer. It is intentionally limited to the MVCC engine. This repository is not the complete Nexir database and does not include networking, command parsing, consensus, durable storage adapters, idempotency caches, query execution, metrics, or operational services.
Key Features
- Strict Separation of Concerns: Core logic runs deterministically in memory. All disk/durable state is managed through a clean
Backendtrait. - Timestamp-Based Ordering: Native support for caller-supplied logical timestamps (
start_ts,commit_ts,read_ts). - Two-Phase Intent Transactions: First-class support for single-key and multi-key intent transactions via
prewrite,commit,abort,prewrite_batch,commit_batch, andabort_batch. - Atomic Batches: Support for multi-key
prewrite_batch,commit_batch, andabort_batchensures all-or-nothing transactional guarantees. - Direct & Guarded Fast Paths:
apply_direct_batchandapply_guarded_batchbypass the intent system for high-performance single-roundtrip writes, complete with Compare-And-Swap (CAS) guard validation. - Incremental GC: Deterministic history retention with
gc_incremental, cursor resumption, and caller-supplied work budgets. - Backend Conformance Suite: Built-in test macros via the
conformancefeature to easily verify that your custom storage layer meets the logical backend contract (note: adapters must still provide their own crash atomicity tests).
Scope and Integration
nexir-mvcc-core sits between an adapter/runtime layer and a durable backend implementation.
- Implement the
Backendtrait for your storage engine or replicated state machine. - Wrap your
Backendin theMvccEngine. - Map external reads, transactions, and conditional writes to the engine methods.
The core intentionally does not own:
- async runtimes or background tasks,
- consensus types,
- durable database bindings,
- command or document parsing,
- idempotency/replay caches,
- production metrics registries.
Adapters own those concerns and must serialize mutation apply for each ordered write domain.
Quick Start
Direct Batch (Single Roundtrip)
use ;
let mut engine = new;
let writes = vec!;
// Apply directly at timestamp 10
engine.apply_direct_batch.unwrap;
let value = engine.read.unwrap;
assert_eq!;
Multi-Key Intent Transaction
use ;
let mut engine = new;
let txn_id = TxnId;
let start_ts = Timestamp;
let writes = vec!;
// Step 1: prewrite all provisional writes.
engine.prewrite_batch.unwrap;
// Step 2: commit and make the transaction visible.
engine.commit_batch.unwrap;
For more advanced use cases, including Read-Modify-Write and Abort idempotency, check the examples/ directory.
Documentation
- Documentation index
- MVCC design
- Adapter contract
- Batch/write-set design
- Conflict semantics
- History retention and GC
- Testing strategy
- Benchmarking
- Contributing
- Security policy
- Changelog
Testing and Conformance
The crate includes an in-memory backend and an extensive suite of property and failure tests.
To verify your own backend implementation, enable the conformance feature in your Cargo.toml:
[]
= { = "0.1", = ["conformance"] }
And run the macro in your tests:
Release Checks
Before publishing or cutting a release, run:
Performance runs are intentionally separate from correctness gates:
License
Dual-licensed under either of:
at your option. See NOTICE for Apache-2.0 attribution notice information.