[pbs-devel] [PATCH] datastore: fix problem with operations counting

Hannes Laimer h.laimer at proxmox.com
Thu Apr 25 10:32:11 CEST 2024


... if `.chunks/` is not available(deleted/moved) ChunkStore::open
fails, but that would happen after updating the active operations on the
datastore, so no reference that could be dropped is returned. Leading to
the operations counter to always increase. This only updates the counter
when a reference is returned, not before.

Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
---
 pbs-datastore/src/datastore.rs | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index f95da761..2f8952ae 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -158,10 +158,6 @@ impl DataStore {
             }
         }
 
-        if let Some(operation) = operation {
-            update_active_operations(name, operation, 1)?;
-        }
-
         // Our operation is registered, unlock the config.
         drop(config_lock);
 
@@ -172,6 +168,9 @@ impl DataStore {
         let chunk_store = if let Some(datastore) = &entry {
             let last_digest = datastore.last_digest.as_ref();
             if let Some(true) = last_digest.map(|last_digest| last_digest == &digest) {
+                if let Some(operation) = operation {
+                    update_active_operations(name, operation, 1)?;
+                }
                 return Ok(Arc::new(Self {
                     inner: Arc::clone(datastore),
                     operation,
@@ -195,6 +194,10 @@ impl DataStore {
         let datastore = Arc::new(datastore);
         datastore_cache.insert(name.to_string(), datastore.clone());
 
+        if let Some(operation) = operation {
+            update_active_operations(name, operation, 1)?;
+        }
+
         Ok(Arc::new(Self {
             inner: datastore,
             operation,
-- 
2.39.2





More information about the pbs-devel mailing list