perf(heal): reduce held MRF probe and scan overhead

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:
Hauser Zhi
2026-12-01 17:53:09 +08:00
parent d79041ab76
commit b8e8b65e1c
4 changed files with 69 additions and 55 deletions
@@ -603,18 +603,18 @@ impl SetDisks {
/// With the lifecycle fence held by the caller, check the exact set without
/// repairing payloads or settling delete transactions.
pub(crate) async fn probe_mrf_unversioned_absence(&self, bucket: &str, object: &str) -> crate::error::Result<bool> {
// Lock order matches delete recovery: lifecycle, raw object, transaction, then inventory validation.
let namespace = self.new_ns_lock(bucket, object).await?;
let object_guard = namespace.get_read_lock(crate::set_disk::get_lock_acquire_timeout()).await?;
let disks = self.get_disks_internal().await;
if disks.len() != self.set_drive_count || disks.iter().any(Option::is_none) {
let first = {
let disks = self.disks.read().await;
disks
.iter()
.flatten()
.find(|disk| disk.is_local())
.or_else(|| disks.iter().flatten().next())
.cloned()
};
let Some(first) = first else {
return Ok(false);
}
let first_disk = disks
.iter()
.position(|disk| disk.as_ref().is_some_and(|disk| disk.is_local()))
.unwrap_or(0);
};
let missing = async |disk: &DiskStore| match disk
.read_version("", bucket, object, "", &crate::disk::ReadOptions::default())
.await
@@ -623,13 +623,17 @@ impl SetDisks {
Ok(_) => Ok(false),
Err(error) => Err(error),
};
let Some(first) = disks.get(first_disk).and_then(Option::as_ref) else {
return Ok(false);
};
if !missing(first).await? {
if !missing(&first).await? {
return Ok(false);
}
// Lock order matches delete recovery: lifecycle, raw object, transaction, then inventory validation.
let namespace = self.new_ns_lock(bucket, object).await?;
let object_guard = namespace.get_read_lock(crate::set_disk::get_lock_acquire_timeout()).await?;
let transaction_guard = self.acquire_delete_transaction_lock(bucket, object).await?;
let disks = self.get_disks_internal().await;
if disks.len() != self.set_drive_count || disks.iter().any(Option::is_none) {
return Ok(false);
}
// The fast rejection is a hint. Read every member under both locks
// before accepting a candidate absence.
if try_join_all(disks.iter().flatten().map(missing)).await?.contains(&false) {
+1 -1
View File
@@ -242,7 +242,7 @@ pub(crate) fn classify_heal_error(error: &Error) -> HealErrorClass {
| Error::ReplacementNamespaceChanged
| Error::TransientSkip { .. }
| Error::BucketDiscoveryIncomplete => HealErrorClass::Transient,
Error::LegacyMrfUnverified { .. } => HealErrorClass::Permanent,
Error::LegacyMrfUnverified { .. } | Error::MrfStorageProofUnavailable { .. } => HealErrorClass::Permanent,
Error::Storage(error) => classify_storage_error(error),
Error::Disk(error) => classify_disk_error(error),
Error::Io(error) => classify_io_error(error),
+40 -36
View File
@@ -22,7 +22,7 @@ use rustfs_common::mrf_channel::{
};
use rustfs_heal_contracts::heal_channel::HealAdmissionResult;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque, hash_map::Entry};
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use tokio::time::Instant;
@@ -420,7 +420,7 @@ impl PartialWrites {
) -> Option<MrfDurableRepairAnchor> {
let now = Instant::now();
let mut held = None;
let mut intents_by_generation: HashMap<(Arc<str>, Uuid), Vec<&MrfIntent>> = HashMap::new();
let mut generations = HashMap::new();
for (key, entry) in &self.entries {
if !entry.persisted {
continue;
@@ -431,12 +431,36 @@ impl PartialWrites {
if !MrfDurableRepairAnchor::is_eligible_for_source(&entry.intent, source_incarnation) {
continue;
}
intents_by_generation
.entry((entry.intent.bucket.clone(), source_incarnation))
.or_default()
.push(&entry.intent);
// Reuse the retirement scan and give the oldest due hold the next
// probe. No second index or scan is needed when a key is parked.
let bucket = &entry.intent.bucket;
let retirement = match generations.entry((bucket.as_ref(), source_incarnation)) {
Entry::Occupied(previous) => previous.into_mut(),
Entry::Vacant(generation) => {
let cache_key = (bucket.clone(), source_incarnation);
let retired = match self.retirement_checks.get(&cache_key) {
Some((_, true)) => true,
Some((checked_at, false))
if now.saturating_duration_since(*checked_at) < MRF_RETIREMENT_PROOF_RECHECK_INTERVAL =>
{
false
}
_ => {
let retired = manager
.mrf_bucket_incarnation_retired(bucket, source_incarnation)
.await
.unwrap_or(false);
self.retirement_checks.insert(cache_key, (now, retired));
retired
}
};
generation.insert(retired.then(Vec::new))
}
};
if let Some(intents) = retirement {
intents.push(&entry.intent);
continue;
}
// Schedule the oldest due hold during the same retirement scan.
if probe_held
&& matches!(entry.state, ResponsibilityState::HeldUnverifiedLegacy { .. })
&& entry.intent.kind == MrfKind::PartialWrite
@@ -451,35 +475,15 @@ impl PartialWrites {
}
self.retirement_checks
.retain(|generation, _| intents_by_generation.contains_key(generation));
for ((bucket, incarnation), intents) in intents_by_generation {
let retired = match self.retirement_checks.get(&(bucket.clone(), incarnation)) {
Some((_, true)) => true,
Some((checked_at, false))
if now.saturating_duration_since(*checked_at) < MRF_RETIREMENT_PROOF_RECHECK_INTERVAL =>
{
false
}
_ => {
let retired = manager
.mrf_bucket_incarnation_retired(bucket.as_ref(), incarnation)
.await
.unwrap_or(false);
self.retirement_checks.insert((bucket.clone(), incarnation), (now, retired));
retired
}
};
if !retired {
continue;
}
.retain(|(bucket, incarnation), _| generations.contains_key(&(bucket.as_ref(), *incarnation)));
for intent in intents {
let Some(anchor) = MrfDurableRepairAnchor::from_intent(intent, incarnation)
.filter(|anchor| anchor.bucket_incarnation_id == incarnation)
else {
continue;
};
publish_mrf_absence(anchor);
// Group emitted proofs by incarnation. Only retired generations need
// per-intent scratch storage.
for ((_, incarnation), intents) in generations {
for intent in intents.into_iter().flatten() {
if let Some(anchor) = MrfDurableRepairAnchor::from_intent(intent, incarnation) {
publish_mrf_absence(anchor);
}
}
}
+9 -3
View File
@@ -740,7 +740,7 @@ async fn degraded_deleted_partial_write_is_discharged_by_an_absence_proof_inner(
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn held_unversioned_partial_write_is_discharged_automatically_after_delete() {
use rustfs_common::mrf_channel::{MrfDurableRepairAnchor, MrfIntent, MrfKind, MrfScope, try_rearm_mrf_replay_intent};
use storage_api::integration::{DeleteOptions, lookup_config_for_pools};
use storage_api::integration::{DeleteOptions, NamespaceLocking as _, lookup_config_for_pools};
const BUCKET: &str = "held-absence";
const OBJECT: &str = "chunks/held-then-deleted";
@@ -802,12 +802,18 @@ async fn held_unversioned_partial_write_is_discharged_automatically_after_delete
rustfs_common::mrf_channel::MrfIngressResult::Enqueued
);
let mut anchor = MrfDurableRepairAnchor::from_intent(&intent, incarnation).expect("valid exact test anchor");
let namespace = set.new_ns_lock(BUCKET, OBJECT).await.expect("object namespace lock");
let writer = namespace
.get_write_lock(Duration::from_secs(2))
.await
.expect("hold object write lock");
assert!(
!env.ecstore
.probe_mrf_unversioned_absence(&anchor)
!tokio::time::timeout(Duration::from_secs(2), env.ecstore.probe_mrf_unversioned_absence(&anchor))
.await
.expect("a present object must finish the probe while the writer owns its namespace")
.expect("check the present object")
);
drop(writer);
assert!(snapshot_contains(OBJECT).await, "a healthy legacy object cannot retire the obligation");
const PREPARED: &str = "chunks/prepared-delete";