mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-25 21:46:50 +00:00
fix(admin): report refreshed lock lease TTLs (#6230)
This commit is contained in:
@@ -295,9 +295,17 @@ impl FastObjectLockManager {
|
||||
/// Powers the admin "top locks" view. Order is shard-then-insertion and is
|
||||
/// not otherwise stable across calls.
|
||||
pub fn list_locks(&self) -> Vec<crate::fast_lock::types::ObjectLockInfo> {
|
||||
self.list_locks_with_holder_counts()
|
||||
.into_iter()
|
||||
.map(|(info, _)| info)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Enumerate held locks with the number of guards represented by each owner.
|
||||
pub fn list_locks_with_holder_counts(&self) -> Vec<(crate::fast_lock::types::ObjectLockInfo, u32)> {
|
||||
let mut infos = Vec::new();
|
||||
for shard in &self.shards {
|
||||
infos.extend(shard.list_locks());
|
||||
infos.extend(shard.list_locks_with_holder_counts());
|
||||
}
|
||||
infos
|
||||
}
|
||||
@@ -556,6 +564,10 @@ mod tests {
|
||||
.acquire_read_lock(read_key.clone(), "reader")
|
||||
.await
|
||||
.expect("read lock should acquire");
|
||||
let _second_read_guard = manager
|
||||
.acquire_read_lock(read_key.clone(), "reader")
|
||||
.await
|
||||
.expect("second read lock should acquire");
|
||||
|
||||
let mut locks = manager.list_locks();
|
||||
locks.sort_by(|a, b| a.key.object.cmp(&b.key.object));
|
||||
@@ -569,6 +581,18 @@ mod tests {
|
||||
assert_eq!(write.mode, LockMode::Exclusive);
|
||||
assert_eq!(write.owner.as_ref(), "writer");
|
||||
|
||||
let counts = manager.list_locks_with_holder_counts();
|
||||
let (_, read_holder_count) = counts
|
||||
.iter()
|
||||
.find(|(info, _)| info.key == read_key)
|
||||
.expect("read holder count listed");
|
||||
assert_eq!(*read_holder_count, 2);
|
||||
let (_, write_holder_count) = counts
|
||||
.iter()
|
||||
.find(|(info, _)| info.key == write_key)
|
||||
.expect("write holder count listed");
|
||||
assert_eq!(*write_holder_count, 1);
|
||||
|
||||
manager.shutdown().await;
|
||||
}
|
||||
|
||||
|
||||
@@ -544,6 +544,13 @@ impl LockShard {
|
||||
/// holder. Entries for objects that are tracked but not currently locked
|
||||
/// (e.g. pooled-but-idle state) are skipped.
|
||||
pub fn list_locks(&self) -> Vec<crate::fast_lock::types::ObjectLockInfo> {
|
||||
self.list_locks_with_holder_counts()
|
||||
.into_iter()
|
||||
.map(|(info, _)| info)
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn list_locks_with_holder_counts(&self) -> Vec<(crate::fast_lock::types::ObjectLockInfo, u32)> {
|
||||
let objects = self.objects.read();
|
||||
let mut infos = Vec::new();
|
||||
for (key, state) in objects.iter() {
|
||||
@@ -558,14 +565,17 @@ impl LockShard {
|
||||
.acquired_at
|
||||
.checked_add(info.lock_timeout)
|
||||
.unwrap_or_else(|| info.acquired_at + crate::fast_lock::DEFAULT_LOCK_TIMEOUT);
|
||||
infos.push(crate::fast_lock::types::ObjectLockInfo {
|
||||
key: key.clone(),
|
||||
mode,
|
||||
owner: info.owner,
|
||||
acquired_at: info.acquired_at,
|
||||
expires_at,
|
||||
priority,
|
||||
});
|
||||
infos.push((
|
||||
crate::fast_lock::types::ObjectLockInfo {
|
||||
key: key.clone(),
|
||||
mode,
|
||||
owner: info.owner,
|
||||
acquired_at: info.acquired_at,
|
||||
expires_at,
|
||||
priority,
|
||||
},
|
||||
1,
|
||||
));
|
||||
}
|
||||
}
|
||||
LockMode::Shared => {
|
||||
@@ -574,14 +584,17 @@ impl LockShard {
|
||||
.acquired_at
|
||||
.checked_add(entry.lock_timeout)
|
||||
.unwrap_or_else(|| entry.acquired_at + crate::fast_lock::DEFAULT_LOCK_TIMEOUT);
|
||||
infos.push(crate::fast_lock::types::ObjectLockInfo {
|
||||
key: key.clone(),
|
||||
mode,
|
||||
owner: entry.owner.clone(),
|
||||
acquired_at: entry.acquired_at,
|
||||
expires_at,
|
||||
priority,
|
||||
});
|
||||
infos.push((
|
||||
crate::fast_lock::types::ObjectLockInfo {
|
||||
key: key.clone(),
|
||||
mode,
|
||||
owner: entry.owner.clone(),
|
||||
acquired_at: entry.acquired_at,
|
||||
expires_at,
|
||||
priority,
|
||||
},
|
||||
entry.count,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user