garage/src/table/replication/fullcopy.rs

51 lines
1.2 KiB
Rust
Raw Normal View History

use std::sync::Arc;
use garage_rpc::layout::*;
2021-10-14 09:50:12 +00:00
use garage_rpc::system::System;
2020-04-24 10:10:01 +00:00
use garage_util::data::*;
2021-03-11 15:54:15 +00:00
use crate::replication::*;
2021-03-26 18:41:46 +00:00
/// 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
#[derive(Clone)]
pub struct TableFullReplication {
2021-03-26 18:41:46 +00:00
/// The membership manager of this node
2021-03-16 10:14:27 +00:00
pub system: Arc<System>,
2021-03-26 18:41:46 +00:00
/// Max number of faults allowed while replicating a record
pub max_faults: usize,
}
impl TableReplication for TableFullReplication {
fn read_nodes(&self, _hash: &Hash) -> Vec<Uuid> {
2021-03-16 10:14:27 +00:00
vec![self.system.id]
}
fn read_quorum(&self) -> usize {
1
}
fn write_nodes(&self, _hash: &Hash) -> Vec<Uuid> {
self.system.cluster_layout().current().node_ids().to_vec()
}
2021-03-16 10:14:27 +00:00
fn write_quorum(&self) -> usize {
let nmembers = self.system.cluster_layout().current().node_ids().len();
if nmembers > self.max_faults {
nmembers - self.max_faults
} else {
1
}
}
fn max_write_errors(&self) -> usize {
self.max_faults
}
2021-03-16 11:18:03 +00:00
fn partition_of(&self, _hash: &Hash) -> Partition {
0u16
}
fn partitions(&self) -> Vec<(Partition, Hash)> {
vec![(0u16, [0u8; 32].into())]
}
}