aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-03-16 11:14:27 +0100
committerAlex Auvolat <alex@adnab.me>2021-03-16 11:14:27 +0100
commit1d9961e4118af0e26068e1d6c5c6c009a1292a88 (patch)
treee05bc162772e8c4a5bd658f437de02108b55c5a2 /src/rpc
parent6a8439fd1345ecae7414386f76dda7a03eb14df2 (diff)
downloadgarage-1d9961e4118af0e26068e1d6c5c6c009a1292a88.tar.gz
garage-1d9961e4118af0e26068e1d6c5c6c009a1292a88.zip
Simplify replication logic
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/ring.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/rpc/ring.rs b/src/rpc/ring.rs
index a89b730c..a0fdcf84 100644
--- a/src/rpc/ring.rs
+++ b/src/rpc/ring.rs
@@ -170,6 +170,11 @@ impl Ring {
Self { config, ring }
}
+ pub fn partition_of(&self, from: &Hash) -> u16 {
+ let top = u16::from_be_bytes(from.as_slice()[0..2].try_into().unwrap());
+ top >> (16 - PARTITION_BITS)
+ }
+
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!");
@@ -177,8 +182,9 @@ impl Ring {
}
let top = u16::from_be_bytes(from.as_slice()[0..2].try_into().unwrap());
-
let partition_idx = (top >> (16 - PARTITION_BITS)) as usize;
+ assert_eq!(partition_idx, self.partition_of(from) as usize);
+
let partition = &self.ring[partition_idx];
let partition_top =