From b53dca635c899370fbf3702bf4a2167bdbd903af Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Mon, 15 Mar 2021 17:35:18 +0100 Subject: [PATCH] Allow removal of backends from config Signed-off-by: Lee Smet --- src/config.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/config.rs b/src/config.rs index ee8e6fc..154efa7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,7 @@ use crate::{encryption::SymmetricKey, zdb::ZdbConnectionInfo}; use gray_codes::{InclusionExclusion, SetMutation}; use rand::seq::SliceRandom; use serde::{Deserialize, Serialize}; +use std::net::SocketAddr; /// The full configuration for the data encoding and decoding. This included the etcd to save the /// data to, as well as all backends which may or may not be used when data is written. @@ -143,6 +144,18 @@ impl Config { .collect() } + /// Remove a shard from the config. If the shard is present multiple times, all instances will + /// be removed. + pub fn remove_shard(&mut self, address: &SocketAddr) { + for mut group in &mut self.groups { + group.backends = group + .backends + .drain(..) + .filter(|backend| backend.address() != address) + .collect(); + } + } + /// Returns a list of 0-db's to use for storage of the data shards, in accordance to the /// encoding profile and redundancy policies. If no valid configuration can be found, an error /// is returned. If multiple valid configurations are found, one is selected at random.