2021-05-28 10:36:22 +00:00
|
|
|
pub enum ReplicationMode {
|
|
|
|
None,
|
|
|
|
TwoWay,
|
2022-03-28 14:20:15 +00:00
|
|
|
TwoWayDangerous,
|
2021-05-28 10:36:22 +00:00
|
|
|
ThreeWay,
|
2022-03-28 14:20:15 +00:00
|
|
|
ThreeWayDegraded,
|
|
|
|
ThreeWayDangerous,
|
2021-05-28 10:36:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ReplicationMode {
|
|
|
|
pub fn parse(v: &str) -> Option<Self> {
|
|
|
|
match v {
|
|
|
|
"none" | "1" => Some(Self::None),
|
|
|
|
"2" => Some(Self::TwoWay),
|
2022-03-28 14:20:15 +00:00
|
|
|
"2-dangerous" => Some(Self::TwoWayDangerous),
|
2021-05-28 10:36:22 +00:00
|
|
|
"3" => Some(Self::ThreeWay),
|
2022-03-28 14:20:15 +00:00
|
|
|
"3-degraded" => Some(Self::ThreeWayDegraded),
|
|
|
|
"3-dangerous" => Some(Self::ThreeWayDangerous),
|
2021-05-28 10:36:22 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn control_write_max_faults(&self) -> usize {
|
|
|
|
match self {
|
|
|
|
Self::None => 0,
|
|
|
|
_ => 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn replication_factor(&self) -> usize {
|
|
|
|
match self {
|
|
|
|
Self::None => 1,
|
2022-03-28 14:20:15 +00:00
|
|
|
Self::TwoWay | Self::TwoWayDangerous => 2,
|
|
|
|
Self::ThreeWay | Self::ThreeWayDegraded | Self::ThreeWayDangerous => 3,
|
2021-05-28 10:36:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn read_quorum(&self) -> usize {
|
|
|
|
match self {
|
|
|
|
Self::None => 1,
|
2022-03-28 14:20:15 +00:00
|
|
|
Self::TwoWay | Self::TwoWayDangerous => 1,
|
2021-05-28 10:36:22 +00:00
|
|
|
Self::ThreeWay => 2,
|
2022-03-28 14:20:15 +00:00
|
|
|
Self::ThreeWayDegraded | Self::ThreeWayDangerous => 1,
|
2021-05-28 10:36:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn write_quorum(&self) -> usize {
|
|
|
|
match self {
|
|
|
|
Self::None => 1,
|
|
|
|
Self::TwoWay => 2,
|
2022-03-28 14:20:15 +00:00
|
|
|
Self::TwoWayDangerous => 1,
|
|
|
|
Self::ThreeWay | Self::ThreeWayDegraded => 2,
|
|
|
|
Self::ThreeWayDangerous => 1,
|
2021-05-28 10:36:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|