userver: storages::postgres::DistLockStrategy Class Reference
Loading...
Searching...
No Matches
storages::postgres::DistLockStrategy Class Referencefinal

#include <userver/storages/postgres/dist_lock_strategy.hpp>

Detailed Description

Postgres distributed locking strategy.

Definition at line 20 of file dist_lock_strategy.hpp.

Inheritance diagram for storages::postgres::DistLockStrategy:

Public Member Functions

 DistLockStrategy (ClusterPtr cluster, std::string_view table, std::string_view lock_name, const dist_lock::DistLockSettings &settings)
void Acquire (std::chrono::milliseconds lock_ttl, const std::string &locker_id) override
void Release (const std::string &locker_id) override
void UpdateCommandControl (CommandControl cc)
virtual void Prolong (std::chrono::milliseconds lock_ttl, const std::string &locker_id)

Member Function Documentation

◆ Acquire()

void storages::postgres::DistLockStrategy::Acquire ( std::chrono::milliseconds lock_ttl,
const std::string & locker_id )
overridevirtual

Acquires the distributed lock.

Parameters
lock_ttlThe duration for which the lock must be held.
locker_idGlobally unique ID of the locking entity.
Exceptions
LockIsAcquiredByAnotherHostErrorwhen the lock is busy
anythingelse when the locking fails, strategy is responsible for cleanup, Release won't be invoked.

Implements dist_lock::DistLockStrategyBase.

◆ Prolong()

virtual void dist_lock::DistLockStrategyBase::Prolong ( std::chrono::milliseconds lock_ttl,
const std::string & locker_id )
inlinevirtualinherited

Prolongs (refreshes the TTL of) a lock already held by locker_id.

Called instead of Acquire() on every refresh while the lock is held, so backends may implement a cheaper query than the full Acquire().

Parameters
lock_ttlThe new duration for which the lock must be held.
locker_idGlobally unique ID of the locking entity, must be the same as in Acquire().
Exceptions
LockIsAcquiredByAnotherHostExceptionwhen the lock is no longer held by locker_id (ownership was lost)
anythingelse when the prolongation fails, strategy is responsible for cleanup, Release won't be invoked.
Note
The default implementation simply calls Acquire(), preserving the legacy behaviour for strategies that do not override it.

Reimplemented in storages::mongo::DistLockStrategy.

Definition at line 51 of file dist_lock_strategy.hpp.

◆ Release()

void storages::postgres::DistLockStrategy::Release ( const std::string & locker_id)
overridevirtual

Releases the lock.

Parameters
locker_idGlobally unique ID of the locking entity, must be the same as in Acquire().
Note
Exceptions are ignored.

Implements dist_lock::DistLockStrategyBase.


The documentation for this class was generated from the following file: