pub struct MySqlDistributedReaderWriterLock { /* private fields */ }Expand description
A MySQL-based distributed reader-writer lock.
Uses a database table to track reader-writer state and transactions to ensure atomic operations. This allows multiple readers to hold the lock simultaneously while ensuring writers get exclusive access.
The table schema is:
CREATE TABLE distributed_locks (
lock_name VARCHAR(255) PRIMARY KEY,
reader_count INT NOT NULL DEFAULT 0,
writer_held TINYINT(1) NOT NULL DEFAULT 0,
version INT NOT NULL DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);Trait Implementations§
Source§impl DistributedReaderWriterLock for MySqlDistributedReaderWriterLock
impl DistributedReaderWriterLock for MySqlDistributedReaderWriterLock
Source§type ReadHandle = MySqlReadLockHandle
type ReadHandle = MySqlReadLockHandle
Handle type for read (shared) locks.
Source§type WriteHandle = MySqlWriteLockHandle
type WriteHandle = MySqlWriteLockHandle
Handle type for write (exclusive) locks.
Source§async fn acquire_read(
&self,
timeout: Option<Duration>,
) -> LockResult<Self::ReadHandle>
async fn acquire_read( &self, timeout: Option<Duration>, ) -> LockResult<Self::ReadHandle>
Acquires a read (shared) lock. Read more
Source§async fn try_acquire_read(&self) -> LockResult<Option<Self::ReadHandle>>
async fn try_acquire_read(&self) -> LockResult<Option<Self::ReadHandle>>
Attempts to acquire a read lock without waiting.
Source§async fn acquire_write(
&self,
timeout: Option<Duration>,
) -> LockResult<Self::WriteHandle>
async fn acquire_write( &self, timeout: Option<Duration>, ) -> LockResult<Self::WriteHandle>
Acquires a write (exclusive) lock. Read more
Source§async fn try_acquire_write(&self) -> LockResult<Option<Self::WriteHandle>>
async fn try_acquire_write(&self) -> LockResult<Option<Self::WriteHandle>>
Attempts to acquire a write lock without waiting.
Auto Trait Implementations§
impl Freeze for MySqlDistributedReaderWriterLock
impl !RefUnwindSafe for MySqlDistributedReaderWriterLock
impl Send for MySqlDistributedReaderWriterLock
impl Sync for MySqlDistributedReaderWriterLock
impl Unpin for MySqlDistributedReaderWriterLock
impl !UnwindSafe for MySqlDistributedReaderWriterLock
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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