aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/replication_mode.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-12-05 15:28:57 +0100
committerAlex Auvolat <alex@adnab.me>2022-12-05 15:28:57 +0100
commit280d1be7b1fde13d23e47f75aa8acd2f90efb81f (patch)
tree5a74e5bdef1cef54360b2b3ca57a53bf1ce61ba2 /src/rpc/replication_mode.rs
parent2065f011ca3f7c736feecffd108c89d3f8019e85 (diff)
downloadgarage-280d1be7b1fde13d23e47f75aa8acd2f90efb81f.tar.gz
garage-280d1be7b1fde13d23e47f75aa8acd2f90efb81f.zip
Refactor health check and add ability to return it in json
Diffstat (limited to 'src/rpc/replication_mode.rs')
-rw-r--r--src/rpc/replication_mode.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/rpc/replication_mode.rs b/src/rpc/replication_mode.rs
new file mode 100644
index 00000000..e244e063
--- /dev/null
+++ b/src/rpc/replication_mode.rs
@@ -0,0 +1,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,
+ }
+ }
+}