userver: userver/storages/mongo/dist_lock_strategy.hpp Source File
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 {
15public:
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, std::string owner);
20
21 void Acquire(std::chrono::milliseconds lock_ttl, const std::string& locker_id) override;
22
23 void Release(const std::string& locker_id) override;
24
25private:
26 storages::mongo::Collection collection_;
27 std::string lock_name_;
28 std::string owner_prefix_;
29};
30
31} // namespace storages::mongo
32
33USERVER_NAMESPACE_END