From c0cdad2192ec7119741f276ab877a93b50ca2011 Mon Sep 17 00:00:00 2001 From: weisd Date: Wed, 17 Dec 2025 11:03:54 +0800 Subject: [PATCH] add DEFAULT_HEAL_OBJECT_SELECT_PROB --- crates/config/src/constants/heal.rs | 15 +++++++++++++++ crates/scanner/src/scanner_folder.rs | 7 +++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/config/src/constants/heal.rs b/crates/config/src/constants/heal.rs index 728806be..6134a75a 100644 --- a/crates/config/src/constants/heal.rs +++ b/crates/config/src/constants/heal.rs @@ -86,3 +86,18 @@ pub const DEFAULT_HEAL_TASK_TIMEOUT_SECS: u64 = 300; // 5 minutes /// - Rationale: This default concurrency limit helps balance healing speed with resource usage, preventing system overload. /// - Adjustments: Users may modify this value via the `RUSTFS_HEAL_MAX_CONCURRENT_HEALS` environment variable based on their system capacity and expected heal workload. pub const DEFAULT_HEAL_MAX_CONCURRENT_HEALS: usize = 4; + +/// Environment variable name that specifies the heal object select probability. +/// - Purpose: Control the probability of selecting objects for healing operations. +/// - Unit: integer probability value. +/// - Valid values: any positive integer. +/// - Semantics: Higher values increase the likelihood of object selection for healing; tune according to healing aggressiveness and system capacity. +/// - Example: `export RUSTFS_HEAL_OBJECT_SELECT_PROB=1024` +/// - Note: This probability affects how frequently objects are selected for background healing operations. +pub const ENV_HEAL_OBJECT_SELECT_PROB: &str = "RUSTFS_HEAL_OBJECT_SELECT_PROB"; + +/// Default heal object select probability if not specified in the environment variable. +/// - Value: 10. +/// - Rationale: This default provides a conservative selection rate for healing operations. +/// - Adjustments: Users may modify this value via the `RUSTFS_HEAL_OBJECT_SELECT_PROB` environment variable based on their healing requirements and system performance. +pub const DEFAULT_HEAL_OBJECT_SELECT_PROB: u32 = 1024; diff --git a/crates/scanner/src/scanner_folder.rs b/crates/scanner/src/scanner_folder.rs index cab6d841..ba288b22 100644 --- a/crates/scanner/src/scanner_folder.rs +++ b/crates/scanner/src/scanner_folder.rs @@ -24,6 +24,7 @@ use crate::metrics::{UpdateCurrentPathFn, current_path_updater}; use crate::scanner_io::ScannerIODisk as _; use rustfs_common::heal_channel::{HEAL_DELETE_DANGLING, HealChannelRequest, HealOpts, HealScanMode, send_heal_request}; use rustfs_common::metrics::IlmAction; +use rustfs_config::{DEFAULT_HEAL_OBJECT_SELECT_PROB, ENV_HEAL_OBJECT_SELECT_PROB}; use rustfs_ecstore::StorageAPI; use rustfs_ecstore::bucket::lifecycle::bucket_lifecycle_audit::LcEventSrc; use rustfs_ecstore::bucket::lifecycle::bucket_lifecycle_ops::apply_expiry_rule; @@ -58,7 +59,9 @@ const DATA_SCANNER_COMPACT_LEAST_OBJECT: usize = 500; const DATA_SCANNER_COMPACT_AT_CHILDREN: usize = 10000; const DATA_SCANNER_COMPACT_AT_FOLDERS: usize = DATA_SCANNER_COMPACT_AT_CHILDREN / 4; const DATA_SCANNER_FORCE_COMPACT_AT_FOLDERS: usize = 250_000; -const HEAL_OBJECT_SELECT_PROB: u32 = 10; // TODO: 1024 +fn heal_object_select_prob() -> u32 { + rustfs_utils::get_env_usize(ENV_HEAL_OBJECT_SELECT_PROB, DEFAULT_HEAL_OBJECT_SELECT_PROB as usize) as u32 +} /// Cached folder information for scanning #[derive(Clone, Debug)] @@ -1130,7 +1133,7 @@ pub async fn scan_data_folder( // Create heal_object_select flag let heal_object_select = if is_erasure_mode && !cache.info.skip_healing { - HEAL_OBJECT_SELECT_PROB + heal_object_select_prob() } else { 0 };