mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-24 13:16:28 +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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user