all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 1/4] GC: s3: fix local marker cleanup for unreferenced, s3 only chunks
Date: Mon, 24 Nov 2025 10:40:15 +0100	[thread overview]
Message-ID: <20251124094018.224661-2-c.ebner@proxmox.com> (raw)
In-Reply-To: <20251124094018.224661-1-c.ebner@proxmox.com>

If a chunk object is located on the s3 object store only, not being
referenced by any index file and having no local marker file it was
marked for cleanup by pretending an atime equal to the unix epoch.

While this will mark the chunk for deletion from the backend and
include it in the delete list for the next s3 delete objects call, it
also will lead to the chunk marker and LRU cache entry being tried to
clean up locally, which however failed since there is no marker to be
cleaned up.

In order to treat this edge case, instead of pretending an atime
equal to the unix epoch, make the atime optional and skip over the
atime check for that case altogether, directly pushing the object and
its guard to the delete list, while updating the gc status
accordingly.

Fixes: https://forum.proxmox.com/threads/176567/
Originally-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
Changes since version 1:
- Skip over cond_sweep_chunk altogether if the marker is not present and
  chunk no longer required

 pbs-datastore/src/datastore.rs | 68 +++++++++++++++++++---------------
 1 file changed, 39 insertions(+), 29 deletions(-)

diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index 65299cca9..1b489b449 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -1709,48 +1709,58 @@ impl DataStore {
                     // 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()?,
+                        Ok(stat) => Some(stat.accessed()?),
                         Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
                             if self.inner.chunk_store.clear_chunk_expected_mark(&digest)? {
                                 unsafe {
                                     // chunk store lock held
                                     self.inner.chunk_store.replace_chunk_with_marker(&digest)?;
                                 }
-                                SystemTime::now()
+                                Some(SystemTime::now())
                             } else {
-                                // File not found, delete by setting atime to unix epoch
-                                SystemTime::UNIX_EPOCH
+                                // File not found, only delete from S3
+                                None
                             }
                         }
                         Err(err) => return Err(err.into()),
                     };
-                    let atime = atime.duration_since(SystemTime::UNIX_EPOCH)?.as_secs() as i64;
-
-                    unsafe {
-                        self.inner.chunk_store.cond_sweep_chunk(
-                            atime,
-                            min_atime,
-                            oldest_writer,
-                            content.size,
-                            bad,
-                            &mut gc_status,
-                            || {
-                                if let Some(cache) = self.cache() {
-                                    if !bad {
-                                        cache.remove(&digest)?;
-                                    } else {
-                                        std::fs::remove_file(chunk_path)?;
+                    if let Some(atime) = atime {
+                        let atime = atime.duration_since(SystemTime::UNIX_EPOCH)?.as_secs() as i64;
+
+                        unsafe {
+                            self.inner.chunk_store.cond_sweep_chunk(
+                                atime,
+                                min_atime,
+                                oldest_writer,
+                                content.size,
+                                bad,
+                                &mut gc_status,
+                                || {
+                                    if let Some(cache) = self.cache() {
+                                        if !bad {
+                                            cache.remove(&digest)?;
+                                        } else {
+                                            std::fs::remove_file(chunk_path)?;
+                                        }
                                     }
-                                }
 
-                                // set age based on first insertion
-                                if delete_list.is_empty() {
-                                    delete_list_age = epoch_i64();
-                                }
-                                delete_list.push((content.key, _chunk_guard));
-                                Ok(())
-                            },
-                        )?;
+                                    // set age based on first insertion
+                                    if delete_list.is_empty() {
+                                        delete_list_age = epoch_i64();
+                                    }
+                                    delete_list.push((content.key, _chunk_guard));
+                                    Ok(())
+                                },
+                            )?;
+                        }
+                    } else {
+                        gc_status.removed_chunks += 1;
+                        gc_status.removed_bytes += content.size;
+                        // set age based on first insertion
+                        if delete_list.is_empty() {
+                            delete_list_age = epoch_i64();
+                        }
+                        delete_list.push((content.key, _chunk_guard));
                     }
 
                     chunk_count += 1;
-- 
2.47.3



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel

  reply	other threads:[~2025-11-24  9:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-24  9:40 [pbs-devel] [PATCH proxmox-backup v2 0/4] " Christian Ebner
2025-11-24  9:40 ` Christian Ebner [this message]
2025-11-24  9:40 ` [pbs-devel] [PATCH proxmox-backup v2 2/4] chunk store: fix and expand the clear_chunk_expected_mark() docstring Christian Ebner
2025-11-24  9:40 ` [pbs-devel] [PATCH proxmox-backup v2 3/4] chunk store: clarify chunk marker helper creates marker if missing Christian Ebner
2025-11-24  9:40 ` [pbs-devel] [PATCH proxmox-backup v2 4/4] datastore: refactor common delete list logic into closure Christian Ebner
2025-11-24 12:23 ` [pbs-devel] applied: [PATCH proxmox-backup v2 0/4] fix local marker cleanup for unreferenced, s3 only chunks Thomas Lamprecht
2025-11-24 12:51   ` Christian Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251124094018.224661-2-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal