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