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

View File

@@ -73,8 +73,11 @@ impl Stream for RetryTimer {
//println!("\njitter: {:?}", jitter);
//println!("sleep: {sleep:?}");
//println!("0000: {:?}", self.random as f64 * jitter / 100_f64);
let sleep_ms = sleep.as_millis() as u64;
sleep = Duration::from_millis(sleep_ms - (sleep_ms as f64 * (self.random as f64 * jitter / 100_f64)) as u64);
let sleep_ms = sleep.as_millis();
let reduction = ((sleep_ms as f64) * (self.random as f64 * jitter / 100_f64)).round() as u128;
let jittered_ms = sleep_ms.saturating_sub(reduction);
let clamped_ms = std::cmp::min(jittered_ms.max(1), u128::from(u64::MAX));
sleep = Duration::from_millis(clamped_ms as u64);
}
//println!("sleep: {sleep:?}");