From 028be4f604dedca9f557b01a3d48e39c202ad747 Mon Sep 17 00:00:00 2001 From: Zhengchao An Date: Fri, 28 Aug 2026 16:21:27 +0800 Subject: [PATCH] refactor(heal): migrate mainline throttle to shared ForegroundPressure (#6780) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The heal manager carried its own byte-identical copy of the foreground pressure type and threshold computation that ecstore's data-movement backpressure also carries, so every change to the admission-utilization rules had to be mirrored by hand across two crates. The shared `ForegroundPressure` and `foreground_pressure` added to `rustfs-concurrency` now own that logic, and heal already depends on that crate, so this removes the duplicate without adding a crate edge. `mainline_throttle_active` keeps the parts that are specific to this call site: the `mainline_throttle_enable` and both-thresholds-zero short circuit that avoids touching the provider at all, the optional-provider unwrap, and the heal-side threshold fields. Everything downstream is untouched — the `reason()` labels `foreground_read_pressure`, `foreground_write_pressure`, and `foreground_pressure` are byte-identical to the removed implementation, so the `rustfs_heal_mainline_throttle_total` reason label and the `heal_mainline_throttle` log fields keep their observability contract. Refs rustfs/backlog#2049 (cherry picked from commit ec491bcbd8939e5978cd94f9a44cffb70d09fade) (cherry picked from commit e800f29d6806591689204b3712300800b480beae) Co-authored-by: houseme --- crates/heal/src/heal/manager.rs | 44 ++++++--------------------- crates/heal/src/heal/manager/queue.rs | 17 ----------- 2 files changed, 9 insertions(+), 52 deletions(-) diff --git a/crates/heal/src/heal/manager.rs b/crates/heal/src/heal/manager.rs index cb159772a..d36c9f9a7 100644 --- a/crates/heal/src/heal/manager.rs +++ b/crates/heal/src/heal/manager.rs @@ -20,7 +20,10 @@ use crate::heal::{ }; use crate::{Error, Result}; use metrics::{counter, gauge}; -use rustfs_concurrency::{AdmissionState, WorkloadAdmissionSnapshotProvider, WorkloadClass}; +use rustfs_concurrency::WorkloadAdmissionSnapshotProvider; +use rustfs_concurrency::workload::{ForegroundPressure, foreground_pressure}; +#[cfg(test)] +use rustfs_concurrency::{AdmissionState, WorkloadClass}; use rustfs_heal_contracts::heal_channel::{ HealAdmissionDropReason, HealAdmissionReceipt, HealAdmissionResult, HealRequestSource, }; @@ -813,40 +816,11 @@ impl HealManager { } let provider = provider.as_ref()?; - let snapshot = provider.workload_admission_snapshot(); - [ - (WorkloadClass::ForegroundRead, config.mainline_read_utilization_high_percent), - (WorkloadClass::ForegroundWrite, config.mainline_write_utilization_high_percent), - ] - .into_iter() - .filter_map(|(class, threshold_pct)| { - if threshold_pct == 0 { - return None; - } - - let entry = snapshot.get(class)?; - let usage_pct = if matches!(entry.state, AdmissionState::Saturated) { - 100 - } else { - let limit = entry.limit?; - if limit == 0 { - return None; - } - entry - .active - .unwrap_or(0) - .saturating_mul(100) - .checked_div(limit) - .unwrap_or(100) - }; - - (usage_pct >= threshold_pct).then_some(ForegroundPressure { - class, - usage_pct, - threshold_pct, - }) - }) - .max_by_key(|pressure| pressure.usage_pct) + foreground_pressure( + &provider.workload_admission_snapshot(), + config.mainline_read_utilization_high_percent, + config.mainline_write_utilization_high_percent, + ) } fn schedule_mainline_throttle_recheck(notify: Arc, delay: Duration) { diff --git a/crates/heal/src/heal/manager/queue.rs b/crates/heal/src/heal/manager/queue.rs index 28bedaba4..b4608f27b 100644 --- a/crates/heal/src/heal/manager/queue.rs +++ b/crates/heal/src/heal/manager/queue.rs @@ -78,23 +78,6 @@ pub(super) enum QueuePushOutcome { Merged, } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub(super) struct ForegroundPressure { - pub(super) class: WorkloadClass, - pub(super) usage_pct: usize, - pub(super) threshold_pct: usize, -} - -impl ForegroundPressure { - pub(super) const fn reason(self) -> &'static str { - match self.class { - WorkloadClass::ForegroundRead => "foreground_read_pressure", - WorkloadClass::ForegroundWrite => "foreground_write_pressure", - _ => "foreground_pressure", - } - } -} - #[derive(Debug, Clone)] pub(super) struct CompletedHealStatus { pub(super) heal_type: HealType,