Github   Telegram
Loading...
Searching...
No Matches
dist_lock_strategy.hpp
1#pragma once
2
3#include <chrono>
4#include <string>
5
6#include <userver/dist_lock/dist_lock_strategy.hpp>
7#include <userver/storages/mongo/collection.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace storages::mongo {
12
13/// Strategy for mongodb-based distributed locking
14class DistLockStrategy final : public dist_lock::DistLockStrategyBase {
15 public:
16 /// Targets a distributed lock in a specified collection as a host.
17 DistLockStrategy(Collection collection, std::string lock_name);
18
19 DistLockStrategy(Collection collection, std::string lock_name,
20 std::string owner);
21
22 void Acquire(std::chrono::milliseconds lock_ttl,
23 const std::string& locker_id) override;
24
25 void Release(const std::string& locker_id) override;
26
27 private:
28 storages::mongo::Collection collection_;
29 std::string lock_name_;
30 std::string owner_prefix_;
31};
32
33} // namespace storages::mongo
34
35USERVER_NAMESPACE_END