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

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

Detailed Description

Strategy for MongoDB-based distributed locking.

Definition at line 17 of file dist_lock_strategy.hpp.

Inheritance diagram for storages::mongo::DistLockStrategy:

Public Member Functions

 DistLockStrategy (Collection collection, std::string lock_name)
 Targets a distributed lock in a specified collection as a host.
 DistLockStrategy (Collection collection, std::string lock_name, std::string owner)
void Acquire (std::chrono::milliseconds lock_ttl, const std::string &locker_id) override
void Prolong (std::chrono::milliseconds lock_ttl, const std::string &locker_id) override
void Release (const std::string &locker_id) override

Member Function Documentation

◆ Acquire()

void storages::mongo::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()

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

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 from dist_lock::DistLockStrategyBase.

◆ Release()

void storages::mongo::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: