1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//! Cluster events: a structured fan-out channel for state
//! transitions that test harnesses, admin tools, and OTLP
//! appenders can consume programmatically.
//!
//! The engine already publishes cluster signals to two
//! observability surfaces - tracing spans and Prometheus
//! counters - which are excellent for humans and dashboards but
//! awkward to consume from code. This module adds a third
//! surface: a strongly-typed, OTP `gen_event`-style broadcast of
//! [`ClusterEvent`] values backed by a
//! [`tokio::sync::broadcast`] channel. Consumers subscribe via
//! [`EventManager::subscribe`] and read events through
//! [`Subscriber::recv`] / [`Subscriber::try_recv`].
//!
//! Slow subscribers do not block publishers. When a subscriber
//! falls behind the channel tail, [`Subscriber::recv`] returns
//! [`SubscriberError::Lagged`] reporting the count of dropped
//! events, then resumes from the freshest event in the buffer.
//!
//! # Examples
//!
//! ```
//! use std::time::SystemTime;
//! use dynomite::events::{ClusterEvent, EventManager};
//! # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
//! let mgr = EventManager::new(16);
//! let mut sub = mgr.subscribe();
//! mgr.publish(ClusterEvent::PeerUp {
//! peer_id: 7,
//! dc: "dc1".to_string(),
//! ts: SystemTime::now(),
//! });
//! match sub.recv().await.unwrap() {
//! ClusterEvent::PeerUp { peer_id, .. } => assert_eq!(peer_id, 7),
//! _ => panic!("unexpected event"),
//! }
//! # });
//! ```
use ;
pub use EventManager;
pub use ;
use crateDynToken;
/// Identifier of a peer in the cluster pool.
///
/// Mirrors [`crate::cluster::peer::Peer::idx`] and the existing
/// [`crate::embed::events::PeerId`] alias so the two event
/// surfaces remain index-compatible.
pub type PeerId = u32;
/// Half-open token range `[start, end)` covering one slice of
/// the consistent-hashing ring.
///
/// Used by AAE exchanges to identify which partition is being
/// reconciled. The range is interpreted as wrap-around when
/// `start >= end`, matching the ring traversal semantics in
/// [`crate::cluster::pool`].
///
/// # Examples
///
/// ```
/// use dynomite::events::TokenRange;
/// use dynomite::hashkit::DynToken;
/// let r = TokenRange::new(DynToken::from_u32(0), DynToken::from_u32(1024));
/// assert_eq!(r.start(), &DynToken::from_u32(0));
/// assert_eq!(r.end(), &DynToken::from_u32(1024));
/// ```
/// Structured cluster-event payload published on the
/// [`EventManager`] broadcast.
///
/// Variants are non-exhaustive at the type level; consumers must
/// always include a wildcard arm so future additions remain
/// non-breaking.
///
/// # Examples
///
/// ```
/// use std::time::SystemTime;
/// use dynomite::events::ClusterEvent;
/// let e = ClusterEvent::PeerUp { peer_id: 1, dc: "dc1".into(), ts: SystemTime::now() };
/// match e {
/// ClusterEvent::PeerUp { peer_id, .. } => assert_eq!(peer_id, 1),
/// _ => panic!("unexpected"),
/// }
/// ```