redo error handling in xredis

This commit is contained in:
aecsocket
2026-08-04 17:20:20 +01:00
committed by Calum H.
parent 99377f8436
commit a414ff0853
20 changed files with 408 additions and 327 deletions
+3 -14
View File
@@ -3,11 +3,10 @@ use std::sync::atomic::{AtomicBool, Ordering};
use dashmap::DashMap;
use dashmap::mapref::entry::Entry;
use eyre::{Result, WrapErr};
use tokio::sync::Notify;
use tokio::time::{Instant, timeout_at};
use crate::Error;
#[derive(Clone)]
pub(in crate::cache) struct LockCoordinator {
locks: Arc<DashMap<String, Arc<LockState>>>,
@@ -76,10 +75,7 @@ pub(in crate::cache) struct LockWaiter {
}
impl LockWaiter {
pub(in crate::cache) async fn wait(
self,
deadline: Instant,
) -> Result<(), Error> {
pub(in crate::cache) async fn wait(self, deadline: Instant) -> Result<()> {
loop {
if self.state.released.load(Ordering::Acquire) {
return Ok(());
@@ -94,7 +90,7 @@ impl LockWaiter {
timeout_at(deadline, notified)
.await
.map_err(|_| lock_timeout())?;
.wrap_err("waiting for local Redis cache lock")?;
}
}
}
@@ -112,10 +108,3 @@ impl LockState {
}
}
}
fn lock_timeout() -> Error {
Error::LocalCacheTimeout {
released: 0,
total: 1,
}
}