| Crates.io | btree-store |
| lib.rs | btree-store |
| version | 0.1.1 |
| created_at | 2026-01-16 08:21:31.280649+00 |
| updated_at | 2026-01-18 02:36:47.878774+00 |
| description | A persistent, embedded key-value storage engine in Rust featuring a Copy-On-Write (COW) B-Tree, ACID compliance, and crash safety with multi-bucket support |
| homepage | https://github.com/abbycin/btree-store |
| repository | https://github.com/abbycin/btree-store |
| max_upload_size | |
| id | 2048158 |
| size | 158,527 |
btree_store is a persistent, embedded key-value storage engine written in Rust. It implements a robust Copy-On-Write (COW) B-Tree architecture to ensure data integrity, crash safety, and efficient concurrent access.
exec (read-write) and view (read-only) APIs with automatic commit and rollback.exec_multi for atomic updates across multiple buckets with a single disk sync, significantly reducing I/O overhead..pending log recovery mechanism ensure zero-leak recovery even from torn writes.clone() creates a new handle that shares the same transaction context, optimized for multi-threaded components.Warning: Multi-process concurrent access is NOT supported. Only one process should access the database file at a time.
src/store.rs): Low-level page management, sharded LRU caching with mandatory invalidation on sync, and positional I/O.src/node.rs): 8-byte aligned memory management (AlignedPage), zero-copy serialization, and checksumming.src/lib.rs): Core B+ Tree algorithms and Transactional Snapshot Isolation logic.Add this to your Cargo.toml:
[dependencies]
btree-store = "0.1.1"
use btree_store::{BTree, Error};
fn main() -> Result<(), Error> {
let db = BTree::open("data.db")?;
// Read-Write Transaction
db.exec("users", |txn| {
txn.put(b"id:100", b"Alice")?;
let val = txn.get(b"id:100")?;
assert_eq!(val, b"Alice");
Ok(())
})?;
// Read-Only View
db.view("users", |txn| {
let val = txn.get(b"id:100")?;
println!("User: {:?}", String::from_utf8_lossy(&val));
Ok(())
})?;
// Multi-Bucket Atomic Transaction
db.exec_multi(|multi| {
multi.execute("users", |txn| {
txn.put(b"id:101", b"Bob")
})?;
multi.execute("stats", |txn| {
txn.put(b"total_users", b"2")
})?;
Ok(())
})?;
Ok(())
}
The engine is optimized for high-throughput scenarios:
The project includes a comprehensive suite of integration tests:
smo_stress_test: Structural Modification Operations under heavy load.crash_safety_tests: Verifies data integrity across simulated crashes.concurrency_tests: Parallel readers and writers with auto-refresh validation.leak_safety_tests: Ensures no pages are lost during failed operations.Run tests with:
cargo test
This project is licensed under the MIT License - see the LICENSE file for details.