$ show rosedblabs/rosedb
RoseDB is a lightweight, fast, and reliable key-value storage engine implemented in Go, based on the Bitcask storage model. It provides a simple embedded database library with operations like Put, Get, Delete, batch writes, TTL/expiry, key watching, and merge (compaction). The architecture uses a Write-Ahead Log (WAL) for persistence and an in-memory BTree index for fast lookups. The codebase is well-structured, with clean separation of concerns: the DB layer, index abstraction, record encoding, and utility functions. It demonstrates strong engineering practices including thread safety via sync.RWMutex, object pooling for performance, and a pluggable index interface. The repository includes comprehensive tests, benchmarks, and examples. It is actively maintained with recent commits and a responsive community.
The LLM identified 4 files worth highlighting for reuse:
Implements the Indexer interface using Google's BTree library with full thread safety via sync.RWMutex. Provides ordered iteration (ascend/descend), range queries, and a custom iterator that supports forward/reverse traversal and seek. The implementation is clean, self-contained, and could be extracted as a reusable in-memory BTree index for any Go project needing ordered key-value storage with concurrent access.
Implements a Watcher with a fixed-capacity circular buffer (eventQueue) for buffering key change events. It provides thread-safe push/pop operations and a goroutine that sends events to a channel. The design handles overflow by overwriting oldest events. This is a generic, reusable event buffering pattern that can be extracted for any system requiring a bounded, non-blocking event queue with a consumer goroutine.
Provides efficient binary encoding and decoding of log records using variable-length integers (varint) for compact representation. Includes encodeLogRecord, decodeLogRecord, encodeHintRecord, and decodeHintRecord functions. The encoding is optimized for size and speed, with a fixed header size calculation. These functions are self-contained (depend only on standard library and a buffer pool) and can be reused in any project needing a compact binary record format for key-value pairs with metadata.
Exposes Go's internal runtime memhash function via //go:linkname, providing a fast, hardware-accelerated hash function for byte slices and strings. This is a non-obvious optimization trick that avoids the overhead of standard library hashers. The implementation is minimal and can be directly reused in any Go project requiring a high-performance hash function for in-memory data structures.