linkrs_storage/engine/storage_events.rs
1use std::sync::Arc;
2
3/// Storage engine lifecycle notification.
4///
5/// Emission is best-effort and synchronous on the persistence path.
6/// Observers must return quickly and must not call back into the
7/// persistence coordinator while handling an event.
8#[derive(Debug, Clone)]
9pub enum StorageEvent {
10 CheckpointStarted {
11 sequence: u64,
12 },
13 CheckpointCompleted {
14 sequence: u64,
15 duration_ms: u64,
16 data_flushed: u64,
17 wal_truncated: u64,
18 snapshot_created: bool,
19 },
20 CheckpointFailed {
21 sequence: Option<u64>,
22 error: String,
23 },
24 WalTruncated {
25 up_to_lsn: u64,
26 },
27 SnapshotCreated {
28 sequence: u64,
29 },
30 GcRun {
31 reclaimed_entries: u64,
32 },
33 CompactionStarted {
34 space_id: u64,
35 },
36 CompactionCompleted {
37 space_id: u64,
38 reclaimed_bytes: u64,
39 },
40}
41
42/// Sentinel space id used for global (cross-space) transactional compaction.
43///
44/// Compaction operates on the whole store rather than a single space, so
45/// observers see this id in `CompactionStarted` / `CompactionCompleted`.
46pub const GLOBAL_COMPACTION_SPACE_ID: u64 = 0;
47
48/// Runtime observer for storage events.
49pub type StorageEventCallback = Arc<dyn Fn(&StorageEvent) + Send + Sync>;
50
51/// Observer for reclaimed-entry counts, forwarded by GC managers to the
52/// persistence coordinator which fans out `StorageEvent::GcRun`.
53pub type GcEventSink = Arc<dyn Fn(u64) + Send + Sync>;