mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-19 19:16:17 +00:00
refactor(obs): migrate metrics runtime/schema and tighten migration guards (#2584)
This commit is contained in:
@@ -16,6 +16,9 @@ use crate::fast_lock::{
|
||||
shard::LockShard,
|
||||
types::{LockMode, ObjectKey},
|
||||
};
|
||||
use rustfs_io_metrics::{
|
||||
record_read_lock_held_acquire, record_read_lock_held_release, record_write_lock_held_acquire, record_write_lock_held_release,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
@@ -40,6 +43,7 @@ pub struct FastLockGuard {
|
||||
impl FastLockGuard {
|
||||
pub(crate) fn new(key: ObjectKey, mode: LockMode, owner: Arc<str>, shard: Arc<LockShard>) -> Self {
|
||||
let guard_id = GUARD_ID_COUNTER.fetch_add(1, Ordering::Relaxed);
|
||||
record_lock_held_acquire(mode);
|
||||
Self {
|
||||
key,
|
||||
mode,
|
||||
@@ -102,6 +106,7 @@ impl FastLockGuard {
|
||||
let success = shard.release_lock_with_guard(&self.key, &self.owner, self.mode, self.guard_id);
|
||||
if success {
|
||||
self.released = true;
|
||||
record_lock_held_release(self.mode);
|
||||
// Unregister the guard after successful release
|
||||
shard.unregister_guard(self.guard_id);
|
||||
}
|
||||
@@ -158,6 +163,9 @@ impl Drop for FastLockGuard {
|
||||
self.guard_id
|
||||
);
|
||||
}
|
||||
if success {
|
||||
record_lock_held_release(self.mode);
|
||||
}
|
||||
// Always unregister the guard to prevent leaks, regardless of release success
|
||||
shard.unregister_guard(self.guard_id);
|
||||
} else {
|
||||
@@ -168,6 +176,22 @@ impl Drop for FastLockGuard {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn record_lock_held_acquire(mode: LockMode) {
|
||||
match mode {
|
||||
LockMode::Shared => record_read_lock_held_acquire(),
|
||||
LockMode::Exclusive => record_write_lock_held_acquire(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn record_lock_held_release(mode: LockMode) {
|
||||
match mode {
|
||||
LockMode::Shared => record_read_lock_held_release(),
|
||||
LockMode::Exclusive => record_write_lock_held_release(),
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for FastLockGuard {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("FastLockGuard")
|
||||
|
||||
Reference in New Issue
Block a user