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 v4 proxmox-backup 1/2] garbage collection: distinguish variants for failed open index reader
Date: Wed, 16 Apr 2025 11:17:17 +0200	[thread overview]
Message-ID: <20250416091718.182071-2-c.ebner@proxmox.com> (raw)
In-Reply-To: <20250416091718.182071-1-c.ebner@proxmox.com>

In preparation for adapting the garbage collection to be able to
distinguish cases for the index file not being accessible because it
is no longer present or because it is a blob and therefore should be
ignored.

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

diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index aa38e2ac1..4630b1b39 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -1033,11 +1033,14 @@ impl DataStore {
 
     // Similar to open index, but ignore index files with blob or unknown archive type.
     // Further, do not fail if file vanished.
-    fn open_index_reader(&self, absolute_path: &Path) -> Result<Option<Box<dyn IndexFile>>, Error> {
+    fn open_index_reader(
+        &self,
+        absolute_path: &Path,
+    ) -> Result<IndexReaderOption<Box<dyn IndexFile>>, Error> {
         let archive_type = match ArchiveType::from_path(absolute_path) {
-            Ok(archive_type) => archive_type,
             // ignore archives with unknown archive type
-            Err(_) => return Ok(None),
+            Ok(ArchiveType::Blob) | Err(_) => return Ok(IndexReaderOption::NoneWrongType),
+            Ok(archive_type) => archive_type,
         };
 
         if absolute_path.is_relative() {
@@ -1047,7 +1050,9 @@ impl DataStore {
         let file = match std::fs::File::open(absolute_path) {
             Ok(file) => file,
             // ignore vanished files
-            Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(None),
+            Err(err) if err.kind() == io::ErrorKind::NotFound => {
+                return Ok(IndexReaderOption::NoneNotFound)
+            }
             Err(err) => {
                 return Err(Error::from(err).context(format!("can't open file '{absolute_path:?}'")))
             }
@@ -1057,14 +1062,14 @@ impl DataStore {
             ArchiveType::FixedIndex => {
                 let reader = FixedIndexReader::new(file)
                     .with_context(|| format!("can't open fixed index '{absolute_path:?}'"))?;
-                Ok(Some(Box::new(reader)))
+                Ok(IndexReaderOption::Some(Box::new(reader)))
             }
             ArchiveType::DynamicIndex => {
                 let reader = DynamicIndexReader::new(file)
                     .with_context(|| format!("can't open dynamic index '{absolute_path:?}'"))?;
-                Ok(Some(Box::new(reader)))
+                Ok(IndexReaderOption::Some(Box::new(reader)))
             }
-            ArchiveType::Blob => Ok(None),
+            ArchiveType::Blob => Ok(IndexReaderOption::NoneWrongType),
         }
     }
 
@@ -1155,8 +1160,8 @@ impl DataStore {
                         path.push(file);
 
                         let index = match self.open_index_reader(&path)? {
-                            Some(index) => index,
-                            None => {
+                            IndexReaderOption::Some(index) => index,
+                            IndexReaderOption::NoneWrongType | IndexReaderOption::NoneNotFound => {
                                 unprocessed_index_list.remove(&path);
                                 continue;
                             }
@@ -1191,8 +1196,8 @@ impl DataStore {
         let mut strange_paths_count = unprocessed_index_list.len();
         for path in unprocessed_index_list {
             let index = match self.open_index_reader(&path)? {
-                Some(index) => index,
-                None => {
+                IndexReaderOption::Some(index) => index,
+                IndexReaderOption::NoneWrongType | IndexReaderOption::NoneNotFound => {
                     // do not count vanished (pruned) backup snapshots as strange paths.
                     strange_paths_count -= 1;
                     continue;
@@ -1695,3 +1700,9 @@ impl DataStore {
         *OLD_LOCKING
     }
 }
+
+enum IndexReaderOption<T> {
+    Some(T),
+    NoneWrongType,
+    NoneNotFound,
+}
-- 
2.39.5



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


  reply	other threads:[~2025-04-16  9:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-16  9:17 [pbs-devel] [PATCH v4 proxmox-backup 0/2] fix rare race in garbage collection Christian Ebner
2025-04-16  9:17 ` Christian Ebner [this message]
2025-04-16 10:00   ` [pbs-devel] [PATCH v4 proxmox-backup 1/2] garbage collection: distinguish variants for failed open index reader Fabian Grünbichler
2025-04-16  9:17 ` [pbs-devel] [PATCH v4 proxmox-backup 2/2] garbage collection: fix rare race in chunk marking phase Christian Ebner
2025-04-16 10:00   ` Fabian Grünbichler
2025-04-16 10:51 ` [pbs-devel] superseded: [PATCH v4 proxmox-backup 0/2] fix rare race in garbage collection 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=20250416091718.182071-2-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