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 735D51FF13A for ; Wed, 27 May 2026 17:21:13 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A8C5432602; Wed, 27 May 2026 17:21:11 +0200 (CEST) From: Shannon Sterz To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager] server: location cache: also update cache if a location was removed Date: Wed, 27 May 2026 17:21:06 +0200 Message-ID: <20260527152106.436183-1-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1779895241815 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.110 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: 7H3HXTGFQIONNERF7QSBXKCHKPWKWPJQ X-Message-ID-Hash: 7H3HXTGFQIONNERF7QSBXKCHKPWKWPJQ X-MailFrom: s.sterz@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 removes all locations from the cache if the remote has no location anymore. otherwise clients may be served inconsitent data depending on how the max age property is set. showing no location when max-age is provided with a low value, but the cached location if it isn't. note that removing it would leave us in a race with newer writers as the `set_if_newer_with_timestamp` has no equivalent for remove. so set `None` in the cache instead for those cases. also this only affected removing the last (or only) location of a remote. if the location of a single node in a cluster with other locations was removed, that worked, because the entry would simply be dropped in the cached hashmap. Reported-by: Christoph Heiss Signed-off-by: Shannon Sterz --- server/src/location_cache.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/server/src/location_cache.rs b/server/src/location_cache.rs index bf73f36..9fe514b 100644 --- a/server/src/location_cache.rs +++ b/server/src/location_cache.rs @@ -39,20 +39,17 @@ pub async fn get_location_info_for_remote( get_cached_location_info(&remote.id, u64::MAX).await? } }; - let info = match location_info { - Some(info) => info, - None => return Ok(None), - }; + let now = proxmox_time::epoch_i64(); if let Some(existing_state) = - update_cached_location_info(&remote.id, info.clone(), now).await? + update_cached_location_info(&remote.id, location_info.clone(), now).await? { // Somebody else updated the cache while we performed the API request, // return the more recent data instead of the data we just fetched. return Ok(Some(existing_state)); } - Ok(Some(info)) + Ok(location_info) } } @@ -76,14 +73,15 @@ async fn get_cached_location_info( async fn update_cached_location_info( remote: &str, - info: CachedLocationInfo, + info: Option, now: i64, ) -> Result, Error> { let cache = api_cache::write_remote(remote).await?; Ok(cache .set_if_newer_with_timestamp(LOCATION_STATE_CACHE_KEY, info, now) - .await?) + .await? + .flatten()) } /// Parse a PVE location property string (from the datacenter or a node config) into our [Location]. -- 2.47.3