Skip to main content

reifydb_core/event/
metric.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4//! Storage and CDC statistics events.
5//!
6//! These events are emitted when storage operations occur that need stats tracking.
7//! The metrics worker listens to these events and updates storage statistics.
8
9use crate::{common::CommitVersion, encoded::key::EncodedKey};
10
11define_event! {
12	/// Emitted when storage operations are committed that need stats tracking.
13	/// Used for both commit-time ops and async drop worker ops.
14	pub struct StorageStatsRecordedEvent {
15		pub writes: Vec<StorageWrite>,
16		pub deletes: Vec<StorageDelete>,
17		pub drops: Vec<StorageDrop>,
18		pub version: CommitVersion,
19	}
20}
21
22/// A storage write operation for stats tracking.
23#[derive(Clone, Debug)]
24pub struct StorageWrite {
25	pub key: EncodedKey,
26	pub value_bytes: u64,
27}
28
29/// A storage delete operation for stats tracking.
30#[derive(Clone, Debug)]
31pub struct StorageDelete {
32	pub key: EncodedKey,
33	pub value_bytes: u64,
34}
35
36/// A storage drop operation (MVCC cleanup) for stats tracking.
37#[derive(Clone, Debug)]
38pub struct StorageDrop {
39	pub key: EncodedKey,
40	pub value_bytes: u64,
41}
42
43define_event! {
44	/// Emitted when CDC entries are written that need stats tracking.
45	pub struct CdcStatsRecordedEvent {
46		pub entries: Vec<CdcEntryStats>,
47		pub version: CommitVersion,
48	}
49}
50
51/// A CDC entry for stats tracking.
52#[derive(Clone, Debug)]
53pub struct CdcEntryStats {
54	pub key: EncodedKey,
55	pub value_bytes: u64,
56}
57
58/// A CDC entry drop for stats tracking.
59#[derive(Clone, Debug)]
60pub struct CdcEntryDrop {
61	pub key: EncodedKey,
62	pub value_bytes: u64,
63}
64
65define_event! {
66	/// Emitted when CDC entries are dropped that need stats tracking.
67	pub struct CdcStatsDroppedEvent {
68		pub entries: Vec<CdcEntryDrop>,
69		pub version: CommitVersion,
70	}
71}