refactor(config): normalize scanner env naming (#2129)

This commit is contained in:
安正超
2026-03-11 22:41:41 +08:00
committed by GitHub
parent aa84d34bf8
commit 83fb530609
4 changed files with 50 additions and 6 deletions
+15 -4
View File
@@ -22,7 +22,10 @@ use crate::{DataUsageInfo, ScannerError};
use chrono::{DateTime, Utc};
use rustfs_common::heal_channel::HealScanMode;
use rustfs_common::metrics::{CurrentCycle, Metric, Metrics, emit_scan_cycle_complete, global_metrics};
use rustfs_config::{DEFAULT_SCANNER_SPEED, ENV_DATA_SCANNER_START_DELAY_SECS, ENV_SCANNER_SPEED, ScannerSpeed};
use rustfs_config::DEFAULT_SCANNER_SPEED;
use rustfs_config::ENV_SCANNER_SPEED;
use rustfs_config::ENV_SCANNER_START_DELAY_SECS;
use rustfs_config::ScannerSpeed;
use rustfs_ecstore::StorageAPI as _;
use rustfs_ecstore::config::com::{read_config, save_config};
use rustfs_ecstore::disk::RUSTFS_META_BUCKET;
@@ -35,17 +38,25 @@ use tokio::time::{Duration, Instant};
use tokio_util::sync::CancellationToken;
use tracing::{debug, error, info, instrument, warn};
/// Returns the base cycle interval. If `RUSTFS_DATA_SCANNER_START_DELAY_SECS`
/// is set, it takes precedence; otherwise the value is derived from the
const ENV_SCANNER_START_DELAY_SECS_DEPRECATED: &str = "RUSTFS_DATA_SCANNER_START_DELAY_SECS";
/// Returns the base cycle interval. If `RUSTFS_SCANNER_START_DELAY_SECS`
/// is set (or `RUSTFS_DATA_SCANNER_START_DELAY_SECS` as deprecated alias),
/// it takes precedence; otherwise the value is derived from the
/// `RUSTFS_SCANNER_SPEED` preset.
fn cycle_interval() -> Duration {
if let Some(secs) = rustfs_utils::get_env_opt_u64(ENV_DATA_SCANNER_START_DELAY_SECS) {
if let Some(secs) = scanner_start_delay_secs() {
return Duration::from_secs(secs);
}
let speed_str = rustfs_utils::get_env_str(ENV_SCANNER_SPEED, DEFAULT_SCANNER_SPEED);
ScannerSpeed::from_env_str(&speed_str).cycle_interval()
}
fn scanner_start_delay_secs() -> Option<u64> {
let deprecated = [ENV_SCANNER_START_DELAY_SECS_DEPRECATED];
rustfs_utils::get_env_opt_u64_with_aliases(ENV_SCANNER_START_DELAY_SECS, &deprecated)
}
/// Compute a randomized inter-cycle sleep.
// Delay is scan interval +- 10%, with a floor of 1 second.
fn randomized_cycle_delay() -> Duration {