#include <userver/dist_lock/dist_lock_strategy.hpp>
Interface for distributed lock strategies.
Definition at line 59 of file dist_lock_strategy.hpp.
Public Member Functions | |
| virtual void | Acquire (std::chrono::milliseconds lock_ttl, const std::string &locker_id)=0 |
| virtual void | Prolong (std::chrono::milliseconds lock_ttl, const std::string &locker_id) |
| virtual LockOperationResult | ExecuteOperation (const std::string &locker_id, const LockOperationOptions &options) |
| virtual void | Release (const std::string &locker_id)=0 |
| virtual void | Release (const std::string &locker_id, const ReleaseOptions &) |
|
pure virtual |
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. |
Implemented in storages::mongo::DistLockStrategy, and storages::postgres::DistLockStrategy.
|
inlinevirtual |
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 95 of file dist_lock_strategy.hpp.
|
inlinevirtual |
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 in storages::mongo::DistLockStrategy, and storages::postgres::DistLockStrategy.
Definition at line 86 of file dist_lock_strategy.hpp.
|
pure virtual |
Releases the lock.
| locker_id | Globally unique ID of the locking entity, must be the same as in Acquire(). |
Implemented in storages::mongo::DistLockStrategy, and storages::postgres::DistLockStrategy.
|
inlinevirtual |
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 125 of file dist_lock_strategy.hpp.