mirror of
https://github.com/rustfs/rustfs.git
synced 2026-12-01 13:44:49 +00:00
perf(scanner): skip redundant snapshot coverage checks
Use the sealed frontier when available and validate only compacted receipts whose ranges can cover a missing frontier. Co-Authored-By: heihutu <heihutu@gmail.com> Co-Authored-By: zhi22915 <qiuzgang@gmail.com> Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>
This commit is contained in:
@@ -1693,16 +1693,14 @@ impl FolderScanner {
|
||||
snapshot.seal_scan_frontier(self.coverage_frontier.as_deref()).ok()?;
|
||||
// A resumed readdir can run before covered subtrees are copied. Keep
|
||||
// its durable receipt until this snapshot can represent that coverage.
|
||||
let compacted_work = snapshot
|
||||
.info
|
||||
.scan_directory_work
|
||||
.iter()
|
||||
.filter_map(|directory| directory.progress(&snapshot.info));
|
||||
if self
|
||||
.coverage_frontier
|
||||
.as_deref()
|
||||
.is_some_and(|frontier| !compacted_work.clone().any(|proof| proof.covers(frontier)))
|
||||
&& snapshot.info.scan_coverage_receipt.is_none()
|
||||
if snapshot.info.scan_coverage_receipt.is_none()
|
||||
&& self.coverage_frontier.as_deref().is_some_and(|frontier| {
|
||||
!snapshot
|
||||
.info
|
||||
.scan_directory_work
|
||||
.iter()
|
||||
.any(|directory| directory.covers_bound_path(&snapshot.info, frontier))
|
||||
})
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -206,13 +206,17 @@ impl DirectoryProgress {
|
||||
self.same_source(previous) && self.through >= previous.through
|
||||
}
|
||||
pub(crate) fn covers(&self, path: &str) -> bool {
|
||||
path.strip_prefix(&self.parent)
|
||||
.and_then(|tail| tail.strip_prefix('/'))
|
||||
.and_then(|tail| tail.split('/').next())
|
||||
.is_some_and(|child| child <= self.through.as_str())
|
||||
compacted_child_covers(&self.parent, &self.through, path)
|
||||
}
|
||||
}
|
||||
|
||||
fn compacted_child_covers(parent: &str, through: &str, path: &str) -> bool {
|
||||
path.strip_prefix(parent)
|
||||
.and_then(|tail| tail.strip_prefix('/'))
|
||||
.and_then(|tail| tail.split('/').next())
|
||||
.is_some_and(|child| child <= through)
|
||||
}
|
||||
|
||||
impl DirectoryCheckpoint {
|
||||
/// Deserialize each replica's independent receipt, then intern equal
|
||||
/// verified immutable name pages across the bucket's active directories.
|
||||
@@ -320,6 +324,11 @@ impl DirectoryCheckpoint {
|
||||
let manifest = self.bound_manifest(info)?;
|
||||
Some(self.compacted_progress(physical, manifest, &done.through))
|
||||
}
|
||||
pub(crate) fn covers_bound_path(&self, info: &DataUsageCacheInfo, path: &str) -> bool {
|
||||
self.aggregate
|
||||
.as_ref()
|
||||
.is_some_and(|done| compacted_child_covers(&self.parent, &done.through, path) && self.is_bound_to(info))
|
||||
}
|
||||
/// A display contribution contains only acknowledged compacted children.
|
||||
pub(crate) fn display_usage(&self, info: &DataUsageCacheInfo) -> Option<(DirectoryProgress, &DataUsageEntry, Option<u64>)> {
|
||||
Some((self.progress(info)?, &self.aggregate.as_ref()?.value, self.measured_at))
|
||||
|
||||
@@ -121,10 +121,23 @@ async fn display_progress_measurement_metadata_keeps_version_one_checkpoint_comp
|
||||
.expect("same validated receipt provides display usage");
|
||||
assert!(compacted.extends(&display) && display.extends(&compacted));
|
||||
assert_eq!(value.objects, 2);
|
||||
let covered = "bucket/obj-000001/nested";
|
||||
assert!(recovered.covers_bound_path(&info, covered));
|
||||
assert!(!recovered.covers_bound_path(&info, "bucket/obj-000002/nested"));
|
||||
assert!(!recovered.covers_bound_path(&info, "bucket-sibling/obj-000001"));
|
||||
let other_incarnation = DataUsageCacheInfo {
|
||||
scan_identity: info.scan_identity.map(|identity| DataUsageScanIdentity {
|
||||
bucket_incarnation: uuid::Uuid::from_u128(2),
|
||||
..identity
|
||||
}),
|
||||
..info.clone()
|
||||
};
|
||||
assert!(!recovered.covers_bound_path(&other_incarnation, covered));
|
||||
|
||||
let mut damaged = recovered;
|
||||
damaged.digest[0] ^= 1;
|
||||
assert!(matches!(damaged.scheduling_progress(&info), (None, None)));
|
||||
assert!(!damaged.covers_bound_path(&info, covered));
|
||||
assert!(damaged.display_usage(&info).is_none());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user