mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-12 16:16:55 +00:00
fix: correct SNSD cluster diagnostics (#5930)
This commit is contained in:
@@ -82,6 +82,7 @@ pub use storage_api::ScannerReplicationConfig as ReplicationConfig;
|
||||
pub use storage_api::scan::SCANNER_ACTIVITY_PROTOCOL_VERSION;
|
||||
|
||||
static SCANNER_ACTIVE_WORK_UNITS: AtomicU64 = AtomicU64::new(0);
|
||||
static SCANNER_RUNTIME_INSTANCES: AtomicU64 = AtomicU64::new(0);
|
||||
static SCANNER_FOREGROUND_READ_ACTIVITY: AtomicU64 = AtomicU64::new(0);
|
||||
static SCANNER_FOREGROUND_STREAM_READS: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
@@ -89,6 +90,10 @@ pub fn current_scanner_activity() -> u64 {
|
||||
SCANNER_ACTIVE_WORK_UNITS.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
pub fn scanner_runtime_initialized() -> bool {
|
||||
SCANNER_RUNTIME_INSTANCES.load(Ordering::Relaxed) > 0
|
||||
}
|
||||
|
||||
pub fn set_foreground_read_activity(active: usize) {
|
||||
let active = u64::try_from(active).unwrap_or(u64::MAX);
|
||||
SCANNER_FOREGROUND_READ_ACTIVITY.store(active, Ordering::Relaxed);
|
||||
@@ -138,6 +143,26 @@ impl ScannerActivityGuard {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct ScannerRuntimeGuard;
|
||||
|
||||
impl ScannerRuntimeGuard {
|
||||
pub(crate) fn new() -> Self {
|
||||
SCANNER_RUNTIME_INSTANCES.fetch_add(1, Ordering::Relaxed);
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ScannerRuntimeGuard {
|
||||
fn drop(&mut self) {
|
||||
let _ = SCANNER_RUNTIME_INSTANCES.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |current| current.checked_sub(1));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn reset_scanner_runtime_instances_for_test() {
|
||||
SCANNER_RUNTIME_INSTANCES.store(0, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
impl Drop for ScannerActivityGuard {
|
||||
fn drop(&mut self) {
|
||||
let _ = SCANNER_ACTIVE_WORK_UNITS
|
||||
@@ -559,4 +584,18 @@ mod tests {
|
||||
set_foreground_read_activity(0);
|
||||
assert_eq!(current_foreground_read_activity(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn scanner_runtime_guard_tracks_runtime_lifetime() {
|
||||
reset_scanner_runtime_instances_for_test();
|
||||
assert!(!scanner_runtime_initialized());
|
||||
|
||||
{
|
||||
let _guard = ScannerRuntimeGuard::new();
|
||||
assert!(scanner_runtime_initialized());
|
||||
}
|
||||
|
||||
assert!(!scanner_runtime_initialized());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ use crate::scanner_io::{
|
||||
scanner_dirty_usage_state, scanner_maintenance_changed, scanner_maintenance_generation,
|
||||
};
|
||||
use crate::sleeper::{SCANNER_SLEEPER, set_scanner_default_speed};
|
||||
use crate::{DataUsageInfo, ScannerActivityGuard, ScannerError};
|
||||
use crate::{DataUsageInfo, ScannerActivityGuard, ScannerError, ScannerRuntimeGuard};
|
||||
use crate::{ScannerConfigObjectDelete, ScannerObjectIO, ScannerObjectOptions};
|
||||
use bytes::Bytes;
|
||||
use chrono::{DateTime, Utc};
|
||||
@@ -1312,7 +1312,9 @@ pub async fn init_data_scanner(ctx: CancellationToken, storeapi: Arc<ECStore>) {
|
||||
let replication_active = startup_features.replication;
|
||||
let ctx_clone = ctx;
|
||||
let storeapi_clone = storeapi;
|
||||
let runtime_guard = ScannerRuntimeGuard::new();
|
||||
tokio::spawn(async move {
|
||||
let _runtime_guard = runtime_guard;
|
||||
let (usage_cache_is_cold, has_buckets) = initial_scanner_startup_usage_state(&storeapi_clone).await;
|
||||
let sleep_time = initial_scanner_delay_for_startup(
|
||||
scanner_start_delay().map(|duration| duration.as_secs()),
|
||||
|
||||
Reference in New Issue
Block a user