From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id C67B21FF0AA for ; Tue, 17 Nov 2026 16:28:52 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id CC7EC216ED; Tue, 17 Nov 2026 16:28:35 +0100 (CET) From: Christian Ebner 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 Message-ID: <20261117152814.491323-8-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117152814.491323-1-c.ebner@proxmox.com> References: <20261117152814.491323-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794929311787 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.368 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: GE53G3NBIX3FS3ZWUT2GVPBTFIQYEAVE X-Message-ID-Hash: GE53G3NBIX3FS3ZWUT2GVPBTFIQYEAVE X-MailFrom: c.ebner@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 Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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, + index: &dyn IndexFile, + chunk_list: &[&ChunkDigest], + chunk_diff: &HashSet<&ChunkDigest>, +) -> Result { + 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