From 652b774eb0c8bdff3f7071495e9e140c4c4ddd24 Mon Sep 17 00:00:00 2001 From: Hannes Laimer Date: Mon, 25 Nov 2024 17:21:49 +0100 Subject: [PATCH] maintenance: make is_offline more generic ... and add MaintenanceType::Delete to it. We also want to clear any cach entries if we are deleting the datastore, not just if it is marked as offline. Signed-off-by: Hannes Laimer --- pbs-api-types/src/maintenance.rs | 7 +++---- pbs-datastore/src/datastore.rs | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pbs-api-types/src/maintenance.rs b/pbs-api-types/src/maintenance.rs index 1e3413dc..a7b8b078 100644 --- a/pbs-api-types/src/maintenance.rs +++ b/pbs-api-types/src/maintenance.rs @@ -77,10 +77,9 @@ pub struct MaintenanceMode { } impl MaintenanceMode { - /// Used for deciding whether the datastore is cleared from the internal cache after the last - /// task finishes, so all open files are closed. - pub fn is_offline(&self) -> bool { - self.ty == MaintenanceType::Offline + /// Used for deciding whether the datastore is cleared from the internal cache + pub fn clear_from_cache(&self) -> bool { + self.ty == MaintenanceType::Offline || self.ty == MaintenanceType::Delete } pub fn check(&self, operation: Option) -> Result<(), Error> { diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index 2755fed8..2bf2b843 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -116,7 +116,8 @@ impl Drop for DataStore { && 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()) + c.get_maintenance_mode() + .map_or(false, |m| m.clear_from_cache()) }); if remove_from_cache { @@ -216,7 +217,7 @@ impl DataStore { let datastore: DataStoreConfig = config.lookup("datastore", name)?; if datastore .get_maintenance_mode() - .map_or(false, |m| m.is_offline()) + .map_or(false, |m| m.clear_from_cache()) { // the datastore drop handler does the checking if tasks are running and clears the // cache entry, so we just have to trigger it here