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 E8B721FF183 for ; Wed, 8 Oct 2025 17:21:40 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BFC53C1FA; Wed, 8 Oct 2025 17:21:43 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Wed, 8 Oct 2025 17:21:19 +0200 Message-ID: <20251008152125.849216-7-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251008152125.849216-1-c.ebner@proxmox.com> References: <20251008152125.849216-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1759936867648 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.043 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 Subject: [pbs-devel] [PATCH proxmox-backup v2 06/12] local store cache: refactor fetch and insert of chunks for s3 backend X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Move the common logic for both, the fetching when no local chunk marker file is found and when the marker file has no content into a common helper. This is in preparation for further restructuring in the following patches/commits. Signed-off-by: Christian Ebner --- .../src/local_datastore_lru_cache.rs | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/pbs-datastore/src/local_datastore_lru_cache.rs b/pbs-datastore/src/local_datastore_lru_cache.rs index 7d0b3e114..ea92bc9b3 100644 --- a/pbs-datastore/src/local_datastore_lru_cache.rs +++ b/pbs-datastore/src/local_datastore_lru_cache.rs @@ -115,18 +115,8 @@ impl LocalDatastoreLruCache { // Expected chunk to be present since LRU cache has it, but it is missing // locally, try to fetch again if err.kind() == std::io::ErrorKind::NotFound { - let object_key = crate::s3::object_key_from_digest(digest)?; - match cacher.client.get_object(object_key).await? { - None => { - bail!("could not fetch object with key {}", hex::encode(digest)) - } - Some(response) => { - let bytes = response.content.collect().await?.to_bytes(); - let chunk = DataBlob::from_raw(bytes.to_vec())?; - self.store.insert_chunk(&chunk, digest)?; - return Ok(Some(chunk)); - } - } + let chunk = self.fetch_and_insert(cacher.client.clone(), digest).await?; + return Ok(Some(chunk)); } else { return Err(Error::from(err)); } @@ -138,18 +128,8 @@ impl LocalDatastoreLruCache { use std::io::Seek; // Check if file is empty marker file, try fetching content if so if file.seek(std::io::SeekFrom::End(0))? == 0 { - let object_key = crate::s3::object_key_from_digest(digest)?; - match cacher.client.get_object(object_key).await? { - None => { - bail!("could not fetch object with key {}", hex::encode(digest)) - } - Some(response) => { - let bytes = response.content.collect().await?.to_bytes(); - let chunk = DataBlob::from_raw(bytes.to_vec())?; - self.store.insert_chunk(&chunk, digest)?; - return Ok(Some(chunk)); - } - } + let chunk = self.fetch_and_insert(cacher.client.clone(), digest).await?; + return Ok(Some(chunk)); } else { return Err(err); } @@ -165,4 +145,23 @@ impl LocalDatastoreLruCache { pub fn contains(&self, digest: &[u8; 32]) -> bool { self.cache.contains(*digest) } + + async fn fetch_and_insert( + &self, + client: Arc, + digest: &[u8; 32], + ) -> Result { + let object_key = crate::s3::object_key_from_digest(digest)?; + match client.get_object(object_key).await? { + None => { + bail!("could not fetch object with key {}", hex::encode(digest)) + } + Some(response) => { + let bytes = response.content.collect().await?.to_bytes(); + let chunk = DataBlob::from_raw(bytes.to_vec())?; + self.store.insert_chunk(&chunk, digest)?; + Ok(chunk) + } + } + } } -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel