#include <userver/storages/postgres/dist_lock_strategy.hpp>
Postgres distributed locking strategy. Release history, when requested, retains one expired row per lock key to track the shared idle interval used by fallback acquisition.
Definition at line 22 of file dist_lock_strategy.hpp.
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 |
| dist_lock::LockOperationResult | ExecuteOperation (const std::string &locker_id, const dist_lock::LockOperationOptions &options) override |
| Acquires, prolongs or checks the lock according to options. A check never changes the lock. Fallback acquisition requires the shared lock row to have been inactive for the entire minimum idle interval. | |
| void | Prolong (std::chrono::milliseconds lock_ttl, const std::string &locker_id) override |
| void | Release (const std::string &locker_id) override |
| Releases the lock by deleting its row. | |
| void | Release (const std::string &locker_id, const dist_lock::ReleaseOptions &options) override |
| Releases the lock according to the shared fallback policy. When dist_lock::ReleaseOptions::preserve_history is enabled, retains the release time in an expired row instead of deleting the row. Retained history prevents fallback contenders from reusing observations made before another worker acquired and released the lock. Ordinary acquisition can reuse the released row immediately. | |
| void | UpdateCommandControl (CommandControl cc) |
|
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.
|
overridevirtual |
Acquires, prolongs or checks the lock according to options. A check never changes the lock. Fallback acquisition requires the shared lock row to have been inactive for the entire minimum idle interval.
| std::invalid_argument | if the minimum idle interval is negative. |
Reimplemented from dist_lock::DistLockStrategyBase.
|
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.
|
overridevirtual |
Releases the lock by deleting its row.
| dist_lock::LockIsAcquiredByAnotherHostException | if this locker no longer owns the lock. |
Implements dist_lock::DistLockStrategyBase.
|
overridevirtual |
Releases the lock according to the shared fallback policy. When dist_lock::ReleaseOptions::preserve_history is enabled, retains the release time in an expired row instead of deleting the row. Retained history prevents fallback contenders from reusing observations made before another worker acquired and released the lock. Ordinary acquisition can reuse the released row immediately.
| dist_lock::LockIsAcquiredByAnotherHostException | if this locker no longer owns the lock. |
Reimplemented from dist_lock::DistLockStrategyBase.