#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReplicationSection {
pub role: ReplicationRole,
pub upstream: Option<String>,
pub listen_port_base: u16,
pub replication_buffer_size: u64,
pub reconnect_window_ms: u32,
}
impl Default for ReplicationSection {
fn default() -> Self {
Self {
role: ReplicationRole::Standalone,
upstream: None,
listen_port_base: 0,
replication_buffer_size: 256 * 1024 * 1024,
reconnect_window_ms: 60_000,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ReplicationRole {
#[default]
Standalone,
Primary,
Replica,
}
impl ReplicationRole {
pub fn as_str(&self) -> &'static str {
match self {
Self::Standalone => "standalone",
Self::Primary => "primary",
Self::Replica => "replica",
}
}
pub fn parse(s: &str) -> Option<Self> {
match s.to_ascii_lowercase().as_str() {
"standalone" => Some(Self::Standalone),
"primary" => Some(Self::Primary),
"replica" => Some(Self::Replica),
_ => None,
}
}
}