Skip to content
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
2 changes: 1 addition & 1 deletion .github/import_generation.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25
26
2 changes: 1 addition & 1 deletion .github/last_commit.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b39a359f04c57875ea162524646ae879f06c7a33
234f6d55e1e71a242c2767a22b990d68ff7fce72
2 changes: 1 addition & 1 deletion cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function(_ydb_sdk_add_library Tgt)
$<BUILD_INTERFACE:${YDB_SDK_SOURCE_DIR}/include>
)
target_compile_definitions(${Tgt} ${includeMode}
YDB_SDK_USE_STD_STRING
YDB_SDK_OSS
)
endfunction()

Expand Down
4 changes: 2 additions & 2 deletions examples/auth/ssa_delegation/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ int main(int argc, char** argv) {

opts.AddLongOption("microservice-id", "Microservice id")
.RequiredArgument("ID")
.DefaultValue("control-plane")
.DefaultValue("data-plane")
.StoreResult(&microserviceId);

opts.AddLongOption("resource-id", "Resource id")
.Required()
.RequiredArgument("ID")
Expand Down
52 changes: 52 additions & 0 deletions examples/executor/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <ydb-cpp-sdk/client/driver/driver.h>
#include <ydb-cpp-sdk/client/helpers/helpers.h>
#include <ydb-cpp-sdk/client/query/client.h>

#include <library/cpp/getopt/last_getopt.h>

#include <util/thread/pool.h>

#include <thread>


void ExecutorExample(const std::string& endpoint, const std::string& database) {
auto driverConfig = NYdb::CreateFromEnvironment(endpoint + "/?database=" + database)
.SetExecutor(NYdb::CreateThreadPoolExecutorAdapter(
std::make_shared<TThreadPool>(TThreadPool::TParams()
.SetBlocking(true)
.SetCatching(false)
.SetForkAware(false)),
std::thread::hardware_concurrency())
);

NYdb::TDriver driver(driverConfig);
NYdb::NQuery::TQueryClient client(driver);

try {
auto result = client.ExecuteQuery("SELECT 1", NYdb::NQuery::TTxControl::NoTx()).GetValueSync();
NYdb::NStatusHelpers::ThrowOnError(result);
auto parser = result.GetResultSetParser(0);
parser.TryNextRow();
std::cout << "Result: " << parser.ColumnParser(0).GetInt32() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Execution failed: " << e.what() << std::endl;
}

driver.Stop(true);
}

int main(int argc, char** argv) {
std::string endpoint;
std::string database;

NLastGetopt::TOpts opts = NLastGetopt::TOpts::Default();

opts.AddLongOption('e', "endpoint", "YDB endpoint").Required().RequiredArgument("HOST:PORT").StoreResult(&endpoint);
opts.AddLongOption('d', "database", "YDB database").Required().RequiredArgument("DATABASE").StoreResult(&database);

opts.SetFreeArgsMin(0);
NLastGetopt::TOptsParseResult result(&opts, argc, argv);

ExecutorExample(endpoint, database);
return 0;
}
11 changes: 8 additions & 3 deletions include/ydb-cpp-sdk/client/driver/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ydb-cpp-sdk/client/types/fatal_error_handlers/handlers.h>
#include <ydb-cpp-sdk/client/types/request_settings.h>
#include <ydb-cpp-sdk/client/types/status/status.h>
#include <ydb-cpp-sdk/client/types/executor/executor.h>

#include <library/cpp/logger/backend.h>

Expand Down Expand Up @@ -54,7 +55,7 @@ class TDriverConfig {
//! Enable Ssl.
//! caCerts - The buffer containing the PEM encoded root certificates for SSL/TLS connections.
//! If this parameter is empty, the default roots will be used.
TDriverConfig& UseSecureConnection(const std::string& caCerts = std::string());
TDriverConfig& UseSecureConnection(const std::string& caCerts = "");
TDriverConfig& SetUsePerChannelTcpConnection(bool usePerChannel);
TDriverConfig& UseClientCertificate(const std::string& clientCert, const std::string& clientPrivateKey);

Expand Down Expand Up @@ -107,8 +108,7 @@ class TDriverConfig {
//! Set policy for balancing
//! Params is a optionally field to set policy settings
//! default: EBalancingPolicy::UsePreferableLocation
TDriverConfig& SetBalancingPolicy(EBalancingPolicy policy, const std::string& params = std::string());

TDriverConfig& SetBalancingPolicy(EBalancingPolicy policy, const std::string& params = "");
//! Set grpc level keep alive. If keepalive ping was delayed more than given timeout
//! internal grpc routine fails request with TRANSIENT_FAILURE or TRANSPORT_UNAVAILABLE error
//! Note: this timeout should not be too small to prevent fail due to
Expand Down Expand Up @@ -142,6 +142,11 @@ class TDriverConfig {

//! Log backend.
TDriverConfig& SetLog(std::unique_ptr<TLogBackend>&& log);

//! Set executor for async responses.
//! If not set, default executor will be used.
TDriverConfig& SetExecutor(std::shared_ptr<IExecutor> executor);

private:
class TImpl;
std::shared_ptr<TImpl> Impl_;
Expand Down
6 changes: 3 additions & 3 deletions include/ydb-cpp-sdk/client/federated_topic/federated_topic.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ struct TFederatedReadSessionSettings: public NTopic::TReadSessionSettings {
//! Executor for handlers.
//! If not set, default single threaded executor will be used.
//! Shared between subsessions
FLUENT_SETTING(NTopic::IExecutor::TPtr, HandlersExecutor);
FLUENT_SETTING(IExecutor::TPtr, HandlersExecutor);
};

//! Federated event handlers.
Expand Down Expand Up @@ -492,10 +492,10 @@ struct TFederatedTopicClientSettings : public TCommonClientSettingsBase<TFederat
using TSelf = TFederatedTopicClientSettings;

//! Default executor for compression tasks.
FLUENT_SETTING_DEFAULT(NTopic::IExecutor::TPtr, DefaultCompressionExecutor, NTopic::CreateThreadPoolExecutor(2));
FLUENT_SETTING_DEFAULT(IExecutor::TPtr, DefaultCompressionExecutor, CreateThreadPoolExecutor(2));

//! Default executor for callbacks.
FLUENT_SETTING_DEFAULT(NTopic::IExecutor::TPtr, DefaultHandlersExecutor, NTopic::CreateThreadPoolExecutor(1));
FLUENT_SETTING_DEFAULT(IExecutor::TPtr, DefaultHandlersExecutor, CreateThreadPoolExecutor(1));

//! Connection timeoout for federation discovery.
FLUENT_SETTING_DEFAULT(TDuration, ConnectionTimeout, TDuration::Seconds(30));
Expand Down
2 changes: 1 addition & 1 deletion include/ydb-cpp-sdk/client/iam/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ydb_sdk_add_library(client-iam-types INTERFACE)

target_link_libraries(client-iam-types
INTERFACE
client-ydb_types-credentials
client-types-credentials
library-jwt
gRPC::grpc++
yutil
Expand Down
40 changes: 1 addition & 39 deletions include/ydb-cpp-sdk/client/topic/executor.h
Original file line number Diff line number Diff line change
@@ -1,47 +1,9 @@
#pragma once

#include <util/generic/ptr.h>
#include <util/system/spinlock.h>
#include <util/thread/pool.h>

#include <memory>
#include <mutex>
#include <ydb-cpp-sdk/client/types/executor/executor.h>

namespace NYdb::inline V3::NTopic {

class IExecutor: public TThrRefBase {
public:
using TPtr = TIntrusivePtr<IExecutor>;
using TFunction = std::function<void()>;

// Is executor asynchronous.
virtual bool IsAsync() const = 0;

// Post function to execute.
virtual void Post(TFunction&& f) = 0;

// Start method.
// This method is idempotent.
// It can be called many times. Only the first one has effect.
void Start() {
std::lock_guard guard(StartLock);
if (!Started) {
DoStart();
Started = true;
}
}

private:
virtual void DoStart() = 0;

private:
bool Started = false;
TAdaptiveLock StartLock;
};
IExecutor::TPtr CreateThreadPoolExecutorAdapter(
std::shared_ptr<IThreadPool> threadPool); // Thread pool is expected to have been started.
IExecutor::TPtr CreateThreadPoolExecutor(size_t threads);

IExecutor::TPtr CreateSyncExecutor();

} // namespace NYdb::NTopic
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct TJwtTokenSourceParams {
class ISigningAlgorithm {
public:
virtual ~ISigningAlgorithm() = default;
#ifdef YDB_SDK_USE_NEW_JWT
#ifdef YDB_SDK_OSS
virtual std::string sign(const std::string& data, std::error_code& ec) const = 0;
#else
virtual std::string sign(const std::string& data) const = 0;
Expand All @@ -54,7 +54,7 @@ struct TJwtTokenSourceParams {
{
}

#ifdef YDB_SDK_USE_NEW_JWT
#ifdef YDB_SDK_OSS
std::string sign(const std::string& data, std::error_code& ec) const override {
return Alg.sign(data, ec);
}
Expand Down
58 changes: 58 additions & 0 deletions include/ydb-cpp-sdk/client/types/executor/executor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once

#ifndef YDB_SDK_OSS
#include <util/thread/pool.h>
#endif

#include <functional>
#include <memory>
#include <mutex>

namespace NYdb::inline V3 {

class IExecutor {
public:
using TPtr = std::shared_ptr<IExecutor>;
using TFunction = std::function<void()>;

// Start method.
// This method is idempotent.
void Start() {
std::lock_guard guard(StartLock);
if (!Started) {
DoStart();
Started = true;
}
}

virtual void Stop() = 0;

// Post function to execute.
virtual void Post(TFunction&& f) = 0;

// Is executor asynchronous.
virtual bool IsAsync() const = 0;

virtual ~IExecutor() = default;

protected:
virtual void DoStart() = 0;

bool Started = false;
std::mutex StartLock;
};

// Create default executor for thread pool.
IExecutor::TPtr CreateThreadPoolExecutor(std::size_t threadCount, std::size_t maxQueueSize = 0);

#ifndef YDB_SDK_OSS
// Create executor adapter for util thread pool.
// Thread pool is started and stopped by SDK.
IExecutor::TPtr CreateThreadPoolExecutorAdapter(std::shared_ptr<IThreadPool> threadPool, std::size_t threadCount, std::size_t maxQueueSize = 0);

// Create executor adapter for util thread pool.
// Thread pool is expected to have been started and stopped by user.
IExecutor::TPtr CreateExternalThreadPoolExecutorAdapter(std::shared_ptr<IThreadPool> threadPool);
#endif

} // namespace NYdb
7 changes: 7 additions & 0 deletions include/ydb-cpp-sdk/client/types/ydb.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class TBalancingPolicy {
//! Use pile with preferable state
static TBalancingPolicy UsePreferablePileState(EPileState pileState = EPileState::PRIMARY);

TBalancingPolicy(const TBalancingPolicy&) = delete;
TBalancingPolicy(TBalancingPolicy&&) = default;
TBalancingPolicy& operator=(const TBalancingPolicy&) = delete;
TBalancingPolicy& operator=(TBalancingPolicy&&) = default;

~TBalancingPolicy();

class TImpl;
private:
TBalancingPolicy(std::unique_ptr<TImpl>&& impl);
Expand Down
14 changes: 8 additions & 6 deletions include/ydb-cpp-sdk/client/value/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ namespace NYdb::inline V3 {

class TResultSetParser;

// Forward declarations for friend access
namespace NTable {

class TTableClient;

} // namespace NTable

//! Representation of YDB type.
class TType {
friend class TProtoAccessor;
friend class NTable::TTableClient;
public:
TType(const Ydb::Type& typeProto);
TType(Ydb::Type&& typeProto);
Expand Down Expand Up @@ -264,12 +272,6 @@ struct TUuidValue {
} Buf_;
};

namespace NTable {

class TTableClient;

} // namespace NTable

//! Representation of YDB value.
class TValue {
friend class TValueParser;
Expand Down
16 changes: 15 additions & 1 deletion src/api/protos/draft/ydb_maintenance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,21 @@ message LockAction {
google.protobuf.Duration duration = 2;
}

// Moving tablets away.
message DrainAction {
ActionScope scope = 1;
}

// Ensuring no new tablets run there.
message CordonAction {
ActionScope scope = 1;
}

message Action {
oneof action {
LockAction lock_action = 1;
DrainAction drain_action = 2;
CordonAction cordon_action = 3;
}
}

Expand Down Expand Up @@ -158,6 +170,8 @@ message ActionState {
ACTION_STATUS_PENDING = 1;
// Action performed: e.g. lock is taken.
ACTION_STATUS_PERFORMED = 2;
// Action is currently in progress
ACTION_STATUS_IN_PROGRESS = 3;
}

enum ActionReason {
Expand All @@ -184,7 +198,7 @@ message ActionState {
ActionUid action_uid = 2;
ActionStatus status = 3;
ActionReason reason = 4;
string reason_details = 6;
string details = 6;
google.protobuf.Timestamp deadline = 5;
}

Expand Down
6 changes: 6 additions & 0 deletions src/api/protos/ydb_common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ message VirtualTimestamp {
uint64 plan_step = 1;
uint64 tx_id = 2;
}

enum MetricsLevel {
Database = 0;
Object = 1;
Detailed = 2;
}
Loading
Loading