From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [RFC FOLLOW-UP proxmox-backup 4/4] task tracking: simplify public interface
Date: Thu, 20 Nov 2025 10:01:39 +0100 [thread overview]
Message-ID: <20251120090342.195791-3-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20251120090342.195791-1-f.gruenbichler@proxmox.com>
instead of an update fn that is always called with 1 or -1, use add/remove_
wrappers.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
Notes:
we could go one step further, and make remove_ return whether it was the last
one, since that is basically the only thing we are interested in when calling
either helper..
pbs-datastore/src/datastore.rs | 12 ++++++------
pbs-datastore/src/task_tracking.rs | 16 +++++++++++++++-
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index 0a5179230..8bc58dcbb 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -43,7 +43,7 @@ use crate::fixed_index::{FixedIndexReader, FixedIndexWriter};
use crate::hierarchy::{ListGroups, ListGroupsType, ListNamespaces, ListNamespacesRecursive};
use crate::index::IndexFile;
use crate::s3::S3_CONTENT_PREFIX;
-use crate::task_tracking::{self, update_active_operations};
+use crate::task_tracking::{self, add_active_operation, remove_active_operation};
use crate::{DataBlob, LocalDatastoreLruCache};
static DATASTORE_MAP: LazyLock<Mutex<HashMap<String, Arc<DataStoreImpl>>>> =
@@ -175,7 +175,7 @@ impl Clone for DataStore {
fn clone(&self) -> Self {
let mut new_operation = self.operation;
if let Some(operation) = self.operation {
- if let Err(e) = update_active_operations(self.name(), operation, 1) {
+ if let Err(e) = add_active_operation(self.name(), operation) {
log::error!("could not update active operations - {}", e);
new_operation = None;
}
@@ -192,7 +192,7 @@ impl Drop for DataStore {
fn drop(&mut self) {
if let Some(operation) = self.operation {
let mut last_task = false;
- match update_active_operations(self.name(), operation, -1) {
+ match remove_active_operation(self.name(), operation) {
Err(e) => log::error!("could not update active operations - {}", e),
Ok(updated_operations) => {
last_task = updated_operations.read + updated_operations.write == 0;
@@ -356,7 +356,7 @@ impl DataStore {
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)?;
+ add_active_operation(name, operation)?;
}
return Ok(Arc::new(Self {
inner: Arc::clone(datastore),
@@ -382,7 +382,7 @@ impl DataStore {
datastore_cache.insert(name.to_string(), datastore.clone());
if let Some(operation) = operation {
- update_active_operations(name, operation, 1)?;
+ add_active_operation(name, operation)?;
}
Ok(Arc::new(Self {
@@ -469,7 +469,7 @@ impl DataStore {
)?);
if let Some(operation) = operation {
- update_active_operations(&name, operation, 1)?;
+ add_active_operation(&name, operation)?;
}
Ok(Arc::new(Self { inner, operation }))
diff --git a/pbs-datastore/src/task_tracking.rs b/pbs-datastore/src/task_tracking.rs
index b7e569efb..f4f6c57e7 100644
--- a/pbs-datastore/src/task_tracking.rs
+++ b/pbs-datastore/src/task_tracking.rs
@@ -91,7 +91,21 @@ pub fn get_active_operations_locked(
Ok((data, lock.unwrap()))
}
-pub fn update_active_operations(
+pub fn add_active_operation(
+ name: &str,
+ operation: Operation,
+) -> Result<ActiveOperationStats, Error> {
+ update_active_operations(name, operation, 1)
+}
+
+pub fn remove_active_operation(
+ name: &str,
+ operation: Operation,
+) -> Result<ActiveOperationStats, Error> {
+ update_active_operations(name, operation, -1)
+}
+
+fn update_active_operations(
name: &str,
operation: Operation,
mut count: i64,
--
2.47.3
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2025-11-20 9:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 6:02 [pbs-devel] [PATCH proxmox-backup v2] task tracking: improve pruning and fix accounting for missing entries Hannes Laimer
2025-11-20 9:01 ` [pbs-devel] [PATCH FOLLOW-UP proxmox-backup 2/4] task tracking: actually reset entry if desynced Fabian Grünbichler
2025-11-20 9:01 ` [pbs-devel] [PATCH FOLLOW-UP proxmox-backup 3/4] task tracking: refactor code Fabian Grünbichler
2025-11-20 9:01 ` Fabian Grünbichler [this message]
2025-11-20 9:37 ` [pbs-devel] [PATCH FOLLOW-UP proxmox-backup 2/4] task tracking: actually reset entry if desynced Hannes Laimer
2025-11-20 10:22 ` Fabian Grünbichler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251120090342.195791-3-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox