From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 9412897080 for ; Tue, 16 Apr 2024 17:24:59 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 43CB21EB1A for ; Tue, 16 Apr 2024 17:24:29 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 16 Apr 2024 17:24:27 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1B20745A4D for ; Tue, 16 Apr 2024 17:24:27 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Tue, 16 Apr 2024 17:23:56 +0200 Message-Id: <20240416152416.96561-3-h.laimer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240416152416.96561-1-h.laimer@proxmox.com> References: <20240416152416.96561-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.008 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup v4 02/22] datastore: make dropping from cache more efficient X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Apr 2024 15:24:59 -0000 ... by not having to read the whole config file on every drop, but assume calling `update-datastore-cache` through the scoket implies it should be dropped and doing the checking on the sending side. Signed-off-by: Hannes Laimer --- pbs-datastore/src/datastore.rs | 60 +++++++++++++++------------------- src/api2/config/datastore.rs | 8 +++-- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index 0685cc84..a7fe3b8c 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -34,7 +34,7 @@ use crate::task_tracking::{self, update_active_operations}; use crate::DataBlob; lazy_static! { - static ref DATASTORE_MAP: Mutex>> = + static ref DATASTORE_MAP: Mutex, bool)>> = Mutex::new(HashMap::new()); } @@ -111,24 +111,15 @@ impl Drop for DataStore { last_task = updated_operations.read + updated_operations.write == 0; } } - - // remove datastore from cache iff - // - last task finished, and - // - datastore is in a maintenance mode that mandates it - let remove_from_cache = last_task - && pbs_config::datastore::config() - .and_then(|(s, _)| s.lookup::("datastore", self.name())) - .map_or(false, |c| { - c.get_maintenance_mode().map_or(false, |m| m.is_offline()) - }); - - if remove_from_cache { - DATASTORE_MAP.lock().unwrap().remove(self.name()); + if last_task { + let mut cache = DATASTORE_MAP.lock().unwrap(); + if let Some((_, true)) = cache.get(self.name()) { + cache.remove(self.name()); + } } } } } - impl DataStore { // This one just panics on everything #[doc(hidden)] @@ -169,7 +160,7 @@ impl DataStore { let entry = datastore_cache.get(name); // reuse chunk store so that we keep using the same process locker instance! - let chunk_store = if let Some(datastore) = &entry { + let (chunk_store, drop_from_cache) = if let Some((datastore, drop_from_cache)) = &entry { let last_digest = datastore.last_digest.as_ref(); if let Some(true) = last_digest.map(|last_digest| last_digest == &digest) { return Ok(Arc::new(Self { @@ -177,23 +168,26 @@ impl DataStore { operation, })); } - Arc::clone(&datastore.chunk_store) + (Arc::clone(&datastore.chunk_store), *drop_from_cache) } else { let tuning: DatastoreTuning = serde_json::from_value( DatastoreTuning::API_SCHEMA .parse_property_string(config.tuning.as_deref().unwrap_or(""))?, )?; - Arc::new(ChunkStore::open( - name, - &config.path, - tuning.sync_level.unwrap_or_default(), - )?) + ( + Arc::new(ChunkStore::open( + name, + &config.path, + tuning.sync_level.unwrap_or_default(), + )?), + false, + ) }; let datastore = DataStore::with_store_and_config(chunk_store, config, Some(digest))?; let datastore = Arc::new(datastore); - datastore_cache.insert(name.to_string(), datastore.clone()); + datastore_cache.insert(name.to_string(), (datastore.clone(), drop_from_cache)); Ok(Arc::new(Self { inner: datastore, @@ -211,20 +205,18 @@ impl DataStore { Ok(()) } - /// trigger clearing cache entry based on maintenance mode. Entry will only - /// be cleared iff there is no other task running, if there is, the end of the + /// trigger clearing of cache entry. Entry will only be cleared iff + /// there is no other task running, if there is, the end of the /// last running task will trigger the clearing of the cache entry. pub fn update_datastore_cache(name: &str) -> Result<(), Error> { - let (config, _digest) = pbs_config::datastore::config()?; - let datastore: DataStoreConfig = config.lookup("datastore", name)?; - if datastore - .get_maintenance_mode() - .map_or(false, |m| m.is_offline()) - { - // the datastore drop handler does the checking if tasks are running and clears the - // cache entry, so we just have to trigger it here - let _ = DataStore::lookup_datastore(name, Some(Operation::Lookup)); + let _store = DataStore::lookup_datastore(name, Some(Operation::Lookup)); + + let mut datastore_cache = DATASTORE_MAP.lock().unwrap(); + if let Some((_, drop_from_cache)) = datastore_cache.get_mut(name) { + *drop_from_cache = true; } + drop(datastore_cache); + drop(_store); Ok(()) } diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 3081e1f4..0b3d92f9 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -389,10 +389,12 @@ pub fn update_datastore( data.tuning = update.tuning; } - let mut maintenance_mode_changed = false; + let mut drop_store_from_cache = false; if update.maintenance_mode.is_some() { - maintenance_mode_changed = data.maintenance_mode != update.maintenance_mode; data.maintenance_mode = update.maintenance_mode; + drop_store_from_cache = data + .get_maintenance_mode() + .map_or(false, |m| m.is_offline()); } config.set_data(&name, "datastore", &data)?; @@ -406,7 +408,7 @@ pub fn update_datastore( } // tell the proxy it might have to clear a cache entry - if maintenance_mode_changed { + if drop_store_from_cache { tokio::spawn(async move { if let Ok(proxy_pid) = proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN) -- 2.39.2