RoughDB
Embedded key-value storage written in Rust — a port of LevelDB to Rust.
RoughDB is an LSM-tree key-value store with a LevelDB-compatible on-disk format. It supports persistent (WAL + MANIFEST + SSTables) and in-memory operation, multi-level compaction, and bidirectional iteration.
Getting started
Opening a database
use ;
let mut opts = default;
opts.create_if_missing = true;
let db = open?;
Use Db::default() for a lightweight in-memory database (no WAL, no flush):
let db = default;
Basic reads and writes
use ;
// Write
db.put?;
db.delete?;
// Read
match db.get
Atomic batch writes
use ;
let mut batch = new;
batch.put;
batch.put;
batch.delete;
db.write?;
Iterating over keys
Iterators start unpositioned — call seek_to_first, seek_to_last, or
seek before reading.
use ReadOptions;
let mut it = db.new_iterator?;
// Forward
it.seek_to_first;
while it.valid
// Backward
it.seek_to_last;
while it.valid
// Range scan from "b" onward
it.seek;
while it.valid
Snapshots
A snapshot pins the database to a specific point in time; reads through it see only writes that preceded the snapshot.
use ReadOptions;
let snap = db.get_snapshot;
// Reads with this snapshot see the state at the moment it was taken.
let opts = ReadOptions ;
let value = db.get_with_options?;
let mut it = db.new_iterator?;
// Release when no longer needed (allows compaction to reclaim old data).
db.release_snapshot;
Manual compaction
// Compact everything
db.compact_range?;
// Compact a specific key range
db.compact_range?;
Building and testing
Status
RoughDB is in active development. The on-disk format is LevelDB-compatible. The following are not yet implemented:
- Compression (Snappy, Zstd) — all blocks written uncompressed
Db::get_property/Db::get_approximate_sizesDestroyDBLOCKfile (multi-process safety)- Block cache, table cache, Bloom filters
License
Apache License 2.0 — see LICENSE.