userver: userver/storages/postgres/dist_lock_strategy.hpp Source File
Loading...
Searching...
No Matches
dist_lock_strategy.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/postgres/dist_lock_strategy.hpp
4/// @brief @copybrief storages::postgres::DistLockStrategy
5
6#include <userver/dist_lock/dist_lock_settings.hpp>
7#include <userver/dist_lock/dist_lock_strategy.hpp>
8#include <userver/engine/deadline.hpp>
9#include <userver/rcu/rcu.hpp>
10#include <userver/storages/postgres/options.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace storages::postgres {
15
16/// Postgres distributed locking strategy
17class DistLockStrategy final : public dist_lock::DistLockStrategyBase {
18public:
19 DistLockStrategy(
20 ClusterPtr cluster,
21 const std::string& table,
22 const std::string& lock_name,
23 const dist_lock::DistLockSettings& settings
24 );
25
26 void Acquire(std::chrono::milliseconds lock_ttl, const std::string& locker_id) override;
27
28 void Release(const std::string& locker_id) override;
29
30 void UpdateCommandControl(CommandControl cc);
31
32private:
33 ClusterPtr cluster_;
34 rcu::Variable<CommandControl> cc_;
35 const std::string acquire_query_;
36 const std::string release_query_;
37 const std::string lock_name_;
38 const std::string owner_prefix_;
39};
40
41} // namespace storages::postgres
42
43USERVER_NAMESPACE_END