all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Shan Shaji <s.shaji@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup 4/6] client: backup_stats: move `uploaded_len` counter to `UploadCounters`
Date: Mon, 13 Jul 2026 10:15:27 +0200	[thread overview]
Message-ID: <20260713081529.62859-5-s.shaji@proxmox.com> (raw)
In-Reply-To: <20260713081529.62859-1-s.shaji@proxmox.com>

earlier the uploaded size was tracked using `uploaded_len` Arc counter.
Since the uploaded size needs to be accessible inside the progress logs
in the later commit, move the `uploaded_len` field to `UploadCounters`.

This was done, in order to avoid passing the variable as a separate
parameter through the callback.

Signed-off-by: Shan Shaji <s.shaji@proxmox.com>
---
 pbs-client/src/backup_stats.rs  | 12 ++++++++++++
 pbs-client/src/backup_writer.rs | 12 +++++-------
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/pbs-client/src/backup_stats.rs b/pbs-client/src/backup_stats.rs
index d7c13784b..6aceee331 100644
--- a/pbs-client/src/backup_stats.rs
+++ b/pbs-client/src/backup_stats.rs
@@ -50,6 +50,7 @@ pub(crate) struct UploadCounters {
     injected_stream_len: Arc<AtomicUsize>,
     reused_stream_len: Arc<AtomicUsize>,
     total_stream_len: Arc<AtomicUsize>,
+    uploaded_len: Arc<AtomicUsize>,
 }
 
 impl UploadCounters {
@@ -63,6 +64,7 @@ impl UploadCounters {
             injected_stream_len: Arc::new(AtomicUsize::new(0)),
             reused_stream_len: Arc::new(AtomicUsize::new(0)),
             total_stream_len: Arc::new(AtomicUsize::new(0)),
+            uploaded_len: Arc::new(AtomicUsize::new(0)),
         }
     }
 
@@ -101,6 +103,16 @@ impl UploadCounters {
         self.total_stream_len.load(Ordering::SeqCst)
     }
 
+    #[inline(always)]
+    pub(crate) fn add_uploaded_len(&mut self, size: usize) {
+        self.uploaded_len.fetch_add(size, Ordering::SeqCst);
+    }
+
+    #[inline(always)]
+    pub fn uploaded_len(&self) -> usize {
+        self.uploaded_len.load(Ordering::SeqCst)
+    }
+
     /// Convert the counters to [`UploadStats`], including given archive checksum and runtime.
     #[inline(always)]
     pub(crate) fn to_upload_stats(&self, csum: [u8; 32], duration: Duration) -> UploadStats {
diff --git a/pbs-client/src/backup_writer.rs b/pbs-client/src/backup_writer.rs
index f0744ecaf..34d8db90b 100644
--- a/pbs-client/src/backup_writer.rs
+++ b/pbs-client/src/backup_writer.rs
@@ -1,6 +1,5 @@
 use std::collections::HashSet;
 use std::future::Future;
-use std::sync::atomic::{AtomicUsize, Ordering};
 use std::sync::{Arc, Mutex};
 use std::time::Instant;
 
@@ -588,7 +587,7 @@ impl BackupWriter {
         h2: H2Client,
         wid: u64,
         path: String,
-        uploaded: Arc<AtomicUsize>,
+        upload_counters: UploadCounters,
     ) -> (UploadQueueSender, UploadResultReceiver) {
         let (verify_queue_tx, verify_queue_rx) = mpsc::channel(64);
         let (verify_result_tx, verify_result_rx) = oneshot::channel();
@@ -606,10 +605,10 @@ impl BackupWriter {
                                     .map_err(Error::from)
                                     .and_then(H2Client::h2api_response)
                                     .and_then({
-                                        let uploaded = uploaded.clone();
+                                        let mut counters = upload_counters.clone();
                                         move |_result| {
                                             // account for uploaded bytes for progress output
-                                            uploaded.fetch_add(response.size, Ordering::SeqCst);
+                                            counters.add_uploaded_len(response.size);
                                             future::ok(MergedChunkInfo::Known(list))
                                         }
                                     })
@@ -871,10 +870,9 @@ impl BackupWriter {
         let upload_chunk_path = format!("{prefix}_chunk");
 
         let start_time = std::time::Instant::now();
-        let uploaded_len = Arc::new(AtomicUsize::new(0));
 
         let (upload_queue, upload_result) =
-            Self::append_chunk_queue(h2.clone(), wid, append_chunk_path, uploaded_len.clone());
+            Self::append_chunk_queue(h2.clone(), wid, append_chunk_path, counters.clone());
 
         let progress_handle = if archive.ends_with(".img.fidx")
             || archive.ends_with(".pxar.didx")
@@ -886,7 +884,7 @@ impl BackupWriter {
                     tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
 
                     let size = HumanByte::from(counters.total_stream_len());
-                    let size_uploaded = HumanByte::from(uploaded_len.load(Ordering::SeqCst));
+                    let size_uploaded = HumanByte::from(counters.uploaded_len());
                     let elapsed = TimeSpan::from(start_time.elapsed());
 
                     info!("processed {size} in {elapsed}, uploaded {size_uploaded}");
-- 
2.47.3





  parent reply	other threads:[~2026-07-13  8:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13  8:15 [PATCH proxmox-backup 0/6] fix #7024: add more information inside backup logs Shan Shaji
2026-07-13  8:15 ` [PATCH proxmox-backup 1/6] client: pxar: rename `ReuseStats` struct to PxarArchiverProgressStats Shan Shaji
2026-07-13  8:15 ` [PATCH proxmox-backup 2/6] client: pxar: use atomic values in `PxarArchiverProgressStats` Shan Shaji
2026-07-13  8:15 ` [PATCH proxmox-backup 3/6] fix #7024: pxar: show archiver summary for legacy and data mode Shan Shaji
2026-07-13  8:15 ` Shan Shaji [this message]
2026-07-13  8:15 ` [PATCH proxmox-backup 5/6] fix #7024: cli: add more information inside the backup progress logs Shan Shaji
2026-07-15 12:46   ` Thomas Ellmenreich
2026-07-15 14:06     ` Shan Shaji
2026-07-13  8:15 ` [PATCH proxmox-backup 6/6] fix #7024: cli: add option to enable verbose logs Shan Shaji

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=20260713081529.62859-5-s.shaji@proxmox.com \
    --to=s.shaji@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal