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 927731FF163 for ; Mon, 6 Oct 2025 12:42:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1DBAD753; Mon, 6 Oct 2025 12:42:06 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Mon, 6 Oct 2025 12:41:45 +0200 Message-ID: <20251006104151.487202-2-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251006104151.487202-1-c.ebner@proxmox.com> References: <20251006104151.487202-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1759747292975 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 1/7] datastore: gc: inline single callsite method 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" This method only has a single callsite and is better split by deduplicating common code in `ChunkStore::swipe_unused_chunks`. Therefore, inline the method in preparation for the following code deduplication. Signed-off-by: Christian Ebner --- pbs-datastore/src/datastore.rs | 127 +++++++++++++-------------------- 1 file changed, 49 insertions(+), 78 deletions(-) diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index 2e62590f9..c2a82b8b8 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -1653,21 +1653,56 @@ impl DataStore { let lock = self.inner.chunk_store.mutex().lock().unwrap(); for content in list_bucket_result.contents { - if self - .mark_chunk_for_object_key( - &content.key, - content.size, - min_atime, - oldest_writer, - &mut delete_list, - &mut gc_status, - ) - .with_context(|| { - format!("failed to mark chunk for object key {}", content.key) - })? - { - chunk_count += 1; + let (chunk_path, digest) = match self.chunk_path_from_object_key(&content.key) { + Some(path) => path, + None => continue, + }; + + // Check local markers (created or atime updated during phase1) and + // keep or delete chunk based on that. + let atime = match std::fs::metadata(&chunk_path) { + Ok(stat) => stat.accessed()?, + Err(err) if err.kind() == std::io::ErrorKind::NotFound => { + // File not found, delete by setting atime to unix epoch + info!("Not found, mark for deletion: {}", content.key); + SystemTime::UNIX_EPOCH + } + Err(err) => return Err(err.into()), + }; + let atime = atime.duration_since(SystemTime::UNIX_EPOCH)?.as_secs() as i64; + + let bad = chunk_path + .as_path() + .extension() + .is_some_and(|ext| ext == "bad"); + + if atime < min_atime { + if let Some(cache) = self.cache() { + // ignore errors, phase 3 will retry cleanup anyways + let _ = cache.remove(&digest); + } + delete_list.push(content.key.clone()); + if bad { + gc_status.removed_bad += 1; + } else { + gc_status.removed_chunks += 1; + } + gc_status.removed_bytes += content.size; + } else if atime < oldest_writer { + if bad { + gc_status.still_bad += 1; + } else { + gc_status.pending_chunks += 1; + } + gc_status.pending_bytes += content.size; + } else { + if !bad { + gc_status.disk_chunks += 1; + } + gc_status.disk_bytes += content.size; } + + chunk_count += 1; } drop(lock); @@ -1796,70 +1831,6 @@ impl DataStore { Ok(()) } - // Mark the chunk marker in the local cache store for the given object key as in use - // by updating it's atime. - // Returns Ok(true) if the chunk was updated and Ok(false) if the object was not a chunk. - fn mark_chunk_for_object_key( - &self, - object_key: &S3ObjectKey, - size: u64, - min_atime: i64, - oldest_writer: i64, - delete_list: &mut Vec, - gc_status: &mut GarbageCollectionStatus, - ) -> Result { - let (chunk_path, digest) = match self.chunk_path_from_object_key(object_key) { - Some(path) => path, - None => return Ok(false), - }; - - // Check local markers (created or atime updated during phase1) and - // keep or delete chunk based on that. - let atime = match std::fs::metadata(&chunk_path) { - Ok(stat) => stat.accessed()?, - Err(err) if err.kind() == std::io::ErrorKind::NotFound => { - // File not found, delete by setting atime to unix epoch - info!("Not found, mark for deletion: {object_key}"); - SystemTime::UNIX_EPOCH - } - Err(err) => return Err(err.into()), - }; - let atime = atime.duration_since(SystemTime::UNIX_EPOCH)?.as_secs() as i64; - - let bad = chunk_path - .as_path() - .extension() - .is_some_and(|ext| ext == "bad"); - - if atime < min_atime { - if let Some(cache) = self.cache() { - // ignore errors, phase 3 will retry cleanup anyways - let _ = cache.remove(&digest); - } - delete_list.push(object_key.clone()); - if bad { - gc_status.removed_bad += 1; - } else { - gc_status.removed_chunks += 1; - } - gc_status.removed_bytes += size; - } else if atime < oldest_writer { - if bad { - gc_status.still_bad += 1; - } else { - gc_status.pending_chunks += 1; - } - gc_status.pending_bytes += size; - } else { - if !bad { - gc_status.disk_chunks += 1; - } - gc_status.disk_bytes += size; - } - - Ok(true) - } - // Check and generate a chunk path from given object key fn chunk_path_from_object_key(&self, object_key: &S3ObjectKey) -> Option<(PathBuf, [u8; 32])> { // Check object is actually a chunk -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel