userver: userver/ydb/coordination.hpp Source File
Loading...
Searching...
No Matches
coordination.hpp
1#pragma once
2
3#include <memory>
4#include <string_view>
5
6#include <ydb-cpp-sdk/client/coordination/coordination.h>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace ydb {
11
12namespace impl {
13class Driver;
14} // namespace impl
15
16class CoordinationSession final {
17public:
18 /// @cond
19 // For internal use only.
20 explicit CoordinationSession(NYdb::NCoordination::TSession&& session);
21 /// @endcond
22
23 std::uint64_t GetSessionId();
24
25 NYdb::NCoordination::ESessionState GetSessionState();
26
27 NYdb::NCoordination::EConnectionState GetConnectionState();
28
29 void Close();
30
31 void Ping();
32
33 void Reconnect();
34
35 /// @warning Use `TAcquireSemaphoreSettings::OnAccepted` callback with care,
36 /// it will be executed on a non-coroutine thread
37 bool AcquireSemaphore(std::string_view name, const NYdb::NCoordination::TAcquireSemaphoreSettings& settings);
38
39 bool ReleaseSemaphore(std::string_view name);
40
41 /// @warning Use `TDescribeSemaphoreSettings::OnChanged` callback with care,
42 /// it will be executed on a non-coroutine thread
45
46 void CreateSemaphore(std::string_view name, std::uint64_t limit);
47
48 void UpdateSemaphore(std::string_view name, std::string_view data);
49
50 void DeleteSemaphore(std::string_view name);
51
52private:
53 NYdb::NCoordination::TSession session_;
54};
55
56class CoordinationClient final {
57public:
58 /// @cond
59 // For internal use only.
60 explicit CoordinationClient(std::shared_ptr<impl::Driver> driver);
61 /// @endcond
62
63 /// @warning Use `TSessionSettings::OnStateChanged` and
64 /// `TSessionSettings::OnStopped` callbacks with care, they will be executed
65 /// on a non-coroutine thread
66 CoordinationSession StartSession(std::string_view path, const NYdb::NCoordination::TSessionSettings& settings);
67
68 void CreateNode(std::string_view path, const NYdb::NCoordination::TCreateNodeSettings& settings);
69
70 void AlterNode(std::string_view path, const NYdb::NCoordination::TAlterNodeSettings& settings);
71
72 void DropNode(std::string_view path);
73
74 NYdb::NCoordination::TNodeDescription DescribeNode(std::string_view path);
75
76 /// Get native coordination client
77 /// @warning Use with care! Facilities from
78 /// `<core/include/userver/drivers/subscribable_futures.hpp>` can help with
79 /// non-blocking wait operations.
81
82private:
83 std::shared_ptr<impl::Driver> driver_;
84 NYdb::NCoordination::TClient client_;
85};
86
87} // namespace ydb
88
89USERVER_NAMESPACE_END