Features
- High Performance: Optimized for concurrent writes and reads
- Topic-based Organization: Separate read/write streams per topic
- Configurable Consistency: Choose between strict and relaxed consistency models
- Batched I/O: Atomic batch append and capped batch read APIs with io_uring acceleration on Linux
- Dual Storage Backends: FD backend with pread/pwrite (default) or mmap backend
- Persistent Read Offsets: Read positions survive process restarts
- Coordination-free Deletion: Atomic file cleanup without blocking operations
- Comprehensive Benchmarking: Built-in performance testing suite
Benchmarks
Run the supplied load tests straight from the repo:
Each target honours the environment variables documented in Makefile. Tweak
things like FSYNC, THREADS, or WALRUS_DURATION to explore other scenarios.
Quick Start
Add Walrus to your Cargo.toml:
[]
= "0.1.0"
Basic Usage
use ;
// Create a new WAL instance with default settings
let wal = new?;
// Write data to a topic
let data = b"Hello, Walrus!";
wal.append_for_topic?;
// Read data from the topic
if let Some = wal.read_next?
To peek without consuming an entry, call read_next("my-topic", false); the cursor only advances
when you pass true.
Advanced Configuration
use ;
// Configure with custom consistency and fsync behavior
let wal = with_consistency_and_schedule?;
// Write and read operations work the same way
wal.append_for_topic?;
Configuration Basics
- Read consistency:
StrictlyAtOncepersists every checkpoint;AtLeastOnce { persist_every }favours throughput and tolerates replays. - Fsync schedule: choose
SyncEach,Milliseconds(n), orNoFsyncwhen constructingWalrusto balance durability vs latency. - Storage backend: FD backend (default) uses pread/pwrite syscalls and enables io_uring for batch operations on Linux;
disable_fd_backend()switches to the mmap backend. - Namespacing & data dir: set
WALRUS_INSTANCE_KEYor use the_for_keyconstructors to isolate workloads;WALRUS_DATA_DIRrelocates the entire tree. - Noise control:
WALRUS_QUIET=1mutes debug logging from internal helpers.
Benchmark targets (make bench-writes, etc.) honour flags like FSYNC, THREADS, WALRUS_DURATION, and WALRUS_BATCH_SIZE, check the Makefile for the full list.
API Reference
Constructors
Walrus::new() -> io::Result<Self>– StrictlyAtOnce reads, 200ms fsync cadence.Walrus::with_consistency(mode: ReadConsistency) -> io::Result<Self>– Pick the read checkpoint model.Walrus::with_consistency_and_schedule(mode: ReadConsistency, schedule: FsyncSchedule) -> io::Result<Self>– Set both read consistency and fsync policy explicitly.Walrus::new_for_key(key: &str) -> io::Result<Self>– Namespace files underwal_files/<sanitized-key>/.Walrus::with_consistency_for_key(...)/with_consistency_and_schedule_for_key(...)– Combine per-key isolation with custom consistency/fsync choices.
Set WALRUS_INSTANCE_KEY=<key> to make the default constructors pick the same namespace without changing call-sites.
Topic Writes
append_for_topic(&self, topic: &str, data: &[u8]) -> io::Result<()>– Appends a single payload. Topics are created lazily. ReturnsErrorKind::WouldBlockif a batch is currently running for the topic.batch_append_for_topic(&self, topic: &str, batch: &[&[u8]]) -> io::Result<()>– Writes up to 2 000 entries (~10 GB including metadata) atomically. On Linux with the fd backend enabled the batch is submitted via io_uring; other platforms fall back to sequential writes. Failures roll back offsets and release provisional blocks.
Topic Reads
read_next(&self, topic: &str, checkpoint: bool) -> io::Result<Option<Entry>>– Returns the next entry, advancing the persisted cursor whencheckpointistrue. Passingfalselets you peek without consuming the entry.batch_read_for_topic(&self, topic: &str, max_bytes: usize, checkpoint: bool) -> io::Result<Vec<Entry>>– Streams entries in commit order until eithermax_bytesof payload or the 2 000-entry ceiling is reached (always yields at least one entry when data is available). Respects the same checkpoint semantics asread_next.
Types
Further Reading
Older deep dives live under docs/ (architecture, batch design notes, etc.) if
you need more than the basics above.
Contributing
We welcome patches, check CONTRIBUTING.md for the workflow.
License
This project is licensed under the MIT License, see the LICENSE file for details.
Changelog
Version 0.1.0
- Initial release
- Core WAL functionality
- Topic-based organization
- Configurable consistency modes
- Comprehensive benchmark suite
- Memory-mapped I/O implementation
- Persistent read offset tracking