pub struct EntityLockManager { /* private fields */ }Expand description
Advisory entity lock manager for a single session.
Implementations§
Source§impl EntityLockManager
impl EntityLockManager
pub fn new(pool: DbPool, session_id: impl Into<String>) -> Self
Sourcepub async fn try_acquire(&self, entity_name: &str) -> Result<bool, MemoryError>
pub async fn try_acquire(&self, entity_name: &str) -> Result<bool, MemoryError>
Try to acquire an advisory lock on entity_name.
- If no lock exists: INSERT and return
true. - If the current session already holds the lock: UPDATE
expires_at, returntrue. - If another session holds a non-expired lock: retry with exponential backoff.
- After
MAX_RETRIESfailures: returnfalse(caller proceeds without lock).
Expired locks (past expires_at) are atomically reclaimed on the INSERT conflict.
§Errors
Returns an error on database failures.
Sourcepub async fn extend_lock(
&self,
entity_name: &str,
extra_secs: i64,
) -> Result<bool, MemoryError>
pub async fn extend_lock( &self, entity_name: &str, extra_secs: i64, ) -> Result<bool, MemoryError>
Extend the TTL of a lock held by this session.
Called before long operations (e.g., an LLM call inside entity resolution) to prevent the lock from expiring while work is in progress.
Returns true if the lock was extended (still held by this session).
§Errors
Returns an error on database failures.
Sourcepub async fn release(&self, entity_name: &str) -> Result<(), MemoryError>
pub async fn release(&self, entity_name: &str) -> Result<(), MemoryError>
Release the lock on entity_name held by this session.
No-op if the lock was already reclaimed by another session.
§Errors
Returns an error on database failures.
Sourcepub async fn release_all(&self) -> Result<(), MemoryError>
pub async fn release_all(&self) -> Result<(), MemoryError>
Release all locks held by this session.
Called on agent shutdown to avoid leaving locks until TTL expiry.
§Errors
Returns an error on database failures.
Auto Trait Implementations§
impl Freeze for EntityLockManager
impl !RefUnwindSafe for EntityLockManager
impl Send for EntityLockManager
impl Sync for EntityLockManager
impl Unpin for EntityLockManager
impl UnsafeUnpin for EntityLockManager
impl !UnwindSafe for EntityLockManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request