TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nubskr/walrus/llms.txt
Use this file to discover all available pages before exploring further.
Walrus struct is the main entry point for the Walrus Write-Ahead Log library. It provides high-performance concurrent read and write operations with configurable consistency models and fsync scheduling.
Constructors
new()
Creates a new Walrus instance with default settings.- Read consistency:
StrictlyAtOnce - Fsync schedule:
Milliseconds(200) - Data directory:
./wal_files(orWALRUS_DATA_DIRenv var)
with_consistency()
Creates a Walrus instance with a custom read consistency model.The read consistency model to use (StrictlyAtOnce or AtLeastOnce)
with_consistency_and_schedule()
Creates a Walrus instance with custom consistency and fsync scheduling.The read consistency model to use
When to flush data to disk (Milliseconds, SyncEach, or NoFsync)
new_for_key()
Creates a namespaced Walrus instance with a separate storage directory.Namespace identifier (creates a subdirectory under
wal_files/<sanitized-key>/)with_consistency_for_key()
Creates a namespaced Walrus instance with custom consistency.Namespace identifier
The read consistency model to use
with_consistency_and_schedule_for_key()
Creates a namespaced Walrus instance with full custom configuration.Namespace identifier
The read consistency model to use
When to flush data to disk
builder()
Returns aWalrusBuilder for explicit configuration.
WALRUS_DATA_DIR environment variable.
Example:
Write Operations
append_for_topic()
Appends a single entry to a topic.The topic name to append to
The data bytes to append
batch_append_for_topic()
Atomically appends multiple entries to a topic (all-or-nothing).The topic name to append to
Slice of byte slices to append atomically (max 2,000 entries, ~10GB total)
- Maximum 2,000 entries per batch
- Maximum ~10GB total payload per batch
- On Linux with FD backend: Uses io_uring for parallel I/O
- Other platforms or mmap backend: Sequential operations
Read Operations
read_next()
Reads the next entry from a topic.The topic name to read from
true: Consume the entry (advances read position)false: Peek at the entry without consuming
Ok(Some(entry)): Entry was read successfullyOk(None): No more entries availableErr(e): I/O error occurred
batch_read_for_topic()
Reads multiple entries from a topic up to a byte limit.The topic name to read from
Maximum bytes to read (returns at least 1 entry if available)
true: Consume entries (advances read position)false: Peek at entries without consuming
None: Stateful read from current positionSome(offset): Stateless read from specific byte offset
Vector of entries read (may be empty if none available)
- On Linux with FD backend: Uses io_uring for parallel I/O
- Enforces max 2,000 entries per call
Topic Management
mark_topic_dirty()
Marks a topic as having uncommitted changes.The topic name to mark as dirty
mark_topic_clean()
Marks a topic as having all changes committed.The topic name to mark as clean
topic_is_clean()
Checks if a topic has uncommitted changes.The topic name to check
true if topic is clean, false if dirtyget_topic_entry_count()
Gets the number of unread entries for a topic.The topic name to query
Number of entries available to read (0 if none or topic doesn’t exist)
get_topic_entry_counts()
Gets entry counts for all topics.Map of topic names to their unread entry counts
get_topic_size()
Gets the total byte size of a topic (sealed + active blocks).The topic name to query
Total bytes used by the topic (0 if topic doesn’t exist)
Helper Functions
topic_entry_count()
Returns the entry count for a specific topic.Reference to a Walrus instance
The topic name
Number of entries written to the topic
topic_entry_counts()
Returns entry counts for all topics.Reference to a Walrus instance
Map of topic names to their entry counts
Module Functions
These functions control global backend behavior and must be called before creating any Walrus instances.enable_fd_backend()
Enables the FD (file descriptor) backend with pread/pwrite (default).- Uses io_uring on Linux for batch operations
- Opens files with O_SYNC when
FsyncSchedule::SyncEachis used
disable_fd_backend()
Disables the FD backend and uses memory-mapped files instead.- Uses memory-mapped files
- Batch operations fall back to sequential reads/writes
- Works on all platforms
Related Types
- Entry (WalEntry) - Structure returned by read operations
- ReadConsistency - Consistency model configuration
- FsyncSchedule - Fsync timing configuration