Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync sdks #356

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions examples/basic_example/basic_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,7 @@

using namespace NYdb;
using namespace NYdb::NQuery;

class TYdbErrorException : public yexception {
public:
TYdbErrorException(const TStatus& status)
: Status(status) {}

TStatus Status;
};

static void ThrowOnError(const TStatus& status) {
if (!status.IsSuccess()) {
throw TYdbErrorException(status) << status;
}
}

static void PrintStatus(const TStatus& status) {
std::cerr << "Status: " << ToString(status.GetStatus()) << std::endl;
std::cerr << status.GetIssues().ToString();
}
using namespace NYdb::NStatusHelpers;

template <class T>
std::string OptionalToString(const std::optional<T>& opt) {
Expand Down Expand Up @@ -502,8 +484,7 @@ bool Run(const TDriver& driver) {
DropTables(client);
}
catch (const TYdbErrorException& e) {
std::cerr << "Execution failed due to fatal error:" << std::endl;
PrintStatus(e.Status);
std::cerr << "Execution failed due to fatal error: " << e.what() << std::endl;
return false;
}

Expand Down
23 changes: 2 additions & 21 deletions examples/pagination/pagination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,10 @@

using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;

const uint32_t MaxPages = 10;

class TYdbErrorException : public yexception {
public:
TYdbErrorException(const TStatus& status)
: Status(status) {}

TStatus Status;
};

static void ThrowOnError(const TStatus& status) {
if (!status.IsSuccess()) {
throw TYdbErrorException(status) << status;
}
}

static void PrintStatus(const TStatus& status) {
std::cerr << "Status: " << ToString(status.GetStatus()) << std::endl;
std::cerr << status.GetIssues().ToString();
}

static std::string JoinPath(const std::string& basePath, const std::string& path) {
if (basePath.empty()) {
return path;
Expand Down Expand Up @@ -184,8 +166,7 @@ bool Run(const TDriver& driver, const std::string& path) {
}
}
catch (const TYdbErrorException& e) {
std::cerr << "Execution failed due to fatal error:" << std::endl;
PrintStatus(e.Status);
std::cerr << "Execution failed due to fatal error: " << e.what() << std::endl;
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion examples/secondary_index/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using namespace NLastGetopt;
using namespace NYdb;
using namespace NYdb::NStatusHelpers;

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -61,7 +62,7 @@ int main(int argc, char** argv) {
return RunDeleteSeries(driver, prefix, argc, argv);
}
} catch (const TYdbErrorException& e) {
std::cerr << "Execution failed: " << e << std::endl;
std::cerr << "Execution failed: " << e.what() << std::endl;
return 1;
}

Expand Down
27 changes: 0 additions & 27 deletions examples/secondary_index/secondary_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,6 @@ std::string JoinPath(const std::string& prefix, const std::string& path);

////////////////////////////////////////////////////////////////////////////////

class TYdbErrorException : public yexception {
public:
TYdbErrorException(NYdb::TStatus status)
: Status(std::move(status))
{ }

friend std::ostream& operator<<(std::ostream& out, const TYdbErrorException& e) {
out << "Status: " << ToString(e.Status.GetStatus());
if (e.Status.GetIssues()) {
out << std::endl;
out << e.Status.GetIssues().ToString();
}
return out;
}

private:
NYdb::TStatus Status;
};

inline void ThrowOnError(NYdb::TStatus status) {
if (!status.IsSuccess()) {
throw TYdbErrorException(status) << status;
}
}

////////////////////////////////////////////////////////////////////////////////

int RunCreateTables(NYdb::TDriver& driver, const std::string& prefix, int argc, char** argv);
int RunDropTables(NYdb::TDriver& driver, const std::string& prefix, int argc, char** argv);
int RunUpdateViews(NYdb::TDriver& driver, const std::string& prefix, int argc, char** argv);
Expand Down
1 change: 1 addition & 0 deletions examples/secondary_index/secondary_index_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using namespace NLastGetopt;
using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;

////////////////////////////////////////////////////////////////////////////////

Expand Down
1 change: 1 addition & 0 deletions examples/secondary_index/secondary_index_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using namespace NLastGetopt;
using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;

////////////////////////////////////////////////////////////////////////////////

Expand Down
1 change: 1 addition & 0 deletions examples/secondary_index/secondary_index_drop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using namespace NLastGetopt;
using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;

////////////////////////////////////////////////////////////////////////////////

Expand Down
1 change: 1 addition & 0 deletions examples/secondary_index/secondary_index_generate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using namespace NLastGetopt;
using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;

namespace {

Expand Down
1 change: 1 addition & 0 deletions examples/secondary_index/secondary_index_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using namespace NLastGetopt;
using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;

////////////////////////////////////////////////////////////////////////////////

Expand Down
1 change: 1 addition & 0 deletions examples/secondary_index/secondary_index_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using namespace NLastGetopt;
using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;

////////////////////////////////////////////////////////////////////////////////

Expand Down
3 changes: 2 additions & 1 deletion examples/secondary_index_builtin/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using namespace NLastGetopt;
using namespace NYdb;
using namespace NYdb::NStatusHelpers;

int main(int argc, char** argv) {

Expand Down Expand Up @@ -56,7 +57,7 @@ int main(int argc, char** argv) {
}

} catch (const TYdbErrorException& e) {
std::cerr << "Execution failed: " << e << std::endl;
std::cerr << "Execution failed: " << e.what() << std::endl;
return 1;
}
}
24 changes: 0 additions & 24 deletions examples/secondary_index_builtin/secondary_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,6 @@ struct TSeries {
, UploadedUserId(uploadedUserId) {}
};

class TYdbErrorException: public yexception {
public:
TYdbErrorException(NYdb::TStatus status)
: Status(std::move(status))
{ }

friend std::ostream& operator<<(std::ostream& out, const TYdbErrorException& e) {
out << "Status:" << ToString(e.Status.GetStatus());
if (e.Status.GetIssues()) {
out << std::endl;
out << e.Status.GetIssues().ToString();
}
return out;
}
private:
NYdb::TStatus Status;
};

inline void ThrowOnError(NYdb::TStatus status) {
if (!status.IsSuccess()){
throw TYdbErrorException(status) << status;
}
}

std::string GetCommandsList();
TCommand Parse(const char *stringCmnd);
std::string JoinPath(const std::string& prefix, const std::string& path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;
using namespace NLastGetopt;

static void CreateSeriesTable(TTableClient& client, const std::string& path) {
Expand Down
1 change: 1 addition & 0 deletions examples/secondary_index_builtin/secondary_index_drop.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "secondary_index.h"

using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;
using namespace NYdb;

static void DropTable(TTableClient& client, const std::string& path) {
Expand Down
1 change: 1 addition & 0 deletions examples/secondary_index_builtin/secondary_index_fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;

std::vector<TSeries> GetSeries() {
std::vector<TSeries> series = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;
using namespace NLastGetopt;

TStatus SelectSeriesWithViews(TSession session, const std::string& path, std::vector<TSeries>& selectResult, uint64_t minViews) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;
using namespace NLastGetopt;

TStatus SelectSeriesWithUserName(TSession session, const std::string& path,
Expand Down
9 changes: 0 additions & 9 deletions examples/topic_writer/transaction/main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#include <ydb-cpp-sdk/client/topic/client.h>
#include <ydb-cpp-sdk/client/table/table.h>

void ThrowOnError(const NYdb::TStatus& status)
{
if (status.IsSuccess()) {
return;
}

ythrow yexception() << status;
}

int main()
{
const std::string ENDPOINT = "HOST:PORT";
Expand Down
1 change: 1 addition & 0 deletions examples/ttl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using namespace NLastGetopt;
using namespace NYdb;
using namespace NYdb::NStatusHelpers;

void StopHandler(int) {
exit(1);
Expand Down
4 changes: 2 additions & 2 deletions examples/ttl/ttl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using namespace NExample;
using namespace NYdb;
using namespace NYdb::NTable;
using namespace NYdb::NStatusHelpers;

constexpr uint32_t DOC_TABLE_PARTITION_COUNT = 4;
constexpr uint32_t EXPIRATION_QUEUE_COUNT = 4;
Expand Down Expand Up @@ -334,8 +335,7 @@ bool Run(const TDriver& driver, const std::string& path) {
ReadDocument(client, path, "https://ya.ru/");
}
catch (const TYdbErrorException& e) {
std::cerr << "Execution failed due to fatal error:" << std::endl;
PrintStatus(e.Status);
std::cerr << "Execution failed due to fatal error: " << e.what() << std::endl;
return false;
}

Expand Down
19 changes: 0 additions & 19 deletions examples/ttl/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,6 @@ namespace NExample {
using namespace NYdb;
using namespace NYdb::NTable;

class TYdbErrorException : public yexception {
public:
TYdbErrorException(const TStatus& status)
: Status(status) {}

TStatus Status;
};

inline void ThrowOnError(const TStatus& status) {
if (!status.IsSuccess()) {
throw TYdbErrorException(status) << status;
}
}

inline void PrintStatus(const TStatus& status) {
std::cerr << "Status: " << ToString(status.GetStatus()) << std::endl;
std::cerr << status.GetIssues().ToString();
}

inline std::string JoinPath(const std::string& basePath, const std::string& path) {
if (basePath.empty()) {
return path;
Expand Down
53 changes: 53 additions & 0 deletions include/ydb-cpp-sdk/client/bsconfig/storage_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once

#include <ydb-cpp-sdk/client/common_client/settings.h>
#include <ydb-cpp-sdk/client/driver/driver.h>
#include <ydb-cpp-sdk/client/types/status/status.h>
#include <ydb-cpp-sdk/client/types/request_settings.h>
#include <ydb-cpp-sdk/client/types/ydb.h>

#include <memory>
#include <string>

namespace NYdb::inline V3::NStorageConfig {

struct TFetchStorageConfigResult : public TStatus {
TFetchStorageConfigResult(
TStatus&& status,
std::string&& config)
: TStatus(std::move(status))
, Config_(std::move(config))
{}

const std::string& GetConfig() const {
return Config_;
}

private:
std::string Config_;
};

using TAsyncFetchStorageConfigResult = NThreading::TFuture<TFetchStorageConfigResult>;

struct TStorageConfigSettings : public NYdb::TOperationRequestSettings<TStorageConfigSettings> {};

class TStorageConfigClient {
public:

explicit TStorageConfigClient(const TDriver& driver, const TCommonClientSettings& settings = {});

~TStorageConfigClient();

// Replace config
TAsyncStatus ReplaceStorageConfig(const std::string& config);

// Fetch current cluster storage config
TAsyncFetchStorageConfigResult FetchStorageConfig(const TStorageConfigSettings& settings = {});

private:
class TImpl;

std::unique_ptr<TImpl> Impl_;
};

}
2 changes: 1 addition & 1 deletion include/ydb-cpp-sdk/client/common_client/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <optional>

namespace NYdb {
namespace NYdb::inline V3 {

using TCertificateAndPrivateKey = std::pair<std::string, std::string>;

Expand Down
Loading
Loading