userver: userver/ydb/coordination.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 {
17 public:
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
38 std::string_view name,
39 const NYdb::NCoordination::TAcquireSemaphoreSettings& settings);
40
41 bool ReleaseSemaphore(std::string_view name);
42
43 /// @warning Use `TDescribeSemaphoreSettings::OnChanged` callback with care,
44 /// it will be executed on a non-coroutine thread
48
49 void CreateSemaphore(std::string_view name, std::uint64_t limit);
50
51 void UpdateSemaphore(std::string_view name, std::string_view data);
52
53 void DeleteSemaphore(std::string_view name);
54
55 private:
56 NYdb::NCoordination::TSession session_;
57};
58
59class CoordinationClient final {
60 public:
61 /// @cond
62 // For internal use only.
63 explicit CoordinationClient(std::shared_ptr<impl::Driver> driver);
64 /// @endcond
65
66 /// @warning Use `TSessionSettings::OnStateChanged` and
67 /// `TSessionSettings::OnStopped` callbacks with care, they will be executed
68 /// on a non-coroutine thread
69 CoordinationSession StartSession(
70 std::string_view path,
71 const NYdb::NCoordination::TSessionSettings& settings);
72
73 void CreateNode(std::string_view path,
74 const NYdb::NCoordination::TCreateNodeSettings& settings);
75
76 void AlterNode(std::string_view path,
77 const NYdb::NCoordination::TAlterNodeSettings& settings);
78
79 void DropNode(std::string_view path);
80
81 NYdb::NCoordination::TNodeDescription DescribeNode(std::string_view path);
82
83 NYdb::NCoordination::TClient& GetNativeCoordinationClient();
84
85 private:
86 std::shared_ptr<impl::Driver> driver_;
87 NYdb::NCoordination::TClient client_;
88};
89
90} // namespace ydb
91
92USERVER_NAMESPACE_END