public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup 07/10] bin: debug: refactor and deduplicate chunk range difference check
Date: Tue, 17 Nov 2026 16:28:11 +0100	[thread overview]
Message-ID: <20261117152814.491323-8-c.ebner@proxmox.com> (raw)
In-Reply-To: <20261117152814.491323-1-c.ebner@proxmox.com>

Refactor the chunk range lookup logic into a dedicated helper function
and deduplicate the chunk difference check. It is currently performed
for directories as well as file entries, but can be performed upfront.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 src/bin/proxmox_backup_debug/diff.rs | 76 +++++++++++++++-------------
 1 file changed, 42 insertions(+), 34 deletions(-)

diff --git a/src/bin/proxmox_backup_debug/diff.rs b/src/bin/proxmox_backup_debug/diff.rs
index caacea21e..06f89f26b 100644
--- a/src/bin/proxmox_backup_debug/diff.rs
+++ b/src/bin/proxmox_backup_debug/diff.rs
@@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet};
 use std::ffi::{OsStr, OsString};
 use std::io::{IsTerminal, Write};
 use std::iter::FromIterator;
+use std::ops::Range;
 use std::path::{Path, PathBuf};
 use std::sync::Arc;
 
@@ -346,6 +347,35 @@ async fn files_in_chunk_set<'c, 'f>(
     visit_directory(&root, index, &path, chunk_list, chunk_set).await
 }
 
+fn range_contains_changed_chunk(
+    range: &Range<u64>,
+    index: &dyn IndexFile,
+    chunk_list: &[&ChunkDigest],
+    chunk_diff: &HashSet<&ChunkDigest>,
+) -> Result<bool, Error> {
+    if range.is_empty() {
+        return Ok(false);
+    }
+
+    let first_chunk = index
+        .chunk_from_offset(range.start)
+        .context("Invalid offset")?
+        .chunk_pos;
+    let last_chunk = index
+        .chunk_from_offset(range.end - 1)
+        .context("Invalid offset")?
+        .chunk_pos;
+
+    for chunk_index in first_chunk..=last_chunk {
+        let digest = chunk_list.get(chunk_index).context("Invalid chunk index")?;
+        if chunk_diff.contains(digest) {
+            return Ok(true);
+        }
+    }
+
+    Ok(false)
+}
+
 /// Recursively visits directories in .pxar archive and create a
 /// map "digest --> set of contained files"
 fn visit_directory<'f, 'c>(
@@ -364,47 +394,25 @@ fn visit_directory<'f, 'c>(
             let entry = entry?.decode_entry().await?;
             let range = &entry.entry_range_info().entry_range;
 
-            let first_chunk = index
-                .chunk_from_offset(range.start)
-                .context("Invalid offset")?
-                .chunk_pos;
-            let last_chunk = index
-                .chunk_from_offset(range.end - 1)
-                .context("Invalid offset")?
-                .chunk_pos;
+            // Check if any chunk of the entry is in the set of modified chunks (symmetric
+            // difference). If not, we can skip directories entirely and save a lot of time.
+            let entry_changed = range_contains_changed_chunk(range, index, chunk_list, chunk_diff)?;
+
+            if !entry_changed {
+                continue;
+            }
 
             if entry.is_dir() {
                 let new_dir = entry.enter_directory().await?;
+                let dir_path = path.join(entry.file_name());
 
-                for chunk_index in first_chunk..=last_chunk {
-                    // Check if any chunk of the serialized directory is in
-                    // set off modified chunks (symmetric difference).
-                    // If not, we can skip the directory entirely and save a lot of time.
-
-                    let digest = chunk_list.get(chunk_index).context("Invalid chunk index")?;
-
-                    if chunk_diff.get(digest).is_some() {
-                        let dir_path = path.join(entry.file_name());
-
-                        entries.extend(
-                            visit_directory(&new_dir, index, &dir_path, chunk_list, chunk_diff)
-                                .await?,
-                        );
-                        break;
-                    }
-                }
+                entries.extend(
+                    visit_directory(&new_dir, index, &dir_path, chunk_list, chunk_diff).await?,
+                );
             }
 
             let file_path = path.join(entry.file_name());
-
-            for chunk_index in first_chunk..=last_chunk {
-                let digest = chunk_list.get(chunk_index).context("Invalid chunk index")?;
-
-                if chunk_diff.get(digest).is_some() {
-                    entries.insert(file_path.into_os_string(), entry);
-                    break;
-                }
-            }
+            entries.insert(file_path.into_os_string(), entry);
         }
 
         Ok(entries)
-- 
2.47.3





  parent reply	other threads:[~2026-11-17 15:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 15:28 [PATCH proxmox-backup/pxar 00/10] fix #8319: support split pxar archives in proxmox-backup-debug diff Christian Ebner
2026-11-17 15:28 ` [PATCH pxar 01/10] encoder: record metadata-only goodbye size for split archive files Christian Ebner
2026-11-17 15:28 ` [PATCH pxar 02/10] accessor: limit split archive file entry ranges to payload reference Christian Ebner
2026-11-17 15:28 ` [PATCH pxar 03/10] accessor: add convenience helper to get content's byte range Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 04/10] datastore: index: return dedicated type for chunk offset trait method Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 05/10] bin: debug: fix off-by-one error in last chunk lookup Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 06/10] bin: debug: refactore dynamic index reader opening logic into helper Christian Ebner
2026-11-17 15:28 ` Christian Ebner [this message]
2026-11-17 15:28 ` [PATCH proxmox-backup 08/10] fix #8319: bin: debug: support split pxar archives via diff Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 09/10] bin: debug: use pxar related archive name helpers for diff Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 10/10] docs: debug: mention split pxar archives for diff subcommand 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=20261117152814.491323-8-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal