From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id 49A6F1FF172
	for <inbox@lore.proxmox.com>; Wed, 16 Apr 2025 11:17:36 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 1CF5D31572;
	Wed, 16 Apr 2025 11:17:34 +0200 (CEST)
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Wed, 16 Apr 2025 11:17:17 +0200
Message-Id: <20250416091718.182071-2-c.ebner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250416091718.182071-1-c.ebner@proxmox.com>
References: <20250416091718.182071-1-c.ebner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.028 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [datastore.rs]
Subject: [pbs-devel] [PATCH v4 proxmox-backup 1/2] garbage collection:
 distinguish variants for failed open index reader
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.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