clasp-journal
Append-only event journal for crash recovery and state persistence in CLASP.
Features
- Append-Only Log - Immutable, ordered record of SET and PUBLISH operations
- Pattern Queries - Retrieve entries matching CLASP address patterns
- Time Range Queries - Filter by timestamp with microsecond precision
- Snapshots - Save and restore full state snapshots for fast recovery
- Compaction - Remove old entries to reclaim storage
- Pluggable Storage - In-memory ring buffer or SQLite backends
- Router Integration - Wire into the router with
Router::with_journal()
Installation
[]
= "3.5"
# With SQLite persistence
= { = "3.5", = ["sqlite"] }
Feature Flags
| Feature | Description |
|---|---|
sqlite |
Enables SqliteJournal for persistent storage |
Usage
In-Memory Journal
use ;
use Value;
// Create with capacity (evicts oldest entries when full)
let journal = new;
// Or use default capacity (10,000 entries)
let journal = default_capacity;
// Append a SET entry
let entry = from_set;
let seq = journal.append.await?;
SQLite Journal
use SqliteJournal;
let journal = new?;
// Same Journal API as MemoryJournal
Query Entries
use SignalType;
// Query by pattern and time range
let entries = journal.query.await?;
// Get entries since a sequence number
let recent = journal.since.await?;
// Get latest sequence number
let latest = journal.latest_seq.await?;
Snapshots
use ParamSnapshot;
// Save a state snapshot
let snapshots = vec!;
let snap_seq = journal.snapshot.await?;
// Load the most recent snapshot
if let Some = journal.load_snapshot.await?
Compaction
// Remove entries older than a given sequence number
let removed = journal.compact.await?;
println!;
Router Integration
use ;
use SqliteJournal;
use Arc;
let journal = new;
let router = new
.with_journal; // requires `journal` feature on clasp-router
The router automatically records all SET and PUBLISH operations to the journal and supports replay for crash recovery.
Configuration Reference
JournalEntry
| Field | Type | Description |
|---|---|---|
seq |
u64 |
Monotonic sequence number (assigned by journal) |
timestamp |
u64 |
Wall clock timestamp (microseconds since epoch) |
author |
String |
Entity or session ID of the author |
address |
String |
CLASP address the entry applies to |
signal_type |
SignalType |
Param, Event, Stream, Gesture, or Timeline |
value |
Value |
The value that was set or published |
revision |
Option<u64> |
Param revision (Some for SET, None for PUBLISH) |
msg_type |
u8 |
Message type code (0x21 = SET, 0x20 = PUBLISH) |
ParamSnapshot
| Field | Type | Description |
|---|---|---|
address |
String |
CLASP address |
value |
Value |
Current param value |
revision |
u64 |
Current revision number |
writer |
String |
Last writer ID |
timestamp |
u64 |
Timestamp (microseconds since epoch) |
Journal Trait Methods
| Method | Description |
|---|---|
append(entry) |
Append an entry, returns sequence number |
query(pattern, from, to, limit, types) |
Query by pattern, time, and signal type |
since(seq, limit) |
Get entries after a sequence number |
latest_seq() |
Get the highest sequence number |
snapshot(state) |
Save a state snapshot |
load_snapshot() |
Load the most recent snapshot |
compact(before_seq) |
Remove entries before a sequence number |
len() |
Total number of entries |
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Maintained by LumenCanvas