22 releases
Uses new Rust 2024
| 0.2.17 | Oct 10, 2025 |
|---|---|
| 0.2.16 | Sep 20, 2025 |
| 0.2.5 | Aug 26, 2025 |
| 0.1.2 | Aug 13, 2025 |
| 0.0.2 | Aug 9, 2025 |
#667 in Database interfaces
444 downloads per month
Used in 14 crates
(via vecdb)
45KB
1K
SLoC
seqdb
A K.I.S.S. (Keep It Simple, Stupid) sequential storage engine that provides memory-mapped file-based storage with dynamic region management.
What is seqdb?
seqdb is a lightweight storage engine designed for applications that need to store and retrieve data in named regions on disk. It provides:
- Memory-mapped file access for fast I/O operations
- Dynamic region management with automatic resizing and defragmentation
- Sequential writes optimized for append-heavy workloads
- Hole punching to reclaim unused disk space
- Thread-safe operations using parking_lot locks
Key Features
- Named regions: Store data in logical regions identified by strings or numbers
- Automatic space management: Regions grow dynamically and can be moved/defragmented
- Memory efficiency: Uses memory mapping for zero-copy reads
- Cross-platform hole punching: Supports Linux, macOS, and FreeBSD
- Thread-safe: Concurrent access using RwLocks
Usage
use std::{fs, path::Path};
use seqdb::{Database, PAGE_SIZE, Result};
fn main() -> Result<()> {
// Create or open a database
let database = Database::open(Path::new("my_db"))?;
// Create a region
let (region_id, _) = database.create_region_if_needed("my_region")?;
// Write data to the region
database.write_all_to_region(region_id.into(), b"Hello, world!")?;
// Write at a specific offset
database.write_all_to_region_at(region_id.into(), b"Hi", 0)?;
// Read data using a reader
let reader = database.create_region_reader(region_id.into())?;
let data = reader.read_all();
// Truncate region to specific length
database.truncate_region(region_id.into(), 5)?;
// Flush changes and reclaim space
database.flush_then_punch()?;
Ok(())
}
Core Types
Database: Main entry point for database operationsIdentifier: Region identifier (string or number)Reader: Zero-copy reader for region dataRegion: Metadata about storage regions
Storage Model
seqdb organizes data into regions within a single memory-mapped file. Each region has:
- Start offset: Position in the file (page-aligned)
- Length: Current data size
- Reserved space: Allocated space (≥ length, page-aligned)
Regions can grow automatically and are moved/defragmented as needed for efficient space utilization.
This README was generated by Claude Code
Dependencies
~2.5–3.5MB
~65K SLoC