mirror of
https://github.com/rustfs/rustfs.git
synced 2026-12-01 13:44:49 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a5acedbee | |||
| 51bd41a30b | |||
| 49f01af16d |
@@ -38,8 +38,8 @@ use super::replication_resync_boundary::{
|
||||
decode_resync_file, encode_mrf_file, should_auto_resume_resync,
|
||||
};
|
||||
use super::replication_resyncer::{
|
||||
ReplicationResyncer, get_heal_replicate_object_info, replicate_delete, replicate_delete_with_outcome, replicate_object,
|
||||
replicate_object_with_outcome, update_resync_status_cas,
|
||||
DeleteReplicationAttempt, ReplicationResyncer, get_heal_replicate_object_info, replicate_delete_attempt,
|
||||
replicate_delete_with_outcome, replicate_object, replicate_object_with_outcome, update_resync_status_cas,
|
||||
};
|
||||
use super::replication_state::ReplicationStats;
|
||||
use super::replication_storage_boundary::{
|
||||
@@ -1329,12 +1329,14 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
|
||||
let storage = self.storage.clone();
|
||||
let stats = self.stats.clone();
|
||||
let in_flight = self.in_flight.clone();
|
||||
let mrf_save_tx = self.mrf_save_tx.clone();
|
||||
|
||||
let handle = tokio::spawn(async move {
|
||||
let mut rx = rx;
|
||||
while let Some(operation) = rx.recv().await {
|
||||
let _active = ActiveWorkerGuard::new(active_counter.clone());
|
||||
process_replication_operation(operation, stats.clone(), storage.clone(), in_flight.clone()).await;
|
||||
process_replication_operation(operation, stats.clone(), storage.clone(), in_flight.clone(), &mrf_save_tx)
|
||||
.await;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1389,12 +1391,14 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
|
||||
let stats = self.stats.clone();
|
||||
let storage = self.storage.clone();
|
||||
let in_flight = self.in_flight.clone();
|
||||
let mrf_save_tx = self.mrf_save_tx.clone();
|
||||
|
||||
let handle = tokio::spawn(async move {
|
||||
let mut rx = rx;
|
||||
while let Some(operation) = rx.recv().await {
|
||||
let _active = ActiveWorkerGuard::new(active_counter.clone());
|
||||
process_replication_operation(operation, stats.clone(), storage.clone(), in_flight.clone()).await;
|
||||
process_replication_operation(operation, stats.clone(), storage.clone(), in_flight.clone(), &mrf_save_tx)
|
||||
.await;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1434,6 +1438,7 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
|
||||
let stats = self.stats.clone();
|
||||
let storage = self.storage.clone();
|
||||
let in_flight = self.in_flight.clone();
|
||||
let mrf_save_tx = self.mrf_save_tx.clone();
|
||||
let mrf_rx = Arc::clone(&self.mrf_replica_rx);
|
||||
|
||||
let handle = tokio::spawn(async move {
|
||||
@@ -1453,7 +1458,8 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
|
||||
let Some(operation) = operation else { break };
|
||||
|
||||
let _active = ActiveWorkerGuard::new(active_counter.clone());
|
||||
process_replication_operation(operation, stats.clone(), storage.clone(), in_flight.clone()).await;
|
||||
process_replication_operation(operation, stats.clone(), storage.clone(), in_flight.clone(), &mrf_save_tx)
|
||||
.await;
|
||||
}
|
||||
});
|
||||
self.task_handles.lock().await.push(handle);
|
||||
@@ -1935,7 +1941,14 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
|
||||
) {
|
||||
while let Some(operation) = rx.recv().await {
|
||||
let _active = ActiveWorkerGuard::new(active_counter.clone());
|
||||
process_replication_operation(operation, stats.clone(), self.storage.clone(), self.in_flight.clone()).await;
|
||||
process_replication_operation(
|
||||
operation,
|
||||
stats.clone(),
|
||||
self.storage.clone(),
|
||||
self.in_flight.clone(),
|
||||
&self.mrf_save_tx,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1953,7 +1966,8 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
|
||||
) {
|
||||
while let Some(operation) = rx.recv().await {
|
||||
let _active = ActiveWorkerGuard::new(active_counter.clone());
|
||||
process_replication_operation(operation, stats.clone(), storage.clone(), self.in_flight.clone()).await;
|
||||
process_replication_operation(operation, stats.clone(), storage.clone(), self.in_flight.clone(), &self.mrf_save_tx)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1970,7 +1984,14 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
|
||||
) {
|
||||
while let Some(operation) = rx.recv().await {
|
||||
let _active = ActiveWorkerGuard::new(active_counter.clone());
|
||||
process_replication_operation(operation, stats.clone(), self.storage.clone(), self.in_flight.clone()).await;
|
||||
process_replication_operation(
|
||||
operation,
|
||||
stats.clone(),
|
||||
self.storage.clone(),
|
||||
self.in_flight.clone(),
|
||||
&self.mrf_save_tx,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2539,6 +2560,7 @@ async fn process_replication_operation<S: ReplicationStorage>(
|
||||
stats: Arc<ReplicationStats>,
|
||||
storage: Arc<S>,
|
||||
in_flight: Arc<ReplicationInFlight>,
|
||||
mrf_save_tx: &Sender<MrfReplicateEntry>,
|
||||
) {
|
||||
match operation {
|
||||
ReplicationOperation::Object(obj_info) => {
|
||||
@@ -2548,7 +2570,14 @@ async fn process_replication_operation<S: ReplicationStorage>(
|
||||
}
|
||||
ReplicationOperation::Delete(del_info) => {
|
||||
let _backlog = ReplicationBacklogGuard::for_delete(stats, del_info.as_ref());
|
||||
replicate_delete(*del_info, storage).await;
|
||||
// The delete request already succeeded, so a source lock that is
|
||||
// still held (a bulk delete keeps its key locks until the whole
|
||||
// batch commits) must not cost the replication: journal it for
|
||||
// the next MRF replay.
|
||||
let retry_entry = del_info.to_mrf_entry();
|
||||
if replicate_delete_attempt(*del_info, storage).await == DeleteReplicationAttempt::SourceDeferred {
|
||||
queue_mrf_save_entry(mrf_save_tx, retry_entry, "delete_source_deferred").await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4506,6 +4535,102 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs one live delete through the worker and returns what it journaled for MRF replay.
|
||||
async fn delete_worker_journal(
|
||||
delete: DeletedObjectReplicationInfo,
|
||||
writeback_error: EcstoreError,
|
||||
) -> Vec<MrfReplicateEntry> {
|
||||
let shared = empty_resync_shared_state();
|
||||
*shared.delete_error.lock().expect("delete error lock should not be poisoned") = writeback_error;
|
||||
let storage = Arc::new(LoadResyncNodeStore::new("delete-worker-journal", shared));
|
||||
let (mrf_save_tx, mut mrf_save_rx) = mpsc::channel(4);
|
||||
|
||||
process_replication_operation(
|
||||
ReplicationOperation::Delete(Box::new(delete)),
|
||||
Arc::new(ReplicationStats::new()),
|
||||
storage,
|
||||
Arc::new(ReplicationInFlight::default()),
|
||||
&mrf_save_tx,
|
||||
)
|
||||
.await;
|
||||
|
||||
drop(mrf_save_tx);
|
||||
let mut journaled = Vec::new();
|
||||
while let Some(entry) = mrf_save_rx.recv().await {
|
||||
journaled.push(entry);
|
||||
}
|
||||
journaled
|
||||
}
|
||||
|
||||
fn purged_on_target_delete(
|
||||
arn: &str,
|
||||
version_id: Uuid,
|
||||
target_status: VersionPurgeStatusType,
|
||||
) -> DeletedObjectReplicationInfo {
|
||||
DeletedObjectReplicationInfo {
|
||||
bucket: "source".to_string(),
|
||||
delete_object: ReplicationDeletedObject {
|
||||
object_name: "purged".to_string(),
|
||||
version_id: Some(version_id),
|
||||
replication_state: Some(ReplicationState {
|
||||
replicate_decision_str: test_replicate_decision(&[arn]).to_string(),
|
||||
purge_targets: HashMap::from([(arn.to_string(), target_status)]),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
op_type: ReplicationType::Delete,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn delete_worker_journals_a_delete_whose_source_writeback_lost_the_object_lock() {
|
||||
let arn = "arn:test";
|
||||
let version_id = Uuid::new_v4();
|
||||
// A bulk delete of the same key still holds the object lock.
|
||||
let lock_timeout = EcstoreError::Lock(rustfs_lock::LockError::internal(
|
||||
"Lock acquisition timeout for resource 'source/purged@latest' after 5s".to_string(),
|
||||
));
|
||||
|
||||
let journaled =
|
||||
delete_worker_journal(purged_on_target_delete(arn, version_id, VersionPurgeStatusType::Complete), lock_timeout).await;
|
||||
|
||||
assert_eq!(
|
||||
journaled.len(),
|
||||
1,
|
||||
"a delete whose result never reached the source must be kept for replay"
|
||||
);
|
||||
let entry = &journaled[0];
|
||||
assert_eq!((entry.bucket.as_str(), entry.object.as_str()), ("source", "purged"));
|
||||
assert_eq!(entry.version_id, Some(version_id));
|
||||
assert_eq!(entry.op, MrfOpKind::Delete);
|
||||
assert_eq!(entry.target_arns, vec![arn.to_string()]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn delete_worker_does_not_journal_deletes_other_paths_own() {
|
||||
let arn = "arn:test";
|
||||
let source_gone = || EcstoreError::ObjectNotFound("source".to_string(), "purged".to_string());
|
||||
|
||||
let completed = delete_worker_journal(
|
||||
purged_on_target_delete(arn, Uuid::new_v4(), VersionPurgeStatusType::Complete),
|
||||
source_gone(),
|
||||
)
|
||||
.await;
|
||||
assert!(completed.is_empty(), "a completed delete must not be replayed");
|
||||
|
||||
let target_pending = delete_worker_journal(
|
||||
purged_on_target_delete(arn, Uuid::new_v4(), VersionPurgeStatusType::Pending),
|
||||
source_gone(),
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
target_pending.is_empty(),
|
||||
"unfinished target work is recorded in the source state for the scanner, not journaled per delete"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn delete_worker_preserves_persisted_admission_without_live_config() {
|
||||
let arn = "arn:test";
|
||||
|
||||
@@ -2422,12 +2422,40 @@ pub async fn replicate_delete<S: ReplicationStorage>(dobj: DeletedObjectReplicat
|
||||
let _ = replicate_delete_with_outcome(dobj, storage).await;
|
||||
}
|
||||
|
||||
/// How one delete replication attempt ended.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum DeleteReplicationAttempt {
|
||||
/// Every admitted target finished and the source state was persisted.
|
||||
Completed,
|
||||
/// The attempt did not finish for a reason another path already owns: a
|
||||
/// target failure is recorded in the persisted state for the scanner, and
|
||||
/// a force delete or delete-marker purge journals its own intent.
|
||||
Unfinished,
|
||||
/// A source-side lock or read kept the attempt from running, or from
|
||||
/// persisting its result. Nothing durable records that, so the caller must
|
||||
/// keep the delete for a later attempt.
|
||||
SourceDeferred,
|
||||
}
|
||||
|
||||
impl DeleteReplicationAttempt {
|
||||
fn from_finished(finished: bool) -> Self {
|
||||
if finished { Self::Completed } else { Self::Unfinished }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
dobj: DeletedObjectReplicationInfo,
|
||||
storage: Arc<S>,
|
||||
) -> bool {
|
||||
replicate_delete_attempt(dobj, storage).await == DeleteReplicationAttempt::Completed
|
||||
}
|
||||
|
||||
pub(crate) async fn replicate_delete_attempt<S: ReplicationStorage>(
|
||||
dobj: DeletedObjectReplicationInfo,
|
||||
storage: Arc<S>,
|
||||
) -> DeleteReplicationAttempt {
|
||||
if dobj.delete_object.force_delete {
|
||||
return replicate_force_delete_to_targets(&dobj, storage).await;
|
||||
return DeleteReplicationAttempt::from_finished(replicate_force_delete_to_targets(&dobj, storage).await);
|
||||
}
|
||||
|
||||
let bucket = dobj.bucket.clone();
|
||||
@@ -2472,7 +2500,7 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
user_agent: "Internal: [Replication]".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
return false;
|
||||
return DeleteReplicationAttempt::Unfinished;
|
||||
}
|
||||
};
|
||||
let target_arns = dobj.admitted_target_arns();
|
||||
@@ -2480,7 +2508,7 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
// Batch expiry can return an empty state after removing the source.
|
||||
// It owes no remote work or local writeback. Persisted target admission
|
||||
// must still be honored even when the live configuration is gone.
|
||||
return true;
|
||||
return DeleteReplicationAttempt::Completed;
|
||||
}
|
||||
|
||||
if dobj.delete_object.delete_marker
|
||||
@@ -2502,7 +2530,7 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
reason = "source_not_delete_marker",
|
||||
"Skipping stale delete-marker replication"
|
||||
);
|
||||
return true;
|
||||
return DeleteReplicationAttempt::Completed;
|
||||
}
|
||||
Err(err) if is_err_object_not_found(&err) || is_err_version_not_found(&err) => {
|
||||
debug!(
|
||||
@@ -2520,7 +2548,7 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
// purge-intent replay landing here on purpose). Purge instead
|
||||
// of just skipping; the result decides whether an MRF replay
|
||||
// may acknowledge the entry.
|
||||
return purge_stale_delete_marker_targets(&bucket, &dobj).await;
|
||||
return DeleteReplicationAttempt::from_finished(purge_stale_delete_marker_targets(&bucket, &dobj).await);
|
||||
}
|
||||
Err(err) => {
|
||||
// A transient source error (lock timeout, IO error) must not
|
||||
@@ -2529,7 +2557,7 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
// target mint one more delete marker (rustfs#6823). Fail the
|
||||
// entry without touching the target; the MRF replay / heal
|
||||
// scanner retries once the source is readable again.
|
||||
debug!(
|
||||
warn!(
|
||||
event = EVENT_REPLICATION_DELETE_SKIPPED,
|
||||
component = LOG_COMPONENT_ECSTORE,
|
||||
subsystem = LOG_SUBSYSTEM_REPLICATION_RESYNC,
|
||||
@@ -2554,7 +2582,7 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
user_agent: "Internal: [Replication]".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
return false;
|
||||
return DeleteReplicationAttempt::SourceDeferred;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2565,7 +2593,7 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
{
|
||||
Ok(ns_lock) => ns_lock,
|
||||
Err(e) => {
|
||||
debug!(
|
||||
warn!(
|
||||
event = EVENT_REPLICATION_DELETE_SKIPPED,
|
||||
component = LOG_COMPONENT_ECSTORE,
|
||||
subsystem = LOG_SUBSYSTEM_REPLICATION_RESYNC,
|
||||
@@ -2589,14 +2617,14 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
user_agent: "Internal: [Replication]".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
return false;
|
||||
return DeleteReplicationAttempt::SourceDeferred;
|
||||
}
|
||||
};
|
||||
|
||||
let _lock_guard = match ns_lock.get_write_lock(ReplicationLockTiming::acquire_timeout()).await {
|
||||
Ok(lock_guard) => lock_guard,
|
||||
Err(e) => {
|
||||
debug!(
|
||||
warn!(
|
||||
event = EVENT_REPLICATION_DELETE_SKIPPED,
|
||||
component = LOG_COMPONENT_ECSTORE,
|
||||
subsystem = LOG_SUBSYSTEM_REPLICATION_RESYNC,
|
||||
@@ -2620,7 +2648,7 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
user_agent: "Internal: [Replication]".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
return false;
|
||||
return DeleteReplicationAttempt::SourceDeferred;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2858,7 +2886,12 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
}
|
||||
};
|
||||
|
||||
replicate_delete_outcome(
|
||||
if !state_persisted {
|
||||
// The targets were driven, but the result never reached the source
|
||||
// metadata, so a scanner pass would still see the pre-attempt state.
|
||||
return DeleteReplicationAttempt::SourceDeferred;
|
||||
}
|
||||
DeleteReplicationAttempt::from_finished(replicate_delete_outcome(
|
||||
expected_targets,
|
||||
rinfos.targets.len(),
|
||||
state_persisted,
|
||||
@@ -2866,7 +2899,7 @@ pub(crate) async fn replicate_delete_with_outcome<S: ReplicationStorage>(
|
||||
// error returns early above instead of replicating unverified.
|
||||
true,
|
||||
&replication_status,
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
/// Reads the source version addressed by `delete_marker_version_id` so a
|
||||
|
||||
@@ -628,19 +628,6 @@ 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() {
|
||||
@@ -651,20 +638,12 @@ impl DataUsageDurableProgress {
|
||||
}
|
||||
|
||||
fn covers_on(&self, source: Option<&str>, path: &str) -> bool {
|
||||
if self
|
||||
.source_frontier(source)
|
||||
self.source_frontier(source)
|
||||
.is_some_and(|frontier| scan_frontier_covers_path(path, frontier))
|
||||
{
|
||||
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))
|
||||
|| self
|
||||
.compacted
|
||||
.iter()
|
||||
.any(|done| Some(done.physical.endpoint.as_str()) == source && done.covers(path))
|
||||
}
|
||||
|
||||
pub(crate) fn advanced_from(&self, previous: &Self) -> bool {
|
||||
@@ -700,10 +679,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()
|
||||
&& !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))
|
||||
&& !previous.listings.iter().any(|before| {
|
||||
before.parent == self.bucket
|
||||
&& Some(before.physical.endpoint.as_str()) == old
|
||||
&& self.listings.iter().any(|after| after.extends(before))
|
||||
})
|
||||
{
|
||||
return false;
|
||||
@@ -716,36 +695,32 @@ impl DataUsageDurableProgress {
|
||||
_ => return false,
|
||||
}
|
||||
}
|
||||
advanced = advanced
|
||||
|| self.raw.iter().any(|(parent, after)| {
|
||||
after.committed_entries() > previous.raw.get(parent).map_or(0, |before| before.committed_entries())
|
||||
});
|
||||
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 !directory_progress_for(&self.listings, &before.parent, |entry| &entry.parent).any(|after| after.extends(before))
|
||||
if !self.listings.iter().any(|after| after.extends(before))
|
||||
&& !self.covers_on(Some(&before.physical.endpoint), &before.parent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for before in &previous.compacted {
|
||||
if !directory_progress_for(&self.compacted, &before.parent, |entry| &entry.parent).any(|after| after.extends(before))
|
||||
if !self.compacted.iter().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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1386,18 +1361,6 @@ 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,
|
||||
@@ -1411,8 +1374,18 @@ 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,
|
||||
compacted,
|
||||
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(),
|
||||
raw: self
|
||||
.info
|
||||
.scan_raw_enumeration_page_index
|
||||
@@ -1493,17 +1466,15 @@ 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 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()
|
||||
let cross_epoch_checkpoint = self.info.leader_epoch < leader_epoch
|
||||
&& self.info.scan_identity == Some(identity)
|
||||
&& (self.validated_scan_frontier().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
|
||||
@@ -1589,13 +1560,9 @@ 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()
|
||||
|| if checking_handoff {
|
||||
handoff_digest.is_some()
|
||||
} else {
|
||||
self.validated_scan_frontier().is_some()
|
||||
};
|
||||
|| self.info.scan_raw_enumeration_page_index.is_some();
|
||||
if !cursor_is_valid {
|
||||
self.info.scan_progress = None;
|
||||
}
|
||||
@@ -1607,12 +1574,13 @@ impl DataUsageCache {
|
||||
self.info.tier_registry_generation = Some(identity.tier_registry_generation);
|
||||
self.info.scan_identity = Some(identity);
|
||||
self.info.snapshot_complete = false;
|
||||
if reusable
|
||||
&& let Some(digest) = handoff_digest
|
||||
if let Some(frontier) = handoff_frontier
|
||||
&& let Ok(digest) = self.coverage_prefix_digest(&frontier)
|
||||
&& let Some(receipt) = self.info.scan_coverage_receipt.as_mut()
|
||||
{
|
||||
// Reuse the digest computed during handoff validation. Only the
|
||||
// leader epoch and fields outside the digest have changed here.
|
||||
// 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.
|
||||
receipt.digest = digest;
|
||||
}
|
||||
// A sweep without a durable position restarts from the first entry,
|
||||
@@ -1751,34 +1719,24 @@ 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()?;
|
||||
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
|
||||
(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
|
||||
.strip_prefix(&self.info.name)
|
||||
.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)))
|
||||
.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())
|
||||
}
|
||||
|
||||
pub(crate) fn validated_raw_enumeration_cursor(&self) -> Option<&DataUsageRawEnumerationCursor> {
|
||||
|
||||
@@ -2358,7 +2358,7 @@ fn data_usage_cache_prepare_for_scan_fences_leader_epochs() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepare_bucket_checkpoint_preserves_current_and_migrates_legacy_frontiers() {
|
||||
fn prepare_bucket_checkpoint_migrates_legacy_epoch_bound_receipt() {
|
||||
let identity = valid_scan_identity();
|
||||
let source = DataUsageCacheSource::new(1, 2);
|
||||
let mut cache = DataUsageCache {
|
||||
@@ -2392,9 +2392,7 @@ fn prepare_bucket_checkpoint_preserves_current_and_migrates_legacy_frontiers() {
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let current_digest = cache.coverage_prefix_digest("bucket/a").expect("current receipt digest");
|
||||
for saved_digest in [
|
||||
current_digest,
|
||||
for legacy_digest in [
|
||||
cache
|
||||
.legacy_coverage_prefix_digest("bucket/a")
|
||||
.expect("epoch-bound receipt digest"),
|
||||
@@ -2403,7 +2401,7 @@ fn prepare_bucket_checkpoint_preserves_current_and_migrates_legacy_frontiers() {
|
||||
let mut cache = cache.clone();
|
||||
cache.info.scan_coverage_receipt = Some(DataUsageScanCoverageReceipt {
|
||||
through: "bucket/a".to_string(),
|
||||
digest: saved_digest,
|
||||
digest: legacy_digest,
|
||||
});
|
||||
assert_eq!(cache.validated_scan_frontier(), Some("bucket/a"));
|
||||
assert_eq!(
|
||||
@@ -2412,8 +2410,8 @@ fn prepare_bucket_checkpoint_preserves_current_and_migrates_legacy_frontiers() {
|
||||
);
|
||||
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("retained receipt").digest;
|
||||
assert_eq!(digest, current_digest);
|
||||
let digest = cache.info.scan_coverage_receipt.as_ref().expect("migrated receipt").digest;
|
||||
assert_ne!(digest, legacy_digest);
|
||||
assert_ne!(digest, cache.v2_coverage_prefix_digest("bucket/a").expect("old reader v2 digest"));
|
||||
assert_ne!(
|
||||
digest,
|
||||
@@ -2423,11 +2421,6 @@ fn prepare_bucket_checkpoint_preserves_current_and_migrates_legacy_frontiers() {
|
||||
);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1160,8 +1160,7 @@ 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 =
|
||||
(supports_durable_progress && checkpoint_plan_digest.is_some()).then(|| cache.durable_scan_progress());
|
||||
let scan_position_before = cache.durable_scan_progress();
|
||||
let resumed_sweep = cache.has_scan_position();
|
||||
|
||||
let set_disks = scanner_set_disk_inventory(set.as_ref()).await;
|
||||
@@ -1428,9 +1427,7 @@ async fn scan_and_persist_local_bucket_with_store(
|
||||
checkpoint_plan_digest,
|
||||
leader_epoch,
|
||||
next_cycle,
|
||||
advanced: scan_position_before
|
||||
.as_ref()
|
||||
.is_some_and(|before| cache.durable_scan_progress().advanced_from(before)),
|
||||
advanced: supports_durable_progress && cache.durable_scan_progress().advanced_from(&scan_position_before),
|
||||
resource_deferred: cache.info.scan_resource_deferred,
|
||||
observation: supports_complete_observation
|
||||
.then(|| cache.completed_bucket_observation().cloned().map(Box::new))
|
||||
@@ -1844,19 +1841,16 @@ where
|
||||
}
|
||||
RemoteScannerFrameResult::DurableProgress(receipt) => {
|
||||
let actual = receipt.identity.tier_registry_generation;
|
||||
let expected_identity = crate::DataUsageScanIdentity {
|
||||
tier_registry_generation: expected.tier_registry_generation,
|
||||
..receipt.identity
|
||||
};
|
||||
if !(expected.supports_durable_progress || expected.supports_complete_observation)
|
||||
|| (!expected.supports_durable_progress && receipt.advanced)
|
||||
|| (!expected.supports_complete_observation && receipt.observation.is_some())
|
||||
|| frame.phase != RemoteScannerPhase::Persisting
|
||||
|| receipt.source != expected.source
|
||||
|| expected.checkpoint_identity.is_none_or(|identity| {
|
||||
// The worker fences persistence with its own process-local epoch.
|
||||
crate::DataUsageScanIdentity {
|
||||
publication_epoch: identity.publication_epoch,
|
||||
tier_registry_generation: expected.tier_registry_generation,
|
||||
..receipt.identity
|
||||
} != identity
|
||||
})
|
||||
|| Some(expected_identity) != expected.checkpoint_identity
|
||||
|| receipt.scan_plan_digest != expected.scan_plan_digest
|
||||
|| receipt.checkpoint_plan_digest != expected.checkpoint_plan_digest
|
||||
|| receipt.leader_epoch != expected.leader_epoch
|
||||
|
||||
@@ -43,20 +43,13 @@ fn durable_receipt() -> RemoteScannerDurableProgress {
|
||||
|
||||
#[tokio::test]
|
||||
async fn durable_progress_requires_negotiation_exact_scope_mac_and_eof() {
|
||||
let leader_publication_epoch = 3;
|
||||
assert_ne!(progress_identity().publication_epoch, leader_publication_epoch);
|
||||
for case in [
|
||||
"valid",
|
||||
"progress_only",
|
||||
"generation",
|
||||
"after_preflight",
|
||||
"legacy",
|
||||
"source",
|
||||
"identity",
|
||||
"layout",
|
||||
"mode",
|
||||
"missing_identity",
|
||||
"observation_epoch",
|
||||
"epoch",
|
||||
"plan",
|
||||
"future_observation",
|
||||
@@ -68,13 +61,16 @@ async fn durable_progress_requires_negotiation_exact_scope_mac_and_eof() {
|
||||
let writer_auth = FrameAuthenticator::for_test(request_id);
|
||||
let reader_auth = FrameAuthenticator::for_test(if case == "mac" { Uuid::new_v4() } else { request_id });
|
||||
let mut receipt = durable_receipt();
|
||||
if case != "valid" {
|
||||
receipt.identity.tier_registry_generation = 1;
|
||||
receipt.observation.as_mut().expect("fixture observation").identity = receipt.identity;
|
||||
}
|
||||
match case {
|
||||
"generation" | "after_preflight" => receipt.identity.tier_registry_generation = 1,
|
||||
"progress_only" => receipt.observation = None,
|
||||
"source" => receipt.source = DataUsageCacheSource::new(99, 99),
|
||||
"identity" => receipt.identity.bucket_incarnation = Uuid::from_u128(99),
|
||||
"layout" => receipt.identity.set_layout = DataUsageScanPlanDigest([99; 32]),
|
||||
"mode" => receipt.identity.scan_mode = HealScanMode::Deep,
|
||||
"identity" => {
|
||||
receipt.identity.bucket_incarnation = Uuid::from_u128(99);
|
||||
receipt.observation.as_mut().expect("fixture observation").identity = receipt.identity;
|
||||
}
|
||||
"epoch" => receipt.leader_epoch += 1,
|
||||
"plan" => receipt.checkpoint_plan_digest = DataUsageScanPlanDigest([99; 32]),
|
||||
"future_observation" => receipt.observation.as_mut().expect("fixture observation").completed_cycle += 1,
|
||||
@@ -85,12 +81,6 @@ async fn durable_progress_requires_negotiation_exact_scope_mac_and_eof() {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if let Some(observation) = receipt.observation.as_mut() {
|
||||
observation.identity = receipt.identity;
|
||||
if case == "observation_epoch" {
|
||||
observation.identity.publication_epoch += 1;
|
||||
}
|
||||
}
|
||||
let mut bytes = Vec::new();
|
||||
write_frame(
|
||||
&mut bytes,
|
||||
@@ -123,16 +113,13 @@ async fn durable_progress_requires_negotiation_exact_scope_mac_and_eof() {
|
||||
tier_registry_generation: 0,
|
||||
supports_durable_progress: case != "legacy",
|
||||
supports_complete_observation: case != "legacy",
|
||||
checkpoint_identity: (case != "missing_identity").then(|| crate::DataUsageScanIdentity {
|
||||
publication_epoch: leader_publication_epoch,
|
||||
..progress_identity()
|
||||
}),
|
||||
checkpoint_identity: Some(progress_identity()),
|
||||
},
|
||||
reader_auth,
|
||||
Instant::now() + Duration::from_secs(5),
|
||||
)
|
||||
.await;
|
||||
if matches!(case, "valid" | "progress_only") {
|
||||
if case == "valid" {
|
||||
let RemoteScannerOutcome::DurableProgress {
|
||||
advanced, observation, ..
|
||||
} = result.expect("validated progress")
|
||||
@@ -140,13 +127,7 @@ async fn durable_progress_requires_negotiation_exact_scope_mac_and_eof() {
|
||||
panic!("progress cannot become Complete")
|
||||
};
|
||||
assert!(advanced);
|
||||
if case == "valid" {
|
||||
let observation = observation.expect("preserved companion");
|
||||
assert_eq!(observation.identity, progress_identity());
|
||||
assert_eq!(observation.entry.objects, 5);
|
||||
} else {
|
||||
assert!(observation.is_none());
|
||||
}
|
||||
assert_eq!(observation.expect("preserved companion").entry.objects, 5);
|
||||
} else if case == "generation" {
|
||||
assert!(matches!(
|
||||
result,
|
||||
@@ -156,20 +137,6 @@ async fn durable_progress_requires_negotiation_exact_scope_mac_and_eof() {
|
||||
assert!(result.is_err(), "invalid progress case {case}");
|
||||
}
|
||||
}
|
||||
println!(
|
||||
"usage_assertion: {}",
|
||||
serde_json::json!({
|
||||
"case_id": "USAGE-23", "assertion_id": "USAGE-23-A01", "status": "PASS",
|
||||
"evidence": {
|
||||
"worker_publication_epoch": progress_identity().publication_epoch,
|
||||
"leader_publication_epoch": leader_publication_epoch,
|
||||
"outcome": "durable_progress",
|
||||
"companion_identity_preserved": true,
|
||||
"mismatched_companion_rejected": true,
|
||||
}
|
||||
}),
|
||||
);
|
||||
println!("usage_cleanup: {}", serde_json::json!({"case_id": "USAGE-23", "status": "PASS"}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1693,14 +1693,16 @@ 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.
|
||||
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))
|
||||
})
|
||||
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()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -206,17 +206,13 @@ impl DirectoryProgress {
|
||||
self.same_source(previous) && self.through >= previous.through
|
||||
}
|
||||
pub(crate) fn covers(&self, path: &str) -> bool {
|
||||
compacted_child_covers(&self.parent, &self.through, path)
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
@@ -244,7 +240,7 @@ impl DirectoryCheckpoint {
|
||||
}
|
||||
hash.finalize().into()
|
||||
}
|
||||
fn checksum(&self, manifest: [u8; 32]) -> Option<[u8; 32]> {
|
||||
fn checksum(&self) -> 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()?;
|
||||
@@ -259,7 +255,7 @@ impl DirectoryCheckpoint {
|
||||
self.sealed,
|
||||
&self.part,
|
||||
self.metadata,
|
||||
manifest,
|
||||
self.manifest(),
|
||||
aggregate,
|
||||
&self.endpoint,
|
||||
))
|
||||
@@ -267,10 +263,7 @@ impl DirectoryCheckpoint {
|
||||
Some(Sha256::digest(header).into())
|
||||
}
|
||||
pub(crate) fn is_bound_to(&self, info: &DataUsageCacheInfo) -> bool {
|
||||
self.bound_manifest(info).is_some()
|
||||
}
|
||||
fn bound_manifest(&self, info: &DataUsageCacheInfo) -> Option<[u8; 32]> {
|
||||
let matches_scope = self.version == 1
|
||||
self.version == 1
|
||||
&& self.scope.bucket == info.name
|
||||
&& self.scope.identity.is_valid()
|
||||
&& Some(self.scope.identity) == info.scan_identity
|
||||
@@ -283,51 +276,28 @@ impl DirectoryCheckpoint {
|
||||
.parent
|
||||
.strip_prefix(&info.name)
|
||||
.and_then(|p| p.strip_prefix('/'))
|
||||
.is_some_and(|tail| tail.split('/').all(super::valid_component)));
|
||||
if matches_scope { self.validated_manifest() } else { None }
|
||||
.is_some_and(|tail| tail.split('/').all(super::valid_component)))
|
||||
&& self.valid_payload()
|
||||
}
|
||||
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 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 progress(&self, info: &DataUsageCacheInfo) -> Option<DirectoryProgress> {
|
||||
let done = self.aggregate.as_ref()?;
|
||||
let physical = self.physical.as_ref()?;
|
||||
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))
|
||||
(self.sealed && self.is_bound_to(info)).then(|| DirectoryProgress {
|
||||
parent: self.parent.clone(),
|
||||
physical: physical.clone(),
|
||||
manifest: self.manifest(),
|
||||
through: done.through.clone(),
|
||||
})
|
||||
}
|
||||
/// A display contribution contains only acknowledged compacted children.
|
||||
pub(crate) fn display_usage(&self, info: &DataUsageCacheInfo) -> Option<(DirectoryProgress, &DataUsageEntry, Option<u64>)> {
|
||||
@@ -337,16 +307,12 @@ 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.validated_manifest().is_some()
|
||||
self.version == 1 && self.parent == parent && self.scope.may_adopt(owner) && self.valid_payload()
|
||||
}
|
||||
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)
|
||||
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)
|
||||
&& 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| {
|
||||
@@ -355,8 +321,7 @@ 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)
|
||||
@@ -437,7 +402,7 @@ impl Recorder {
|
||||
digest: [0; 32],
|
||||
measured_at: work.measured_at,
|
||||
};
|
||||
checkpoint.checksum(checkpoint.manifest()).map(|digest| {
|
||||
checkpoint.checksum().map(|digest| {
|
||||
checkpoint.digest = digest;
|
||||
checkpoint
|
||||
})
|
||||
|
||||
@@ -71,9 +71,10 @@ struct LegacyCheckpoint {
|
||||
digest: [u8; 32],
|
||||
}
|
||||
|
||||
fn checkpoint_info() -> DataUsageCacheInfo {
|
||||
#[tokio::test]
|
||||
async fn display_progress_measurement_metadata_keeps_version_one_checkpoint_compatibility() {
|
||||
let plan = crate::DataUsageScanPlanDigest([1; 32]);
|
||||
DataUsageCacheInfo {
|
||||
let info = DataUsageCacheInfo {
|
||||
name: "bucket".into(),
|
||||
source: Some(DataUsageCacheSource::new(0, 0)),
|
||||
scan_identity: Some(DataUsageScanIdentity {
|
||||
@@ -91,12 +92,7 @@ fn checkpoint_info() -> DataUsageCacheInfo {
|
||||
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");
|
||||
@@ -113,69 +109,4 @@ 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"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2212,10 +2212,9 @@ impl ScannerIOCache for SetDisks {
|
||||
).await;
|
||||
bucket_observations_clone.lock().await.insert(bucket.name.clone(), observation.clone());
|
||||
}
|
||||
}
|
||||
let advanced = partial_progress_proven && cache.durable_scan_progress().advanced_from(&scan_position_before);
|
||||
if advanced {
|
||||
bucket_budget.record_durable_turn_progress();
|
||||
if partial_progress_proven && cache.durable_scan_progress().advanced_from(&scan_position_before) {
|
||||
bucket_budget.record_durable_turn_progress();
|
||||
}
|
||||
}
|
||||
if local_stop.reason().is_some() {
|
||||
// Recovery is independent of durable forward progress, but
|
||||
@@ -2244,8 +2243,9 @@ impl ScannerIOCache for SetDisks {
|
||||
}
|
||||
// Only saved forward motion earns another turn in this
|
||||
// cycle; otherwise the bucket waits for the next one.
|
||||
if advanced
|
||||
if partial_progress_proven
|
||||
&& 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(
|
||||
|
||||
Reference in New Issue
Block a user