#include <userver/storages/mongo/dist_lock_strategy.hpp>
Strategy for MongoDB-based distributed locking.
Definition at line 17 of file dist_lock_strategy.hpp.
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 |
| virtual LockOperationResult | ExecuteOperation (const std::string &locker_id, const LockOperationOptions &options) |
| virtual void | Release (const std::string &locker_id, const ReleaseOptions &) |
|
overridevirtual |
Acquires the distributed lock.
| lock_ttl | The duration for which the lock must be held. |
| locker_id | Globally unique ID of the locking entity. |
| LockIsAcquiredByAnotherHostError | when the lock is busy |
| anything | else when the locking fails, strategy is responsible for cleanup, Release won't be invoked. |
Implements dist_lock::DistLockStrategyBase.
|
inlinevirtualinherited |
Acquire, refresh, or check a lock, returning expected outcomes without exceptions. The default implementation delegates acquisition and refresh to the legacy virtual methods. Checks and fallback acquisition are unsupported by default, so enabling fallback cannot accidentally acquire a lock while checking it. Backend errors other than contention are propagated to the caller.
Reimplemented in storages::postgres::DistLockStrategy.
Definition at line 97 of file dist_lock_strategy.hpp.
|
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().
| lock_ttl | The new duration for which the lock must be held. |
| locker_id | Globally unique ID of the locking entity, must be the same as in Acquire(). |
| LockIsAcquiredByAnotherHostException | when the lock is no longer held by locker_id (ownership was lost) |
| anything | else when the prolongation fails, strategy is responsible for cleanup, Release won't be invoked. |
Reimplemented from dist_lock::DistLockStrategyBase.
|
inlinevirtualinherited |
Release with the current shared fallback policy. The default implementation delegates to the legacy release method; legacy strategies do not support fallback acquisition. Backends supporting fallback must preserve history when requested, and must only release the lock owned by locker_id.
Reimplemented in storages::postgres::DistLockStrategy.
Definition at line 127 of file dist_lock_strategy.hpp.
|
overridevirtual |
Releases the lock.
| locker_id | Globally unique ID of the locking entity, must be the same as in Acquire(). |
Implements dist_lock::DistLockStrategyBase.