all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 2/2] server: remote task cache: improve handling of missing archive files
Date: Wed,  3 Sep 2025 16:48:52 +0200	[thread overview]
Message-ID: <20250903144852.370452-3-l.wagner@proxmox.com> (raw)
In-Reply-To: <20250903144852.370452-1-l.wagner@proxmox.com>

This avoids misleading 'could not create task iterator' errors in some
cases, for instance when requesting a task list when the 'active' is
missing/has not been created yet.

The changed handling allows us to skip creating the 'active' file in
'init', it will be created when needed.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 server/src/remote_tasks/task_cache.rs | 64 +++++++++++++--------------
 1 file changed, 31 insertions(+), 33 deletions(-)

diff --git a/server/src/remote_tasks/task_cache.rs b/server/src/remote_tasks/task_cache.rs
index 57047c8c..aa038443 100644
--- a/server/src/remote_tasks/task_cache.rs
+++ b/server/src/remote_tasks/task_cache.rs
@@ -214,19 +214,6 @@ impl WritableTaskCache {
     ///
     /// This function only has an effect if there are no archive files yet.
     pub fn init(&self, now: i64) -> Result<(), Error> {
-        let active_filename = self.cache.base_path.join(ACTIVE_FILENAME);
-
-        if !active_filename.exists() {
-            let mut file = OpenOptions::new()
-                .create(true)
-                .write(true)
-                .open(&active_filename)?;
-
-            self.cache
-                .create_options
-                .apply_to(&mut file, &active_filename)?;
-        }
-
         if self.cache.archive_files(&self.lock)?.is_empty() {
             for i in 0..self.cache.max_files {
                 self.new_file(
@@ -694,6 +681,12 @@ impl WritableTaskCache {
 
         let archive_iter = file
             .iter()?
+            .with_context(|| {
+                format!(
+                    "task archive file '{}' disappeared while merging tasks",
+                    file.path.display()
+                )
+            })?
             .flat_map(|item| match item {
                 Ok(item) => Some(item),
                 Err(err) => {
@@ -819,33 +812,28 @@ impl TaskCache {
         lock: &'a TaskCacheLock,
     ) -> Result<TaskArchiveIterator<'a>, Error> {
         let journal_file = self.base_path.join(WAL_FILENAME);
-        let active_path = self.base_path.join(ACTIVE_FILENAME);
 
         match mode {
             GetTasks::All => {
                 let mut archive_files = self.archive_files(lock)?;
                 archive_files.reverse();
 
-                if active_path.exists() {
-                    archive_files.push(ArchiveFile {
-                        path: self.base_path.join(ACTIVE_FILENAME),
-                        compressed: false,
-                        starttime: 0,
-                    });
-                }
+                archive_files.push(ArchiveFile {
+                    path: self.base_path.join(ACTIVE_FILENAME),
+                    compressed: false,
+                    starttime: 0,
+                });
 
                 TaskArchiveIterator::new(Some(journal_file), archive_files, lock)
             }
             GetTasks::Active => {
                 let mut archive_files = Vec::new();
 
-                if active_path.exists() {
-                    archive_files.push(ArchiveFile {
-                        path: self.base_path.join(ACTIVE_FILENAME),
-                        compressed: false,
-                        starttime: 0,
-                    });
-                }
+                archive_files.push(ArchiveFile {
+                    path: self.base_path.join(ACTIVE_FILENAME),
+                    compressed: false,
+                    starttime: 0,
+                });
 
                 TaskArchiveIterator::new(None, archive_files, lock)
             }
@@ -1026,10 +1014,13 @@ impl Iterator for InnerTaskArchiveIterator {
                     let next_file = self.files.pop()?;
 
                     match next_file.iter() {
-                        Ok(iter) => {
+                        Ok(Some(iter)) => {
                             self.current = Some(iter);
                             break 'inner;
                         }
+                        Ok(None) => {
+                            // File does not exist, nothing to log in this case.
+                        }
                         Err(err) => {
                             log::error!("could not create archive iterator while iteration over task archive files, skipping: {err:#}")
                         }
@@ -1053,9 +1044,16 @@ struct ArchiveFile {
 
 impl ArchiveFile {
     /// Create an [`ArchiveIterator`] for this file.
-    fn iter(&self) -> Result<ArchiveIterator, Error> {
-        let fd = File::open(&self.path)
-            .with_context(|| format!("failed to open archive file {}", self.path.display()))?;
+    fn iter(&self) -> Result<Option<ArchiveIterator>, Error> {
+        let fd = match File::open(&self.path) {
+            Ok(fd) => fd,
+            Err(err) if err.kind() == ErrorKind::NotFound => {
+                return Ok(None);
+            }
+            Err(err) => {
+                return Err(err.into());
+            }
+        };
 
         let iter = if self.compressed {
             let reader = zstd::stream::read::Decoder::new(fd).with_context(|| {
@@ -1069,7 +1067,7 @@ impl ArchiveFile {
             ArchiveIterator::new(Box::new(BufReader::new(fd)))
         };
 
-        Ok(iter)
+        Ok(Some(iter))
     }
 
     fn compress(&mut self, options: CreateOptions) -> Result<(), Error> {
-- 
2.47.2



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


  parent reply	other threads:[~2025-09-03 14:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-03 14:48 [pdm-devel] [PATCH proxmox-datacenter-manager 0/2] improve handling of missing task cache files Lukas Wagner
2025-09-03 14:48 ` [pdm-devel] [PATCH proxmox-datacenter-manager 1/2] server: remote task archive: handle missing journal file gracefully Lukas Wagner
2025-09-03 14:48 ` Lukas Wagner [this message]
2025-09-03 15:01 ` [pdm-devel] applied-series: [PATCH proxmox-datacenter-manager 0/2] improve handling of missing task cache files Thomas Lamprecht

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=20250903144852.370452-3-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pdm-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