From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 3D5541FF0E7 for ; Fri, 10 Jul 2026 13:36:41 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C52E52146C; Fri, 10 Jul 2026 13:36:35 +0200 (CEST) Message-ID: <655cfb23-835d-456d-a2f8-5bc4ae0f7c07@proxmox.com> Date: Fri, 10 Jul 2026 13:36:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH datacenter-manager 04/15] task cache: rotate: align timestamp for new files to UTC midnight To: Lukas Wagner , pdm-devel@lists.proxmox.com References: <20260702092258.174740-1-l.wagner@proxmox.com> <20260702092258.174740-5-l.wagner@proxmox.com> Content-Language: en-US From: Dominik Csapak In-Reply-To: <20260702092258.174740-5-l.wagner@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1783683351173 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.057 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) 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: 4CLGUIQACJSS5BRXCWHAPK7F326STYRR X-Message-ID-Hash: 4CLGUIQACJSS5BRXCWHAPK7F326STYRR X-MailFrom: d.csapak@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: wouldn't it make more sense to put the alignment inside rotate? so potential future callers can't miss this? also the init cache function does not align the timestamp so it's aligned only after rotation, is that intended? On 7/2/26 11:23 AM, Lukas Wagner wrote: > 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 > --- > server/src/remote_tasks/refresh_task.rs | 23 ++++++++++++++++++++++- > server/src/remote_tasks/task_cache.rs | 3 ++- > 2 files changed, 24 insertions(+), 2 deletions(-) > > diff --git a/server/src/remote_tasks/refresh_task.rs b/server/src/remote_tasks/refresh_task.rs > index 68ef5a25..55d5694e 100644 > --- a/server/src/remote_tasks/refresh_task.rs > +++ b/server/src/remote_tasks/refresh_task.rs > @@ -360,7 +360,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 +547,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)?; > } > }