From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 62A001FF17C for ; Wed, 3 Sep 2025 16:49:18 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 73B1F11048; Wed, 3 Sep 2025 16:49:33 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Wed, 3 Sep 2025 16:48:52 +0200 Message-ID: <20250903144852.370452-3-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250903144852.370452-1-l.wagner@proxmox.com> References: <20250903144852.370452-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1756910925326 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.026 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 Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 2/2] server: remote task cache: improve handling of missing archive files X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" 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 --- 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, 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 { - let fd = File::open(&self.path) - .with_context(|| format!("failed to open archive file {}", self.path.display()))?; + fn iter(&self) -> Result, 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