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:
guojidan
2025-09-26 11:21:53 +08:00
committed by GitHub
parent 9b7f4d477a
commit 9b029d18b2
5 changed files with 223 additions and 99 deletions
+14 -2
View File
@@ -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();