From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 7A4C71FF14C for ; Fri, 15 May 2026 11:07:20 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E630412633; Fri, 15 May 2026 11:07:18 +0200 (CEST) From: Thomas Lamprecht To: Lukas Wagner Subject: Re: [PATCH datacenter-manager 3/4] api: resources: subscriptions: switch over to api_cache Date: Fri, 15 May 2026 11:06:31 +0200 Message-ID: <20260515090637.950992-3-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260513135457.573414-4-l.wagner@proxmox.com> References: <20260513135457.573414-1-l.wagner@proxmox.com> <20260513135457.573414-4-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1778835997482 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.004 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 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: UWTSQYUXIBGMYEAM45YDRV64JURL44UC X-Message-ID-Hash: UWTSQYUXIBGMYEAM45YDRV64JURL44UC X-MailFrom: t.lamprecht@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 CC: pdm-devel@lists.proxmox.com 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: On Wed, 13 May 2026 15:54:56 +0200, Lukas Wagner wrote:=0D > diff --git a/server/src/api/resources.rs b/server/src/api/resources.rs=0D > --- a/server/src/api/resources.rs=0D > +++ b/server/src/api/resources.rs=0D > @@ -815,66 +812,46 @@ pub async fn get_subscription_info_for_remote(=0D > remote: &Remote,=0D > max_age: u64,=0D > ) -> Result>, Error> {=0D > - if let Some(cached_subscription) =3D get_cached_subscription_info(&r= emote.id, max_age) {=0D > + if let Some(cached_subscription) =3D=0D > + get_cached_subscription_info(remote.id.clone(), max_age).await?= =0D > + {=0D > Ok(cached_subscription.node_info)=0D > } else {=0D > let node_info =3D fetch_remote_subscription_info(remote).await?;= =0D > - let now =3D proxmox_time::epoch_i64();=0D > - update_cached_subscription_info(&remote.id, &node_info, now);=0D > + update_cached_subscription_info(remote.id.clone(), node_info.clo= ne()).await?;=0D > Ok(node_info)=0D > }=0D > }=0D =0D Both helpers below only borrow their `remote` parameter (they pass=0D `&remote` into `api_cache::read_remote` / `write_remote`), so changing=0D their parameter type from `String` to `&str` would let this call site=0D stop cloning `remote.id` twice FWICT.=0D =0D The old `update_cached_subscription_info` used to compare timestamps and=0D skip the insert when the existing cache entry was already at least as=0D new:=0D =0D if let Some(cached_resource) =3D cache.get(remote) {=0D if cached_resource.timestamp >=3D now {=0D return;=0D }=0D }=0D cache.insert(...)=0D =0D The new code drops that check and just calls `set` unconditionally, so=0D under two concurrent misses for the same remote the slower fetch result=0D will overwrite the fresher one that arrived first. The fetch race itself=0D existed before too, but the compare-before-insert mitigated the worst=0D outcome (older data replacing newer). If you want to keep that property,=0D the new function would have to `get` the existing entry under the held=0D write lock and skip when its timestamp is already at least as new. See=0D also the doc-comment point below.=0D =0D [...]=0D > /// Update cached subscription data.=0D > ///=0D > /// If the cache already contains more recent data we don't insert the p= assed resources.=0D [...]=0D > +async fn update_cached_subscription_info(=0D > + remote: String,=0D > + node_info: HashMap>,=0D > +) -> Result<(), Error> {=0D > + let cache =3D api_cache::write_remote(&remote).await?;=0D >=0D > + Ok(cache=0D > + .set(=0D > + SUBSCRIPTION_STATE_CACHE_KEY,=0D > + CachedSubscriptionState {=0D > + node_info: node_info,=0D =0D nit: `node_info: node_info,` -> `node_info,` (clippy redundant_field_names)= .=0D =0D > + },=0D > + )=0D > + .await?)=0D > +}=0D =0D The doc comment above is the one that used to describe the=0D compare-before-insert behaviour from the old code. Either drop the doc=0D line (IMO not ideal), or restore the behaviour as discussed above.=0D