2020-04-19 13:14:23 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2021-02-23 17:46:25 +00:00
|
|
|
use garage_rpc::membership::System;
|
2021-02-21 12:11:10 +00:00
|
|
|
use garage_rpc::ring::Ring;
|
2020-04-24 10:10:01 +00:00
|
|
|
use garage_util::data::*;
|
|
|
|
|
2021-03-11 15:54:15 +00:00
|
|
|
use crate::replication::*;
|
2020-04-19 13:14:23 +00:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct TableFullReplication {
|
2021-03-05 14:09:18 +00:00
|
|
|
pub max_faults: usize,
|
2020-04-19 13:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
struct Neighbors {
|
|
|
|
ring: Arc<Ring>,
|
|
|
|
neighbors: Vec<UUID>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TableFullReplication {
|
2021-03-05 14:09:18 +00:00
|
|
|
pub fn new(max_faults: usize) -> Self {
|
|
|
|
TableFullReplication { max_faults }
|
2020-04-19 13:14:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TableReplication for TableFullReplication {
|
|
|
|
// Full replication schema: all nodes store everything
|
|
|
|
// Writes are disseminated in an epidemic manner in the network
|
|
|
|
|
|
|
|
// Advantage: do all reads locally, extremely fast
|
|
|
|
// Inconvenient: only suitable to reasonably small tables
|
|
|
|
|
|
|
|
fn read_nodes(&self, _hash: &Hash, system: &System) -> Vec<UUID> {
|
2020-04-21 17:08:42 +00:00
|
|
|
vec![system.id]
|
2020-04-19 13:14:23 +00:00
|
|
|
}
|
|
|
|
fn read_quorum(&self) -> usize {
|
|
|
|
1
|
|
|
|
}
|
|
|
|
|
2021-03-05 14:09:18 +00:00
|
|
|
fn write_nodes(&self, hash: &Hash, system: &System) -> Vec<UUID> {
|
|
|
|
self.replication_nodes(hash, system.ring.borrow().as_ref())
|
2020-04-19 13:14:23 +00:00
|
|
|
}
|
2021-03-05 14:09:18 +00:00
|
|
|
fn write_quorum(&self, system: &System) -> usize {
|
2021-03-11 18:06:27 +00:00
|
|
|
let nmembers = system.ring.borrow().config.members.len();
|
|
|
|
if nmembers > self.max_faults {
|
|
|
|
nmembers - self.max_faults
|
|
|
|
} else {
|
|
|
|
1
|
|
|
|
}
|
2020-04-19 13:14:23 +00:00
|
|
|
}
|
|
|
|
fn max_write_errors(&self) -> usize {
|
2021-03-05 14:09:18 +00:00
|
|
|
self.max_faults
|
2020-04-19 13:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn replication_nodes(&self, _hash: &Hash, ring: &Ring) -> Vec<UUID> {
|
|
|
|
ring.config.members.keys().cloned().collect::<Vec<_>>()
|
|
|
|
}
|
|
|
|
fn split_points(&self, _ring: &Ring) -> Vec<Hash> {
|
|
|
|
let mut ret = vec![];
|
|
|
|
ret.push([0u8; 32].into());
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
}
|