Expand description
Regolith: ACID, performance oriented, embedded key-value database engine for edge systems.
Regolith provides a fast, embedded key-value store with:
- Read committed, snapshot isolation, or serializable per transaction, via MVCC sequence numbers
- Lock-free transactions whose reads and writes take
&self, so one transaction can be shared across threads without a lock - Crash recovery via write-ahead logging (WAL)
- LZ4 compression for data blocks
- Bloom filters for fast negative lookups
- Level-based compaction on a dedicated OS thread
- Lock-free reads via an arena-backed skip list memtable
- Zero-copy reads via
DbSlice, which borrows the bytes the database already holds
§Quick Start
use regolith::{Db, Options};
let db = Db::open("/tmp/my_db", Options::default()).unwrap();
// Write
db.put(b"hello", b"world").unwrap();
// Read
let value = db.get(b"hello").unwrap();
assert_eq!(value, Some(b"world".to_vec()));
// Delete
db.delete(b"hello").unwrap();
// Batch write
let mut batch = regolith::WriteBatch::new();
batch.put(b"key1", b"val1");
batch.put(b"key2", b"val2");
batch.delete(b"key3");
db.write(batch).unwrap();
// Snapshot reads
let snap = db.snapshot();
db.put(b"key1", b"val_new").unwrap();
// Snapshot still sees old value
assert_eq!(snap.get(b"key1").unwrap(), Some(b"val1".to_vec()));Re-exports§
pub use env::Capabilities;pub use env::Env;pub use env::MemEnv;pub use env::StdEnv;
Modules§
- env
- The host platform, behind one trait.
Structs§
- Arena
Profile - How a memtable arena sizes its chunks.
- Backup
Engine - Content-addressed backup repository for one or more databases.
- Backup
Id - Opaque identifier for a single backup generation. Monotonically increasing within a backup directory.
- Backup
Info - High-level summary of a backup returned from
BackupEngine::list_backups. - CfIter
- Streaming iterator scoped to a single column family. Wraps a
regular
Iterand bounds the scan to the CF’s prefix range, stripping the 4-byte CF prefix from every key before returning it. Created byDb::iter_cf/Snapshot::iter_cf. - Checkpoint
- A handle to a
Dbprepared for checkpointing. The handle itself captures no engine state - the actual flush, version snapshot, and filesystem work all happen insideCheckpoint::createunder a single held compaction lock, so dropping theCheckpointwithout callingcreateis free. - Column
Family Handle - A handle to a column family. Cheap to clone; carries only the CF’s name and numeric id. Handles become invalid after their CF is dropped; result-returning CF operations reject stale handles.
- Compaction
JobInfo - Information about a compaction job, passed to
EventListener::on_compaction_beginandEventListener::on_compaction_completed. - Db
- A key-value database backed by an LSM-tree.
- DbSlice
- A borrowed, refcounted view of a value.
- DbWith
Ttl - A
Dbwrapper that attaches a wall-clock TTL to every written value. Entries whose embedded timestamp is older thanttl_secondsread asNoneand are physically reclaimed at the next compaction. - Entries
- Ordered entries drained from a cursor, from its current position on.
- External
File Ingestion Info - Information about a file ingested via
crate::Db::ingest_external_files. - Fifo
Compaction Options - Tunables for
CompactionStyle::Fifo. Ignored whenOptions::compaction_styleisCompactionStyle::Level. - Fixed
Length Prefix - A
PrefixExtractorthat takes the firstNbytes of every key. Keys shorter thanNcontribute no prefix. - Flush
JobInfo - Information about a flush that just completed.
- Histogram
Snapshot - Immutable snapshot of a single histogram’s state. Callers read this to export to their metrics pipeline or assert in tests.
- Ingest
Options - Options controlling how
crate::Db::ingest_external_filesmoves files into the database. - Iter
- Streaming iterator over a consistent view of the database.
- MemTable
Stats - Approximate memtable stats returned by
Db::get_approximate_memtable_stats.countis the number of raw entries (including every version and every tombstone) for user keys in the queried range;sizeis the sum ofinternal_key.len() + value.len()over those entries. Both values are exact with respect to the current active memtable - this method walks the skip list. - Optimistic
Transaction Db - Optimistic-concurrency-control wrapper over a
Db. - Options
- Configuration options for a regolith database.
- Owned
Snapshot Iter - Owned streaming iterator over a
Snapshotin the default column family. This is useful for adapters that need to return an owned iterator object without tying the type to a borrowed snapshot lifetime. - Owned
Transaction - A
Transactionbundled with an owning handle on the database that began it. - Perf
Context - Thread-local performance counters. See the module docs for the usage pattern; every accessor is a static function so callers never need a live reference.
- Perf
Context Snapshot - Immutable snapshot of the current thread’s perf counters.
Returned by
PerfContext::captureso callers can inspect fields without holding the live thread-local borrow. - Range
- A half-open key range
[start, end)passed to the approximate-size APIs. Borrowed; cheap to construct inline. - Scan
Page - One bounded page of ordered scan results.
- Scan
Stream - A lazy, bounded scan over a key range.
- Snapshot
- A point-in-time snapshot for consistent reads.
- SstFile
Meta - Summary of a finished ingest file, returned by
SstFileWriter::finish. - SstFile
Writer - Writes a standalone SSTable file that a running
crate::Dbcan bulk-ingest viacrate::Db::ingest_external_files. - Statistics
- Engine-wide counters and histograms. Constructed by the
caller and passed to
crate::Options::statistics. The engine clones theArcinto the paths it wants to instrument and updates it via lock-free atomic adds (tickers) or short mutex sections (histograms). - Stream
Options - How a
StreamingWriterbuffers. - Streaming
Writer - A write stream that bounds its own memory.
- Table
File Creation Info - Information about a freshly-created SSTable file. Fires for
both flush output and compaction output, distinguished by
TableFileCreationReason. - Table
File Deletion Info - Information about an SSTable file that was just unlinked from
disk. Fires after compaction has committed the version edit
that removed the file from the live set and the physical
unlink(2)has succeeded. - Tailing
Iter - Forward-only tailing iterator. See the module docs.
- Token
Bucket Rate Limiter - Default rate-limiter implementation: a single token bucket refilled
at
bytes_per_secondbytes/sec with a burst capacity ofburst_bytes. - Transaction
- An in-flight transaction. Created by
OptimisticTransactionDb::begin_transactionorTransactionDb::begin_transactionand resolved byTransaction::commitorTransaction::rollback. - Transaction
Db - Pessimistic-concurrency-control wrapper over a
Db. - TtlCompaction
Filter - Compaction filter that drops every point entry whose embedded
Unix timestamp is older than
ttl_secondsat compaction time. - TxnScan
Stream - A transaction’s view of a key range, streamed.
- Universal
Compaction Options - Tunables for
CompactionStyle::Universal. Ignored when the style is notCompactionStyle::Universal. - WalFull
Info - Information about a full WAL. The struct is declared so that listener implementations can target a common shape across storage backends; regolith itself never fires this callback, because the engine rotates the WAL alongside every memtable and there is no separate “WAL-full” condition.
- Write
Batch - A batch of write operations to apply atomically.
- Write
Options - Per-call knobs for point and batch writes. Overrides the database-
global
Options::durabilityon a single operation so callers can opt a critical write into synchronous fsync, or opt a bulk-load phase out of the WAL, without flipping the whole database.
Enums§
- Background
Error Reason - Reason passed to
EventListener::on_background_error. - Compaction
Decision - Decision returned by a
CompactionFilterfor each entry it sees. - Compaction
Style - Compaction strategy used by the background compaction thread.
- Compression
Type - Block compression codec applied to SSTable data blocks.
- Durability
Mode - Controls when data is flushed to disk after a write.
- Error
- Errors returned by regolith operations.
- Histogram
- Enumerated histograms recorded by the engine. Every variant
is backed by one histogram slot in
Statistics, guarded by its own short mutex so recording is non-contending across histograms. - Isolation
Level - How much a transaction is protected against concurrent commits.
- Perf
Level - Granularity of
PerfContextmeasurement. Higher levels produce more detail at the cost of more work per instrumentation site. - Priority
- Priority of a rate-limited I/O request. High-priority waiters are always served before low-priority waiters; within a priority class waiters are served in FIFO order.
- Scan
Direction - Which way a scan walks its range.
- Table
File Creation Reason - Why the flush / compaction path chose to produce a file, used
by
TableFileCreationInfo::reason. - Ticker
- Enumerated counters incremented by the engine. Every variant
is backed by one
AtomicU64slot inStatistics; looking up a ticker isO(1)and thread-safe. - Transaction
Error - Reasons a transaction can fail to commit. Not a variant of
crate::Error: a conflict is a retry-able business outcome, distinct from an I/O failure.
Constants§
- DEFAULT_
CF_ NAME - Name of the default column family.
- DEFAULT_
MAX_ BACKGROUND_ COMPACTIONS - Default value of
Options::max_background_compactions: one background worker, or none on a target that has no threads. - DEFAULT_
MAX_ KEY_ SIZE - Default maximum user-key length accepted by write APIs: 8 MiB.
- DEFAULT_
MAX_ VALUE_ SIZE - Default maximum value / merge-operand length accepted by write APIs: 64 MiB.
- DEFAULT_
TRANSACTION_ KEYS_ INLINE - Default
Options::transaction_keys_inline. - MAX_
BLOCK_ CACHE_ SHARD_ BITS - Highest supported block-cache shard exponent.
- MAX_
BLOOM_ BITS_ PER_ KEY - Highest supported Bloom-filter density. Larger values waste space because the hash count is already capped internally.
Traits§
- Compaction
Filter - A user-supplied hook that runs during compaction and can drop or rewrite entries in place. Typical uses: TTL expiration, application- level GC, schema migrations.
- Event
Listener - Trait implemented by callers that want to react to engine
lifecycle events. Registered via
crate::Options::listeners. - Merge
Operator - A user-supplied associative merge operator.
- Prefix
Extractor - Carves a prefix out of a user key so the SSTable bloom filter can answer “does this file contain any key with prefix P?” queries.
- Rate
Limiter - A byte-denominated rate limiter.
Functions§
- strip_
timestamp - Return the raw user value with the trailing TTL suffix removed.
Returns
Noneifstampeddoes not contain a supported suffix. Callers that hold astampedbuffer from a raw read throughDbWithTtl::innercan use this to recover the user payload.