ruvector_replication/
lib.rs1pub mod conflict;
33pub mod failover;
34pub mod replica;
35pub mod stream;
36pub mod sync;
37
38pub use conflict::{ConflictResolver, LastWriteWins, MergeFunction, VectorClock};
39pub use failover::{FailoverManager, FailoverPolicy, HealthStatus};
40pub use replica::{Replica, ReplicaRole, ReplicaSet, ReplicaStatus};
41pub use stream::{ChangeEvent, ChangeOperation, ReplicationStream};
42pub use sync::{LogEntry, ReplicationLog, SyncManager, SyncMode};
43
44use thiserror::Error;
45
46pub type Result<T> = std::result::Result<T, ReplicationError>;
48
49#[derive(Error, Debug)]
51pub enum ReplicationError {
52 #[error("Replica not found: {0}")]
53 ReplicaNotFound(String),
54
55 #[error("No primary replica available")]
56 NoPrimary,
57
58 #[error("Replication timeout: {0}")]
59 Timeout(String),
60
61 #[error("Synchronization failed: {0}")]
62 SyncFailed(String),
63
64 #[error("Conflict resolution failed: {0}")]
65 ConflictResolution(String),
66
67 #[error("Failover failed: {0}")]
68 FailoverFailed(String),
69
70 #[error("Network error: {0}")]
71 Network(String),
72
73 #[error("Quorum not met: needed {needed}, got {available}")]
74 QuorumNotMet { needed: usize, available: usize },
75
76 #[error("Split-brain detected")]
77 SplitBrain,
78
79 #[error("Invalid replica state: {0}")]
80 InvalidState(String),
81
82 #[error("Serialization encode error: {0}")]
83 SerializationEncode(#[from] bincode::error::EncodeError),
84
85 #[error("Serialization decode error: {0}")]
86 SerializationDecode(#[from] bincode::error::DecodeError),
87
88 #[error("IO error: {0}")]
89 Io(#[from] std::io::Error),
90}
91
92#[cfg(test)]
93mod tests {
94 use super::*;
95
96 #[test]
97 fn test_error_display() {
98 let err = ReplicationError::QuorumNotMet {
99 needed: 2,
100 available: 1,
101 };
102 assert_eq!(err.to_string(), "Quorum not met: needed 2, got 1");
103 }
104}