aboutsummaryrefslogtreecommitdiff
path: root/src/table/replication
diff options
context:
space:
mode:
Diffstat (limited to 'src/table/replication')
-rw-r--r--src/table/replication/mod.rs2
-rw-r--r--src/table/replication/mode.rs47
-rw-r--r--src/table/replication/sharded.rs6
3 files changed, 52 insertions, 3 deletions
diff --git a/src/table/replication/mod.rs b/src/table/replication/mod.rs
index dfcb026a..19e6772f 100644
--- a/src/table/replication/mod.rs
+++ b/src/table/replication/mod.rs
@@ -1,8 +1,10 @@
mod parameters;
mod fullcopy;
+mod mode;
mod sharded;
pub use fullcopy::TableFullReplication;
+pub use mode::ReplicationMode;
pub use parameters::*;
pub use sharded::TableShardedReplication;
diff --git a/src/table/replication/mode.rs b/src/table/replication/mode.rs
new file mode 100644
index 00000000..32687288
--- /dev/null
+++ b/src/table/replication/mode.rs
@@ -0,0 +1,47 @@
+pub enum ReplicationMode {
+ None,
+ TwoWay,
+ ThreeWay,
+}
+
+impl ReplicationMode {
+ pub fn parse(v: &str) -> Option<Self> {
+ match v {
+ "none" | "1" => Some(Self::None),
+ "2" => Some(Self::TwoWay),
+ "3" => Some(Self::ThreeWay),
+ _ => 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 => 2,
+ Self::ThreeWay => 3,
+ }
+ }
+
+ pub fn read_quorum(&self) -> usize {
+ match self {
+ Self::None => 1,
+ Self::TwoWay => 1,
+ Self::ThreeWay => 2,
+ }
+ }
+
+ pub fn write_quorum(&self) -> usize {
+ match self {
+ Self::None => 1,
+ Self::TwoWay => 2,
+ Self::ThreeWay => 2,
+ }
+ }
+}
diff --git a/src/table/replication/sharded.rs b/src/table/replication/sharded.rs
index 93b95a38..8081b892 100644
--- a/src/table/replication/sharded.rs
+++ b/src/table/replication/sharded.rs
@@ -26,8 +26,8 @@ pub struct TableShardedReplication {
impl TableReplication for TableShardedReplication {
fn read_nodes(&self, hash: &Hash) -> Vec<Uuid> {
- let ring = self.system.ring.borrow().clone();
- ring.walk_ring(&hash, self.replication_factor)
+ let ring = self.system.ring.borrow();
+ ring.get_nodes(&hash, self.replication_factor)
}
fn read_quorum(&self) -> usize {
self.read_quorum
@@ -35,7 +35,7 @@ impl TableReplication for TableShardedReplication {
fn write_nodes(&self, hash: &Hash) -> Vec<Uuid> {
let ring = self.system.ring.borrow();
- ring.walk_ring(&hash, self.replication_factor)
+ ring.get_nodes(&hash, self.replication_factor)
}
fn write_quorum(&self) -> usize {
self.write_quorum