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
use openraft_macros::VariantName;
use openraft_macros::since;
/// Enum representing the name of each `Notification` variant.
///
/// This provides an efficient way to identify notification types without
/// string comparisons, useful for logging, metrics, and debugging.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(VariantName)]
#[variant_name(prefix = "Notify::")]
#[since(version = "0.10.2", change = "Added `ReplicationStopped`")]
#[since(version = "0.10.2", change = "Added `ReplicateCleared`")]
#[since(version = "0.10.1", change = "`Tick` comes from the heartbeat timer of a leader")]
#[since(version = "0.10.1", change = "Added `ElectionDeadlineReached`")]
#[since(version = "0.10.1", change = "marked #[non_exhaustive]")]
#[since(version = "0.10.0", change = "Added `LogPurged`")]
#[since(
version = "0.10.0",
change = "renamed from `CheckPendingLinearizableReads` to `PendingReadDeadlineReached`"
)]
#[non_exhaustive]
pub enum NotificationName {
/// A response to a vote request.
VoteResponse,
/// A response to a Pre-Vote request.
PreVoteResponse,
/// A leader saw a higher vote while replicating.
HigherVote,
/// A local storage error that stops `RaftCore`.
StorageError,
/// A local storage IO operation completed.
LocalIO,
/// A replication worker reported progress.
ReplicationProgress,
/// A heartbeat worker reported progress.
HeartbeatProgress,
/// A state machine worker returned the result of a command.
StateMachine,
/// A leader's heartbeat timer reached the next heartbeat, waking `RaftCore` to send it.
Tick,
/// The earliest pending linearizable read reached its deadline.
PendingReadDeadlineReached,
/// A log purge completed in storage.
LogPurged,
/// A follower's election timeout may have expired, waking `RaftCore` to check whether to
/// start an election.
ElectionDeadlineReached,
/// A replication worker stopped reading the log for a plan the leader dropped.
ReplicateCleared,
/// A replication worker whose stream was closed reads the log no more.
ReplicationStopped,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_notification_name_index() {
assert_eq!(NotificationName::COUNT, NotificationName::ALL.len());
for (i, name) in NotificationName::ALL.iter().enumerate() {
assert_eq!(
name.index(),
i,
"NotificationName::{:?} index mismatch: expected {}, got {}",
name,
i,
name.index()
);
}
}
}