pub struct CoordinationGuard { /* private fields */ }Expand description
Guard type that releases leadership when dropped.
Holds the advisory lock key and the actual database connection that acquired the lock. This is critical because PostgreSQL advisory locks are session-scoped: the unlock must happen on the same connection that acquired the lock.
§Lock Release Behavior
The guard attempts to explicitly release the advisory lock when dropped:
-
Multi-threaded runtime: Uses
block_in_placeto synchronously release the lock before the guard is fully dropped. -
Single-threaded runtime: Spawns a task to release the lock asynchronously. This task may not execute before process shutdown, in which case the lock is released when the PostgreSQL session ends (connection closes).
§PostgreSQL Session-Scoped Locks
PostgreSQL advisory locks acquired with pg_try_advisory_lock are session-scoped
and automatically released when the database connection closes. This provides a
safety net: even if explicit unlock fails or is skipped, the lock will be released
when:
- The connection is returned to the pool and recycled
- The connection pool is shut down
- The database connection times out
For production deployments, configure appropriate connection pool idle timeouts to ensure timely lock release on ungraceful shutdown.
Trait Implementations§
Source§impl Debug for CoordinationGuard
impl Debug for CoordinationGuard
Auto Trait Implementations§
impl Freeze for CoordinationGuard
impl !RefUnwindSafe for CoordinationGuard
impl Send for CoordinationGuard
impl Sync for CoordinationGuard
impl Unpin for CoordinationGuard
impl !UnwindSafe for CoordinationGuard
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 more