all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/5] garbage collection: refactor archive type based chunk marking logic
Date: Fri, 21 Feb 2025 15:01:07 +0100	[thread overview]
Message-ID: <20250221140110.377328-3-c.ebner@proxmox.com> (raw)
In-Reply-To: <20250221140110.377328-1-c.ebner@proxmox.com>

Move the logic for marking in-use chunks by image files based on
archive type and its error handling into its own dedicated method.

This is in preparation for optimizing the iteration order to avoid
multiple atime updates of chunks. The method can then be reused for
both cases, iteration over expected image file paths and unexpected
paths, the latter being iterated separately.

No functional changes.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 pbs-datastore/src/datastore.rs | 48 ++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index a6a91ca79..eda78193d 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -1065,6 +1065,34 @@ impl DataStore {
         Ok(())
     }
 
+    fn mark_used_chunks_do(
+        &self,
+        img: &Path,
+        status: &mut GarbageCollectionStatus,
+        worker: &dyn WorkerTaskContext,
+    ) -> Result<(), Error> {
+        match std::fs::File::open(img) {
+            Ok(file) => {
+                if let Ok(archive_type) = ArchiveType::from_path(img) {
+                    if archive_type == ArchiveType::FixedIndex {
+                        let index = FixedIndexReader::new(file).map_err(|err| {
+                            format_err!("can't read index '{}' - {err}", img.to_string_lossy())
+                        })?;
+                        self.index_mark_used_chunks(index, img, status, worker)?;
+                    } else if archive_type == ArchiveType::DynamicIndex {
+                        let index = DynamicIndexReader::new(file).map_err(|err| {
+                            format_err!("can't read index '{}' - {err}", img.to_string_lossy())
+                        })?;
+                        self.index_mark_used_chunks(index, img, status, worker)?;
+                    }
+                }
+            }
+            Err(err) if err.kind() == io::ErrorKind::NotFound => (), // ignore vanished files
+            Err(err) => bail!("can't open index {} - {err}", img.to_string_lossy()),
+        }
+        Ok(())
+    }
+
     fn mark_used_chunks(
         &self,
         status: &mut GarbageCollectionStatus,
@@ -1090,25 +1118,7 @@ impl DataStore {
                 }
             }
 
-            match std::fs::File::open(&img) {
-                Ok(file) => {
-                    if let Ok(archive_type) = ArchiveType::from_path(&img) {
-                        if archive_type == ArchiveType::FixedIndex {
-                            let index = FixedIndexReader::new(file).map_err(|e| {
-                                format_err!("can't read index '{}' - {}", img.to_string_lossy(), e)
-                            })?;
-                            self.index_mark_used_chunks(index, &img, status, worker)?;
-                        } else if archive_type == ArchiveType::DynamicIndex {
-                            let index = DynamicIndexReader::new(file).map_err(|e| {
-                                format_err!("can't read index '{}' - {}", img.to_string_lossy(), e)
-                            })?;
-                            self.index_mark_used_chunks(index, &img, status, worker)?;
-                        }
-                    }
-                }
-                Err(err) if err.kind() == io::ErrorKind::NotFound => (), // ignore vanished files
-                Err(err) => bail!("can't open index {} - {}", img.to_string_lossy(), err),
-            }
+            self.mark_used_chunks_do(&img, status, worker)?;
 
             let percentage = (i + 1) * 100 / image_count;
             if percentage > last_percentage {
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  parent reply	other threads:[~2025-02-21 14:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21 14:01 [pbs-devel] [PATCH proxmox-backup 0/5] GC: avoid multiple atime updates Christian Ebner
2025-02-21 14:01 ` [pbs-devel] [PATCH proxmox-backup 1/5] datastore: restrict datastores list_images method scope to module Christian Ebner
2025-02-21 14:01 ` Christian Ebner [this message]
2025-02-21 14:01 ` [pbs-devel] [PATCH proxmox-backup 3/5] garbage collection: add structure for optimized image iteration Christian Ebner
2025-03-05 13:47   ` Fabian Grünbichler
2025-03-07  8:24     ` Christian Ebner
2025-03-07  8:53       ` Fabian Grünbichler
2025-03-07  8:59         ` Christian Ebner
2025-02-21 14:01 ` [pbs-devel] [PATCH proxmox-backup 4/5] garbage collection: allow to keep track of already touched chunks Christian Ebner
2025-02-21 14:01 ` [pbs-devel] [PATCH proxmox-backup 5/5] fix #5331: garbage collection: avoid multiple chunk atime updates Christian Ebner
2025-02-21 15:35 ` [pbs-devel] [PATCH proxmox-backup 0/5] GC: avoid multiple " Roland
2025-02-21 15:49   ` Christian Ebner
2025-02-22 17:50     ` Roland
2025-03-10 11:18 ` Christian Ebner

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=20250221140110.377328-3-c.ebner@proxmox.com \
    --to=c.ebner@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