mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-31 01:09:23 +00:00
feat(lock): enhance lock management with timeout and ownership tracking (#589)
- Add lock timeout support and track acquisition time in lock state - Improve lock conflict handling with detailed error messages - Optimize lock reuse when already held by same owner - Refactor lock state to store owner info and timeout duration - Update all lock operations to handle new state structure Signed-off-by: junxiang Mu <1948535941@qq.com>
This commit is contained in:
@@ -111,6 +111,9 @@ impl ObjectLockState {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::fast_lock::state::{ExclusiveOwnerInfo, SharedOwnerEntry};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
#[test]
|
||||
fn test_object_pool() {
|
||||
@@ -142,8 +145,17 @@ mod tests {
|
||||
let mut state = ObjectLockState::new();
|
||||
|
||||
// Modify state
|
||||
*state.current_owner.write() = Some("test_owner".into());
|
||||
state.shared_owners.write().push("shared_owner".into());
|
||||
*state.current_owner.write() = Some(ExclusiveOwnerInfo {
|
||||
owner: Arc::from("test_owner"),
|
||||
acquired_at: SystemTime::now(),
|
||||
lock_timeout: Duration::from_secs(30),
|
||||
});
|
||||
state.shared_owners.write().push(SharedOwnerEntry {
|
||||
owner: Arc::from("shared_owner"),
|
||||
count: 1,
|
||||
acquired_at: SystemTime::now(),
|
||||
lock_timeout: Duration::from_secs(30),
|
||||
});
|
||||
|
||||
// Reset
|
||||
state.reset_for_reuse();
|
||||
|
||||
Reference in New Issue
Block a user