Skip to content

Repository files navigation

Crave

An LSM-tree key-value database built on compio, the completion-based async runtime.

Features

  • Async-native: Built entirely on compio's io_uring/IOCP-backed async I/O
  • Two access modes: Embed as a library or run as a standalone TCP server
  • Write-optimized: LSM-tree with WAL, memtable, leveled compaction
  • Point-in-time snapshots: Consistent reads without blocking writes
  • Range scans: Async iterator over key ranges
  • Atomic batches: WriteBatch for multi-key atomic writes

Usage

Embedded library

use crave::{Db, Options, WriteBatch};

#[compio::main]
async fn main() -> Result<(), crave::Error> {
    let db = Db::open("./my-db", Options::default()).await?;

    db.put(b"hello", b"world").await?;

    let mut batch = WriteBatch::new();
    batch.put(b"key1", b"value1");
    batch.delete(b"old-key");
    db.write(batch).await?;

    let value = db.get(b"hello").await?;
    assert_eq!(value.as_deref(), Some(b"world".as_slice()));

    db.close().await?;
    Ok(())
}

Remote access

Server

cargo run --features remote -- serve --bind 127.0.0.1:6380 --data-dir ./crave-data

Client

TODO

Building

# Library only
cargo build

# With standalone server binary
cargo build --features remote

Architecture

graph TD
    subgraph Remote["Standalone Server (feature = remote)"]
        CLI["CLI (clap)"]
        SRV["TCP Server"]
        PROTO["Wire Protocol (deku)"]
        CLI --> SRV --> PROTO
    end

    subgraph API["Public API"]
        OPS["get / put / delete / scan / batch"]
    end

    subgraph Engine["DB Engine"]
        MT["MemTable (skip list)"]
        WAL["WAL"]
        IMM["Immutable MemTable"]
        COMP["Compaction"]
        SSM["SSTable Manager"]
        CACHE["Block Cache (LRU)"]
        MT --> IMM --> SSM
        COMP --> SSM
    end

    subgraph Storage["Storage Layer (compio)"]
        READ["AsyncReadAt / Managed I/O"]
        WRITE["AsyncWriteAt + BufWriter"]
    end

    PROTO --> API
    API --> MT & WAL
    API --> CACHE --> READ
    SSM --> READ & WRITE
    WAL --> WRITE
Loading

License

MIT

About

An LSM-tree key-value database built on compio

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages