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
//! Mutation origin metadata per spec 02 section 8.
use serde::{Deserialize, Serialize};
use crate::NodeId;
/// Origin of a graph mutation.
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum Origin {
/// Mutation originated in this selene-db instance.
#[default]
Local,
/// Reserved for future replication (no production producer today).
///
/// The WAL entry-header slot and the recovery dedup branch carry this
/// variant, but no engine code path emits it yet; it is retained as the
/// stable on-disk surface for a future replication producer.
///
/// `source_node_id` names a replication source node, not a property-graph
/// node. Sequence values are caller-defined; `0` is allowed.
Replicated {
/// Federation source node.
source_node_id: NodeId,
/// Source sequence number.
source_seq: u64,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn local_and_replicated_distinct() {
assert_ne!(
Origin::Local,
Origin::Replicated {
source_node_id: NodeId::new(1),
source_seq: 1,
}
);
}
#[test]
fn replicated_carries_source_metadata() {
let origin = Origin::Replicated {
source_node_id: NodeId::new(7),
source_seq: 42,
};
match origin {
Origin::Replicated {
source_node_id,
source_seq,
} => {
assert_eq!(source_node_id, NodeId::new(7));
assert_eq!(source_seq, 42);
}
Origin::Local => panic!("expected replicated origin"),
}
}
#[test]
fn default_is_local() {
assert_eq!(Origin::default(), Origin::Local);
}
#[test]
fn replicated_sequence_zero_is_allowed() {
let origin = Origin::Replicated {
source_node_id: NodeId::new(1),
source_seq: 0,
};
assert!(matches!(origin, Origin::Replicated { source_seq: 0, .. }));
}
}