aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/replication_mode.rs
blob: e244e063a10204858b688293d2f830706210e0f8 (plain) (blame)
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
#[derive(Clone, Copy)]
pub enum ReplicationMode {
	None,
	TwoWay,
	TwoWayDangerous,
	ThreeWay,
	ThreeWayDegraded,
	ThreeWayDangerous,
}

impl ReplicationMode {
	pub fn parse(v: &str) -> Option<Self> {
		match v {
			"none" | "1" => Some(Self::None),
			"2" => Some(Self::TwoWay),
			"2-dangerous" => Some(Self::TwoWayDangerous),
			"3" => Some(Self::ThreeWay),
			"3-degraded" => Some(Self::ThreeWayDegraded),
			"3-dangerous" => Some(Self::ThreeWayDangerous),
			_ => 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,
			Self::TwoWay | Self::TwoWayDangerous => 2,
			Self::ThreeWay | Self::ThreeWayDegraded | Self::ThreeWayDangerous => 3,
		}
	}

	pub fn read_quorum(&self) -> usize {
		match self {
			Self::None => 1,
			Self::TwoWay | Self::TwoWayDangerous => 1,
			Self::ThreeWay => 2,
			Self::ThreeWayDegraded | Self::ThreeWayDangerous => 1,
		}
	}

	pub fn write_quorum(&self) -> usize {
		match self {
			Self::None => 1,
			Self::TwoWay => 2,
			Self::TwoWayDangerous => 1,
			Self::ThreeWay | Self::ThreeWayDegraded => 2,
			Self::ThreeWayDangerous => 1,
		}
	}
}