diff options
author | Alex Auvolat <alex@adnab.me> | 2021-03-16 12:18:03 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-03-16 12:18:03 +0100 |
commit | 2a41b8238496dfeac5ee0f273445299cbd112ff6 (patch) | |
tree | 1c65e8eeaea6ba5124600d33ad98e62b5e13ab53 /src/rpc/ring.rs | |
parent | 0aad2f2e066b5914ac94bb319e7679e2e7761b2b (diff) | |
download | garage-2a41b8238496dfeac5ee0f273445299cbd112ff6.tar.gz garage-2a41b8238496dfeac5ee0f273445299cbd112ff6.zip |
Simpler Merkle & sync
Diffstat (limited to 'src/rpc/ring.rs')
-rw-r--r-- | src/rpc/ring.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/rpc/ring.rs b/src/rpc/ring.rs index a0fdcf84..490fb1de 100644 --- a/src/rpc/ring.rs +++ b/src/rpc/ring.rs @@ -5,6 +5,11 @@ use serde::{Deserialize, Serialize}; use garage_util::data::*; +// A partition number is encoded on 16 bits, +// i.e. we have up to 2**16 partitions. +// (in practice we have exactly 2**PARTITION_BITS partitions) +pub type Partition = u16; + // TODO: make this constant parametrizable in the config file // For deployments with many nodes it might make sense to bump // it up to 10. @@ -17,6 +22,7 @@ const PARTITION_MASK_U16: u16 = ((1 << PARTITION_BITS) - 1) << (16 - PARTITION_B // (most deployments use a replication factor of 3, so...) pub const MAX_REPLICATION: usize = 3; + #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NetworkConfig { pub members: HashMap<UUID, NetworkConfigEntry>, @@ -170,11 +176,24 @@ impl Ring { Self { config, ring } } - pub fn partition_of(&self, from: &Hash) -> u16 { + pub fn partition_of(&self, from: &Hash) -> Partition { let top = u16::from_be_bytes(from.as_slice()[0..2].try_into().unwrap()); top >> (16 - PARTITION_BITS) } + pub fn partitions(&self) -> Vec<(Partition, Hash)> { + let mut ret = vec![]; + + for (i, entry) in self.ring.iter().enumerate() { + ret.push((i as u16, entry.location)); + } + if ret.len() > 0 { + assert_eq!(ret[0].1, [0u8; 32].into()); + } + + ret + } + pub fn walk_ring(&self, from: &Hash, n: usize) -> Vec<UUID> { if self.ring.len() != 1 << PARTITION_BITS { warn!("Ring not yet ready, read/writes will be lost!"); |