Skip to content

Commit

Permalink
feat ydb: upd coordination docs
Browse files Browse the repository at this point in the history
commit_hash:e86fd7ca18f8351f5debc9d44577a2efa2c64cd3
  • Loading branch information
kpavlov00 committed Dec 18, 2024
1 parent 20abd49 commit 672f262
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ydb/include/userver/ydb/coordination.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

/// @file userver/ydb/coordination.hpp
/// @brief YDB Coordination client

#include <memory>
#include <string_view>

Expand All @@ -13,64 +16,90 @@ namespace impl {
class Driver;
} // namespace impl

/// @brief Coordination Session
///
/// @see https://ydb.tech/docs/ru/reference/ydb-sdk/coordination#session
class CoordinationSession final {
public:
/// @cond
// For internal use only.
explicit CoordinationSession(NYdb::NCoordination::TSession&& session);
/// @endcond

/// Get session id
std::uint64_t GetSessionId();

/// Get session state
NYdb::NCoordination::ESessionState GetSessionState();

/// Get connection state
NYdb::NCoordination::EConnectionState GetConnectionState();

/// Close session
void Close();

/// Ping
void Ping();

/// Reconnect session
void Reconnect();

/// Acquire semaphore
/// @warning Use `TAcquireSemaphoreSettings::OnAccepted` callback with care,
/// it will be executed on a non-coroutine thread
bool AcquireSemaphore(std::string_view name, const NYdb::NCoordination::TAcquireSemaphoreSettings& settings);

/// Release semaphore
bool ReleaseSemaphore(std::string_view name);

/// Describe semaphore
/// @warning Use `TDescribeSemaphoreSettings::OnChanged` callback with care,
/// it will be executed on a non-coroutine thread
NYdb::NCoordination::TSemaphoreDescription
DescribeSemaphore(std::string_view name, const NYdb::NCoordination::TDescribeSemaphoreSettings& settings);

/// Create semaphore
void CreateSemaphore(std::string_view name, std::uint64_t limit);

/// Update semaphore
void UpdateSemaphore(std::string_view name, std::string_view data);

/// Delete semaphore
void DeleteSemaphore(std::string_view name);

private:
NYdb::NCoordination::TSession session_;
};

/// @ingroup userver_clients
///
/// @brief YDB Coordination Client
///
/// Provides access to work with Coordination Service
/// @see https://ydb.tech/docs/ru/reference/ydb-sdk/coordination
class CoordinationClient final {
public:
/// @cond
// For internal use only.
explicit CoordinationClient(std::shared_ptr<impl::Driver> driver);
/// @endcond

/// Start session
/// @warning Use `TSessionSettings::OnStateChanged` and
/// `TSessionSettings::OnStopped` callbacks with care, they will be executed
/// on a non-coroutine thread
CoordinationSession StartSession(std::string_view path, const NYdb::NCoordination::TSessionSettings& settings);

/// Create coordination node
void CreateNode(std::string_view path, const NYdb::NCoordination::TCreateNodeSettings& settings);

/// Alter coordination node
void AlterNode(std::string_view path, const NYdb::NCoordination::TAlterNodeSettings& settings);

/// Drop coordination node
void DropNode(std::string_view path);

/// Describe coordination node
NYdb::NCoordination::TNodeDescription DescribeNode(std::string_view path);

/// Get native coordination client
Expand Down

0 comments on commit 672f262

Please sign in to comment.