Compare commits

..

4 Commits

Author SHA1 Message Date
Hauser Zhi 6dccb2cd93 perf(scanner): reuse frontier digest at leader handoff
Validate the saved frontier once during checkpoint preparation and reuse its digest when retaining or migrating an accepted receipt. Preserve exact scope checks and validate legacy digest domains before migration.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>
2026-12-01 20:55:26 +08:00
Hauser Zhi de8eace204 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>
2026-12-01 18:31:48 +08:00
Hauser Zhi 825e296f98 perf(scanner): bound directory progress lookups by path
Match checkpoint progress within each parent path while retaining exact replica and manifest checks. Search ancestor paths for compacted coverage and keep the direct path for single records.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>
2026-12-01 18:01:58 +08:00
Hauser Zhi f8680240d9 perf(scanner): validate durable directory progress once
Reuse the verified directory manifest for both listing and compacted progress. Compare saved bucket progress once per local turn and skip the initial snapshot when remote durable progress cannot be reported.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>
2026-12-01 17:28:05 +08:00
7 changed files with 272 additions and 118 deletions
+103 -61
View File
@@ -628,6 +628,19 @@ pub(crate) struct DataUsageDurableProgress {
active_source: Option<String>,
}
fn directory_progress_for<'a, T>(
progress: &'a [T],
parent: &'a str,
path: impl Fn(&T) -> &str + 'a,
) -> impl Iterator<Item = &'a T> {
let start = if progress.len() > 1 {
progress.partition_point(|entry| path(entry) < parent)
} else {
0
};
progress[start..].iter().take_while(move |entry| path(entry) == parent)
}
impl DataUsageDurableProgress {
fn source_frontier(&self, source: Option<&str>) -> Option<&str> {
if source == self.active_source.as_deref() {
@@ -638,12 +651,20 @@ impl DataUsageDurableProgress {
}
fn covers_on(&self, source: Option<&str>, path: &str) -> bool {
self.source_frontier(source)
if self
.source_frontier(source)
.is_some_and(|frontier| scan_frontier_covers_path(path, frontier))
|| self
.compacted
.iter()
.any(|done| Some(done.physical.endpoint.as_str()) == source && done.covers(path))
{
return true;
}
let covers = |done: &crate::scanner_folder::DirectoryProgress| {
Some(done.physical.endpoint.as_str()) == source && done.covers(path)
};
if self.compacted.len() <= 1 {
return self.compacted.iter().any(covers);
}
path.match_indices('/')
.any(|(separator, _)| directory_progress_for(&self.compacted, &path[..separator], |entry| &entry.parent).any(covers))
}
pub(crate) fn advanced_from(&self, previous: &Self) -> bool {
@@ -679,10 +700,10 @@ impl DataUsageDurableProgress {
// Legacy raw-name pages are local to their writer. The physical
// root position must still exist for that writer across rotation.
if !previous.raw.is_empty()
&& !previous.listings.iter().any(|before| {
before.parent == self.bucket
&& Some(before.physical.endpoint.as_str()) == old
&& self.listings.iter().any(|after| after.extends(before))
&& !directory_progress_for(&previous.listings, &self.bucket, |entry| &entry.parent).any(|before| {
Some(before.physical.endpoint.as_str()) == old
&& directory_progress_for(&self.listings, &before.parent, |entry| &entry.parent)
.any(|after| after.extends(before))
})
{
return false;
@@ -695,32 +716,36 @@ impl DataUsageDurableProgress {
_ => return false,
}
}
advanced |= self.raw.iter().any(|(parent, after)| {
after.committed_entries() > previous.raw.get(parent).map_or(0, |before| before.committed_entries())
});
advanced = advanced
|| self.raw.iter().any(|(parent, after)| {
after.committed_entries() > previous.raw.get(parent).map_or(0, |before| before.committed_entries())
});
}
for before in &previous.listings {
if !self.listings.iter().any(|after| after.extends(before))
if !directory_progress_for(&self.listings, &before.parent, |entry| &entry.parent).any(|after| after.extends(before))
&& !self.covers_on(Some(&before.physical.endpoint), &before.parent)
{
return false;
}
}
for before in &previous.compacted {
if !self.compacted.iter().any(|after| after.extends(before))
if !directory_progress_for(&self.compacted, &before.parent, |entry| &entry.parent).any(|after| after.extends(before))
&& !self.covers_on(Some(&before.physical.endpoint), &before.parent)
{
return false;
}
}
advanced |= self.listings.iter().any(|after| {
Some(after.physical.endpoint.as_str()) == active && !previous.listings.iter().any(|before| before.extends(after))
});
advanced |= self.compacted.iter().any(|after| {
Some(after.physical.endpoint.as_str()) == active && !previous.compacted.iter().any(|before| before.extends(after))
});
advanced
|| self.listings.iter().any(|after| {
Some(after.physical.endpoint.as_str()) == active
&& !directory_progress_for(&previous.listings, &after.parent, |entry| &entry.parent)
.any(|before| before.extends(after))
})
|| self.compacted.iter().any(|after| {
Some(after.physical.endpoint.as_str()) == active
&& !directory_progress_for(&previous.compacted, &after.parent, |entry| &entry.parent)
.any(|before| before.extends(after))
})
}
}
@@ -1361,6 +1386,18 @@ impl DataUsageCache {
}
pub(crate) fn durable_scan_progress(&self) -> DataUsageDurableProgress {
let mut listings = Vec::new();
let mut compacted = Vec::new();
for directory in &self.info.scan_directory_work {
let (listing, aggregate) = directory.scheduling_progress(&self.info);
listings.extend(listing);
compacted.extend(aggregate);
}
// Cache readers can restore receipts in a different order from the producer.
if self.info.scan_directory_work.len() > 1 {
listings.sort_unstable_by(|left, right| left.parent.cmp(&right.parent));
compacted.sort_unstable_by(|left, right| left.parent.cmp(&right.parent));
}
DataUsageDurableProgress {
bucket: self.info.name.clone(),
source: self.info.source,
@@ -1374,18 +1411,8 @@ impl DataUsageCache {
.filter_map(|(source, tree)| tree.frontier(&self.info).map(|last| (source.clone(), last.to_owned())))
.collect(),
active_source: self.info.scan_directory_source.clone(),
listings: self
.info
.scan_directory_work
.iter()
.filter_map(|d| d.read_progress(&self.info))
.collect(),
compacted: self
.info
.scan_directory_work
.iter()
.filter_map(|d| d.progress(&self.info))
.collect(),
listings,
compacted,
raw: self
.info
.scan_raw_enumeration_page_index
@@ -1466,15 +1493,17 @@ impl DataUsageCache {
// authorizing a new leader to skip namespace coverage.
// Cycle deadlines advance both counters, so a validated frontier from
// an earlier cycle must remain eligible for adoption.
let cross_epoch_checkpoint = self.info.leader_epoch < leader_epoch
&& self.info.scan_identity == Some(identity)
&& (self.validated_scan_frontier().is_some()
let checking_handoff = self.info.leader_epoch < leader_epoch && self.info.scan_identity == Some(identity);
let handoff_digest = if checking_handoff {
self.validated_scan_frontier_receipt().map(|(_, digest)| digest)
} else {
None
};
let cross_epoch_checkpoint = checking_handoff
&& (handoff_digest.is_some()
|| self.validated_raw_enumeration_cursor().is_some()
|| self.validated_raw_enumeration_page_index().is_some()
|| self.info.scan_directory_work.iter().any(|d| d.is_bound_to(&self.info)));
let handoff_frontier = cross_epoch_checkpoint
.then(|| self.validated_scan_frontier().map(clone_cache_value))
.flatten();
let reusable = identity.is_valid()
&& name != DATA_USAGE_ROOT
&& self.info.name == name
@@ -1560,9 +1589,13 @@ impl DataUsageCache {
self.info.scan_directory_work = directory_work.into_iter().filter(|d| d.is_bound_to(&self.info)).collect();
let cursor_is_valid = !self.has_scan_position()
|| !self.info.scan_directory_work.is_empty()
|| self.validated_scan_frontier().is_some()
|| self.info.scan_raw_enumeration_cursor.is_some()
|| self.info.scan_raw_enumeration_page_index.is_some();
|| self.info.scan_raw_enumeration_page_index.is_some()
|| if checking_handoff {
handoff_digest.is_some()
} else {
self.validated_scan_frontier().is_some()
};
if !cursor_is_valid {
self.info.scan_progress = None;
}
@@ -1574,13 +1607,12 @@ impl DataUsageCache {
self.info.tier_registry_generation = Some(identity.tier_registry_generation);
self.info.scan_identity = Some(identity);
self.info.snapshot_complete = false;
if let Some(frontier) = handoff_frontier
&& let Ok(digest) = self.coverage_prefix_digest(&frontier)
if reusable
&& let Some(digest) = handoff_digest
&& let Some(receipt) = self.info.scan_coverage_receipt.as_mut()
{
// Migrate a legacy epoch-bound receipt while the old epoch is
// still available for validation. New receipts deliberately do
// not bind to the process-local leader epoch.
// Reuse the digest computed during handoff validation. Only the
// leader epoch and fields outside the digest have changed here.
receipt.digest = digest;
}
// A sweep without a durable position restarts from the first entry,
@@ -1719,24 +1751,34 @@ impl DataUsageCache {
}
pub(crate) fn validated_scan_frontier(&self) -> Option<&str> {
self.validated_scan_frontier_receipt().map(|(frontier, _)| frontier)
}
/// Verify the saved frontier and return the digest to retain at handoff.
fn validated_scan_frontier_receipt(&self) -> Option<(&str, [u8; 32])> {
let receipt = self.info.scan_coverage_receipt.as_ref()?;
let checkpoint = self.info.scan_checkpoint.as_ref()?;
(self.info.scan_progress.is_some()
&& self.info.scan_identity.is_some_and(|identity| identity.is_valid())
&& self.info.source.is_some()
&& receipt.through.len() <= 16 * 1024
&& checkpoint.version == DATA_USAGE_SCAN_CHECKPOINT_VERSION
&& checkpoint.resume_after == receipt.through
&& self.info.scan_resume_after.as_deref() == Some(receipt.through.as_str())
&& receipt
.through
let through = receipt.through.as_str();
if self.info.scan_progress.is_none()
|| self.info.scan_identity.is_none_or(|identity| !identity.is_valid())
|| self.info.source.is_none()
|| through.len() > 16 * 1024
|| checkpoint.version != DATA_USAGE_SCAN_CHECKPOINT_VERSION
|| checkpoint.resume_after != through
|| self.info.scan_resume_after.as_deref() != Some(through)
|| through
.strip_prefix(&self.info.name)
.is_some_and(|suffix| suffix.starts_with('/'))
&& self.find(&receipt.through).is_some()
&& (self.coverage_prefix_digest(&receipt.through).ok() == Some(receipt.digest)
|| self.v2_coverage_prefix_digest(&receipt.through).ok() == Some(receipt.digest)
|| self.legacy_coverage_prefix_digest(&receipt.through).ok() == Some(receipt.digest)))
.then_some(receipt.through.as_str())
.is_none_or(|suffix| !suffix.starts_with('/'))
|| self.find(through).is_none()
{
return None;
}
let current = self.coverage_prefix_digest(through).ok();
// If a legacy proof validates but cannot be migrated, retain its bytes.
(current == Some(receipt.digest)
|| self.v2_coverage_prefix_digest(through).ok() == Some(receipt.digest)
|| self.legacy_coverage_prefix_digest(through).ok() == Some(receipt.digest))
.then_some((through, current.unwrap_or(receipt.digest)))
}
pub(crate) fn validated_raw_enumeration_cursor(&self) -> Option<&DataUsageRawEnumerationCursor> {
+12 -5
View File
@@ -2358,7 +2358,7 @@ fn data_usage_cache_prepare_for_scan_fences_leader_epochs() {
}
#[test]
fn prepare_bucket_checkpoint_migrates_legacy_epoch_bound_receipt() {
fn prepare_bucket_checkpoint_preserves_current_and_migrates_legacy_frontiers() {
let identity = valid_scan_identity();
let source = DataUsageCacheSource::new(1, 2);
let mut cache = DataUsageCache {
@@ -2392,7 +2392,9 @@ fn prepare_bucket_checkpoint_migrates_legacy_epoch_bound_receipt() {
..Default::default()
},
);
for legacy_digest in [
let current_digest = cache.coverage_prefix_digest("bucket/a").expect("current receipt digest");
for saved_digest in [
current_digest,
cache
.legacy_coverage_prefix_digest("bucket/a")
.expect("epoch-bound receipt digest"),
@@ -2401,7 +2403,7 @@ fn prepare_bucket_checkpoint_migrates_legacy_epoch_bound_receipt() {
let mut cache = cache.clone();
cache.info.scan_coverage_receipt = Some(DataUsageScanCoverageReceipt {
through: "bucket/a".to_string(),
digest: legacy_digest,
digest: saved_digest,
});
assert_eq!(cache.validated_scan_frontier(), Some("bucket/a"));
assert_eq!(
@@ -2410,8 +2412,8 @@ fn prepare_bucket_checkpoint_migrates_legacy_epoch_bound_receipt() {
);
assert_eq!(cache.info.leader_epoch, 2);
assert_eq!(cache.validated_scan_frontier(), Some("bucket/a"));
let digest = cache.info.scan_coverage_receipt.as_ref().expect("migrated receipt").digest;
assert_ne!(digest, legacy_digest);
let digest = cache.info.scan_coverage_receipt.as_ref().expect("retained receipt").digest;
assert_eq!(digest, current_digest);
assert_ne!(digest, cache.v2_coverage_prefix_digest("bucket/a").expect("old reader v2 digest"));
assert_ne!(
digest,
@@ -2421,6 +2423,11 @@ fn prepare_bucket_checkpoint_migrates_legacy_epoch_bound_receipt() {
);
cache.cache.get_mut("bucket/a").expect("covered entry").failed_objects = 1;
assert!(cache.validated_scan_frontier().is_none(), "tampered health debt invalidates coverage");
assert_eq!(
cache.prepare_bucket_checkpoint("bucket", 10, 3, source, TEST_PLAN_DIGEST, identity),
DataUsageCachePrepareOutcome::Reset
);
assert!(cache.validated_scan_frontier().is_none());
}
}
+5 -2
View File
@@ -1160,7 +1160,8 @@ async fn scan_and_persist_local_bucket_with_store(
usage_watch.as_deref(),
checkpoint_plan_digest.unwrap_or(scan_plan_digest),
);
let scan_position_before = cache.durable_scan_progress();
let scan_position_before =
(supports_durable_progress && checkpoint_plan_digest.is_some()).then(|| cache.durable_scan_progress());
let resumed_sweep = cache.has_scan_position();
let set_disks = scanner_set_disk_inventory(set.as_ref()).await;
@@ -1427,7 +1428,9 @@ async fn scan_and_persist_local_bucket_with_store(
checkpoint_plan_digest,
leader_epoch,
next_cycle,
advanced: supports_durable_progress && cache.durable_scan_progress().advanced_from(&scan_position_before),
advanced: scan_position_before
.as_ref()
.is_some_and(|before| cache.durable_scan_progress().advanced_from(before)),
resource_deferred: cache.info.scan_resource_deferred,
observation: supports_complete_observation
.then(|| cache.completed_bucket_observation().cloned().map(Box::new))
+8 -10
View File
@@ -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.
@@ -240,7 +244,7 @@ impl DirectoryCheckpoint {
}
hash.finalize().into()
}
fn checksum(&self) -> Option<[u8; 32]> {
fn checksum(&self, manifest: [u8; 32]) -> Option<[u8; 32]> {
// Nested usage distributions can contain maps. Canonicalize those
// map keys before hashing so restart hash randomization is irrelevant.
let mut aggregate = serde_json::to_value(&self.aggregate).ok()?;
@@ -255,7 +259,7 @@ impl DirectoryCheckpoint {
self.sealed,
&self.part,
self.metadata,
self.manifest(),
manifest,
aggregate,
&self.endpoint,
))
@@ -263,7 +267,10 @@ impl DirectoryCheckpoint {
Some(Sha256::digest(header).into())
}
pub(crate) fn is_bound_to(&self, info: &DataUsageCacheInfo) -> bool {
self.version == 1
self.bound_manifest(info).is_some()
}
fn bound_manifest(&self, info: &DataUsageCacheInfo) -> Option<[u8; 32]> {
let matches_scope = self.version == 1
&& self.scope.bucket == info.name
&& self.scope.identity.is_valid()
&& Some(self.scope.identity) == info.scan_identity
@@ -276,28 +283,51 @@ impl DirectoryCheckpoint {
.parent
.strip_prefix(&info.name)
.and_then(|p| p.strip_prefix('/'))
.is_some_and(|tail| tail.split('/').all(super::valid_component)))
&& self.valid_payload()
.is_some_and(|tail| tail.split('/').all(super::valid_component)));
if matches_scope { self.validated_manifest() } else { None }
}
pub(crate) fn read_progress(&self, info: &DataUsageCacheInfo) -> Option<DirectoryReadProgress> {
let physical = self.physical.as_ref()?;
(self.is_bound_to(info) && (self.sealed || self.anchor.is_some()) && self.entries_read > 0).then(|| {
DirectoryReadProgress {
parent: self.parent.clone(),
physical: physical.clone(),
position: (self.entries_read, self.sealed),
}
})
pub(crate) fn scheduling_progress(
&self,
info: &DataUsageCacheInfo,
) -> (Option<DirectoryReadProgress>, Option<DirectoryProgress>) {
let Some(physical) = self.physical.as_ref() else {
return (None, None);
};
if self.entries_read == 0 && self.aggregate.is_none() {
return (None, None);
}
let Some(manifest) = self.bound_manifest(info) else {
return (None, None);
};
let listing = (self.entries_read > 0).then(|| DirectoryReadProgress {
parent: self.parent.clone(),
physical: physical.clone(),
position: (self.entries_read, self.sealed),
});
let compacted = self
.aggregate
.as_ref()
.map(|done| self.compacted_progress(physical, manifest, &done.through));
(listing, compacted)
}
fn compacted_progress(&self, physical: &Physical, manifest: [u8; 32], through: &str) -> DirectoryProgress {
DirectoryProgress {
parent: self.parent.clone(),
physical: physical.clone(),
manifest,
through: through.to_owned(),
}
}
pub(crate) fn progress(&self, info: &DataUsageCacheInfo) -> Option<DirectoryProgress> {
let done = self.aggregate.as_ref()?;
let physical = self.physical.as_ref()?;
(self.sealed && self.is_bound_to(info)).then(|| DirectoryProgress {
parent: self.parent.clone(),
physical: physical.clone(),
manifest: self.manifest(),
through: done.through.clone(),
})
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>)> {
@@ -307,12 +337,16 @@ impl DirectoryCheckpoint {
&self.endpoint
}
fn valid_for(&self, parent: &str, owner: &Scope) -> bool {
self.version == 1 && self.parent == parent && self.scope.may_adopt(owner) && self.valid_payload()
self.version == 1 && self.parent == parent && self.scope.may_adopt(owner) && self.validated_manifest().is_some()
}
fn valid_payload(&self) -> bool {
self.physical.as_ref().is_some_and(|source| source.endpoint == self.endpoint)
&& (self.sealed || self.anchor.is_some())
&& self.checksum() == Some(self.digest)
fn validated_manifest(&self) -> Option<[u8; 32]> {
if !(self.physical.as_ref().is_some_and(|source| source.endpoint == self.endpoint)
&& (self.sealed || self.anchor.is_some()))
{
return None;
}
let manifest = self.manifest();
(self.checksum(manifest) == Some(self.digest)
&& self.pages.iter().all(NamePage::valid)
&& self.part.as_deref().is_none_or(super::super::is_erasure_part_name)
&& self.aggregate.as_ref().is_none_or(|done| {
@@ -321,7 +355,8 @@ impl DirectoryCheckpoint {
&& done.value.children.is_empty()
&& done.value.failed_objects == 0
&& self.pages.iter().any(|page| page.contains(&done.through))
})
}))
.then_some(manifest)
}
pub(super) fn restore_allowed(&self, parent: &str, owner: &Scope, physical: &Option<Physical>) -> bool {
self.valid_for(parent, owner)
@@ -402,7 +437,7 @@ impl Recorder {
digest: [0; 32],
measured_at: work.measured_at,
};
checkpoint.checksum().map(|digest| {
checkpoint.checksum(checkpoint.manifest()).map(|digest| {
checkpoint.digest = digest;
checkpoint
})
@@ -71,10 +71,9 @@ struct LegacyCheckpoint {
digest: [u8; 32],
}
#[tokio::test]
async fn display_progress_measurement_metadata_keeps_version_one_checkpoint_compatibility() {
fn checkpoint_info() -> DataUsageCacheInfo {
let plan = crate::DataUsageScanPlanDigest([1; 32]);
let info = DataUsageCacheInfo {
DataUsageCacheInfo {
name: "bucket".into(),
source: Some(DataUsageCacheSource::new(0, 0)),
scan_identity: Some(DataUsageScanIdentity {
@@ -92,7 +91,12 @@ async fn display_progress_measurement_metadata_keeps_version_one_checkpoint_comp
scan_directory_source: Some("disk-a".into()),
last_update: Some(SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(10)),
..Default::default()
};
}
}
#[tokio::test]
async fn display_progress_measurement_metadata_keeps_version_one_checkpoint_compatibility() {
let info = checkpoint_info();
let [checkpoint, _] = DirectoryCheckpoint::storage_fixture(&info, 4, [2, 3]).await;
assert_eq!(checkpoint.measured_at, Some(10_000));
let bytes = rmp_serde::to_vec(&checkpoint).expect("encode additive named checkpoint");
@@ -109,4 +113,69 @@ async fn display_progress_measurement_metadata_keeps_version_one_checkpoint_comp
recovered.is_bound_to(&info),
"diagnostic metadata must not change the version-one coverage checksum"
);
let (listing, compacted) = recovered.scheduling_progress(&info);
assert!(listing.is_some(), "valid receipt proves listing progress");
let compacted = compacted.expect("valid receipt proves compacted progress");
let (display, value, _) = recovered
.display_usage(&info)
.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());
}
#[tokio::test]
async fn durable_progress_checks_unordered_paths_and_each_replica() {
let mut cache = crate::DataUsageCache {
info: checkpoint_info(),
..Default::default()
};
let [earlier, later] = DirectoryCheckpoint::storage_fixture(&cache.info, 4, [2, 3]).await;
let receipt = |parent: &str, endpoint: &str| {
let mut receipt = earlier.clone();
receipt.parent = parent.to_owned();
receipt.endpoint = endpoint.to_owned();
receipt.physical.as_mut().expect("fixture source").endpoint = receipt.endpoint.clone();
receipt.digest = receipt.checksum(receipt.manifest()).expect("fixture checksum");
receipt
};
let covered = receipt("bucket/obj-000000/child", "disk-a");
let uncovered = receipt("bucket/obj-000003/child", "disk-a");
let replica = receipt("bucket", "disk-b");
cache.info.scan_directory_work = vec![uncovered.clone(), replica.clone(), covered, earlier];
let before = cache.durable_scan_progress();
cache.info.scan_directory_work = vec![uncovered, later, replica];
assert!(
cache.durable_scan_progress().advanced_from(&before),
"the advanced root still covers a removed descendant and retains the other replica"
);
let unrelated = cache.info.scan_directory_work.remove(0);
assert!(
!cache.durable_scan_progress().advanced_from(&before),
"the root frontier does not cover every sibling directory"
);
cache.info.scan_directory_work.pop();
cache.info.scan_directory_work.push(unrelated);
assert!(
!cache.durable_scan_progress().advanced_from(&before),
"the root on one replica cannot replace the same path on another"
);
}
+5 -5
View File
@@ -2212,9 +2212,10 @@ impl ScannerIOCache for SetDisks {
).await;
bucket_observations_clone.lock().await.insert(bucket.name.clone(), observation.clone());
}
if partial_progress_proven && cache.durable_scan_progress().advanced_from(&scan_position_before) {
bucket_budget.record_durable_turn_progress();
}
}
let advanced = partial_progress_proven && cache.durable_scan_progress().advanced_from(&scan_position_before);
if advanced {
bucket_budget.record_durable_turn_progress();
}
if local_stop.reason().is_some() {
// Recovery is independent of durable forward progress, but
@@ -2243,9 +2244,8 @@ impl ScannerIOCache for SetDisks {
}
// Only saved forward motion earns another turn in this
// cycle; otherwise the bucket waits for the next one.
if partial_progress_proven
if advanced
&& bucket_budget.quantum_exhausted()
&& cache.durable_scan_progress().advanced_from(&scan_position_before)
&& requeue_bucket_work(&bucket_tx_clone, &bucket, &mut work_guard).await
{
increment_disk_bucket_scans_queued(