aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-03-11 19:06:27 +0100
committerAlex Auvolat <alex@adnab.me>2021-03-11 19:06:27 +0100
commit3f7a496355bdbeeeee859912fa6fa7a95cb47f3b (patch)
tree53284e346d2020de4a9207b6a20bc1b83ae9df6e
parentf7c2cd1cd7ee15b9c97b9fbdef25c0644b3523bb (diff)
downloadgarage-3f7a496355bdbeeeee859912fa6fa7a95cb47f3b.tar.gz
garage-3f7a496355bdbeeeee859912fa6fa7a95cb47f3b.zip
More security: don't delete stuff too easily
-rw-r--r--src/model/block.rs3
-rw-r--r--src/table/replication/fullcopy.rs7
-rw-r--r--src/table/sync.rs3
3 files changed, 12 insertions, 1 deletions
diff --git a/src/model/block.rs b/src/model/block.rs
index 987ec9e4..a3bbe43d 100644
--- a/src/model/block.rs
+++ b/src/model/block.rs
@@ -305,6 +305,9 @@ impl BlockManager {
let ring = self.system.ring.borrow().clone();
let mut who = self.replication.replication_nodes(&hash, &ring);
+ if who.len() < self.replication.write_quorum(&self.system) {
+ return Err(Error::Message(format!("Not trying to offload block because we don't have a quorum of nodes to write to")));
+ }
who.retain(|id| *id != self.system.id);
let msg = Arc::new(Message::NeedBlockQuery(*hash));
diff --git a/src/table/replication/fullcopy.rs b/src/table/replication/fullcopy.rs
index a20f20b7..a5faece9 100644
--- a/src/table/replication/fullcopy.rs
+++ b/src/table/replication/fullcopy.rs
@@ -41,7 +41,12 @@ impl TableReplication for TableFullReplication {
self.replication_nodes(hash, system.ring.borrow().as_ref())
}
fn write_quorum(&self, system: &System) -> usize {
- system.ring.borrow().config.members.len() - self.max_faults
+ let nmembers = system.ring.borrow().config.members.len();
+ if nmembers > self.max_faults {
+ nmembers - self.max_faults
+ } else {
+ 1
+ }
}
fn max_write_errors(&self) -> usize {
self.max_faults
diff --git a/src/table/sync.rs b/src/table/sync.rs
index b5044a4e..f8ebb2f0 100644
--- a/src/table/sync.rs
+++ b/src/table/sync.rs
@@ -277,6 +277,9 @@ where
warn!("Interrupting offload as partitions seem to have changed");
break;
}
+ if nodes.len() < self.aux.replication.write_quorum(&self.aux.system) {
+ return Err(Error::Message(format!("Not offloading as we don't have a quorum of nodes to write to.")));
+ }
counter += 1;
debug!(