From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id D12061FF0E1 for ; Mon, 13 Jul 2026 11:50:30 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id CAE60214F3; Mon, 13 Jul 2026 11:50:19 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager v2 04/15] task cache: rotate/init: align timestamp for new files to UTC midnight Date: Mon, 13 Jul 2026 11:49:26 +0200 Message-ID: <20260713094937.151838-5-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713094937.151838-1-l.wagner@proxmox.com> References: <20260713094937.151838-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1783936169024 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.312 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: XIRFW2SIJ5OZ64TBNALC7NN56PWKOMB6 X-Message-ID-Hash: XIRFW2SIJ5OZ64TBNALC7NN56PWKOMB6 X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This also requires to change the rotation check to an inclusive >=, otherwise we would only rotate after two days instead of every day. Signed-off-by: Lukas Wagner --- Notes: Changes since v1: - Also align timestamp for `init` call (thx @ Dominik) server/src/remote_tasks/refresh_task.rs | 28 +++++++++++++++++++++++-- server/src/remote_tasks/task_cache.rs | 3 ++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/server/src/remote_tasks/refresh_task.rs b/server/src/remote_tasks/refresh_task.rs index 68ef5a25..f77ce3af 100644 --- a/server/src/remote_tasks/refresh_task.rs +++ b/server/src/remote_tasks/refresh_task.rs @@ -216,7 +216,10 @@ pub async fn refresh_taskcache(remotes: Vec) -> Result<(), Error> { pub async fn init_cache() -> Result<(), Error> { tokio::task::spawn_blocking(|| { let cache = super::get_cache()?; - cache.write()?.init(proxmox_time::epoch_i64())?; + cache.write()?.init(align_timestamp( + proxmox_time::epoch_i64(), + ROTATE_AFTER as i64, + ))?; Ok(()) }) .await? @@ -360,7 +363,13 @@ fn get_remotes_with_finished_tasks( /// /// Returns Ok(true) the cache's files were rotated. async fn rotate_cache(cache: TaskCache) -> Result { - tokio::task::spawn_blocking(move || cache.write()?.rotate(proxmox_time::epoch_i64())).await? + tokio::task::spawn_blocking(move || { + cache.write()?.rotate(align_timestamp( + proxmox_time::epoch_i64(), + super::ROTATE_AFTER as i64, + )) + }) + .await? } /// Apply the task cache journal. @@ -541,3 +550,18 @@ async fn update_task_cache( }) .await? } + +/// Align a UNIX timestamp to the specified interval. +fn align_timestamp(now: i64, interval: i64) -> i64 { + now - (now.rem_euclid(interval)) +} + +#[cfg(test)] +mod tests { + use crate::remote_tasks::refresh_task::align_timestamp; + + #[test] + fn test_align_timestamp() { + assert_eq!(align_timestamp(1782898009, 24 * 3600), 1782864000); + } +} diff --git a/server/src/remote_tasks/task_cache.rs b/server/src/remote_tasks/task_cache.rs index b5fc3b21..55aa8b70 100644 --- a/server/src/remote_tasks/task_cache.rs +++ b/server/src/remote_tasks/task_cache.rs @@ -285,7 +285,8 @@ impl WritableTaskCache { match archive_files.first() { Some(bound) => { - if now > bound.starttime && now - bound.starttime > self.cache.rotate_after as i64 { + if now > bound.starttime && now - bound.starttime >= self.cache.rotate_after as i64 + { start_new_file(&mut archive_files)?; } } -- 2.47.3