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 @@
22
23
2 changes: 1 addition & 1 deletion .github/last_commit.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a1abe1a8139be6a6188d79503a63aa2e5068c6c1
9563c7b171619687436257273b34ceba261903ed
94 changes: 94 additions & 0 deletions examples/auth/ssa_delegation/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <ydb-cpp-sdk/client/query/client.h>
#include <ydb-cpp-sdk/client/iam/iam.h>
#include <ydb-cpp-sdk/client/iam_private/iam.h>

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


int main(int argc, char** argv) {
std::string endpoint;
std::string database;
std::string serviceId;
std::string microserviceId;
std::string targetServiceAccountId;
std::string resourceId;
std::string resourceType;
std::string iamEndpoint;
bool useSsl = false;
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("PATH").StoreResult(&database);

opts.AddLongOption("ssl", "Use SSL").NoArgument().SetFlag(&useSsl);

opts.AddLongOption("target-service-account-id", "Target service account id")
.Required()
.RequiredArgument("ID")
.StoreResult(&targetServiceAccountId);

opts.AddLongOption("service-id", "Service id")
.RequiredArgument("ID")
.DefaultValue("ydb")
.StoreResult(&serviceId);

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

opts.AddLongOption("resource-id", "Resource id")
.Required()
.RequiredArgument("ID")
.StoreResult(&resourceId);

opts.AddLongOption("iam-endpoint", "IAM endpoint")
.RequiredArgument("HOST")
.DefaultValue("iam.api.cloud.yandex.net")
.StoreResult(&iamEndpoint);

opts.AddLongOption("resource-type", "Resource type")
.RequiredArgument("STRING")
.DefaultValue("resource-manager.cloud")
.StoreResult(&resourceType);

opts.SetFreeArgsMin(0);

NLastGetopt::TOptsParseResult optsResult(&opts, argc, argv);

NYdb::TIamServiceParams iamParams{
.SystemServiceAccountCredentials = NYdb::CreateIamCredentialsProviderFactory(),
.ServiceId = serviceId,
.MicroserviceId = microserviceId,
.ResourceId = resourceId,
.ResourceType = resourceType,
.TargetServiceAccountId = targetServiceAccountId,
};

iamParams.Endpoint = iamEndpoint;

auto config = NYdb::TDriverConfig()
.SetEndpoint(endpoint)
.SetDatabase(database)
.SetCredentialsProviderFactory(NYdb::CreateIamServiceCredentialsProviderFactory(iamParams));

if (useSsl) {
config.UseSecureConnection();
}

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

auto result = client.ExecuteQuery("SELECT 1", NYdb::NQuery::TTxControl::NoTx()).ExtractValueSync();
if (!result.IsSuccess()) {
std::cerr << ToString(static_cast<NYdb::TStatus>(result)) << std::endl;
return 1;
}

auto parser = result.GetResultSetParser(0);
while (parser.TryNextRow()) {
std::cout << parser.ColumnParser(0).GetInt32() << std::endl;
}

return 0;
}
16 changes: 0 additions & 16 deletions include/ydb-cpp-sdk/client/arrow/accessor.h

This file was deleted.

26 changes: 20 additions & 6 deletions include/ydb-cpp-sdk/client/iam/common/generic_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
private:
class TImpl : public std::enable_shared_from_this<TGrpcIamCredentialsProvider<TRequest, TResponse, TService>::TImpl> {
public:
TImpl(const TIamEndpoint& iamEndpoint, const TRequestFiller& requestFiller, TAsyncRpc rpc)
TImpl(const TIamEndpoint& iamEndpoint,
const TRequestFiller& requestFiller,
TAsyncRpc rpc,
TCredentialsProviderPtr authTokenProvider = nullptr)
: Rpc_(rpc)
, Ticket_("")
, NextTicketUpdate_(TInstant::Zero())
Expand All @@ -40,6 +43,7 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
, NeedStop_(false)
, BackoffTimeout_(BACKOFF_START)
, Lock_()
, AuthTokenProvider_(authTokenProvider)
{
std::shared_ptr<grpc::ChannelCredentials> creds = nullptr;
if (IamEndpoint_.EnableSsl) {
Expand Down Expand Up @@ -82,15 +86,18 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {

RequestFiller_(req);

grpc::ClientContext context;
Context_ = std::make_unique<grpc::ClientContext>();

auto deadline = gpr_time_add(
gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_micros(IamEndpoint_.RequestTimeout.MicroSeconds(), GPR_TIMESPAN));

context.set_deadline(deadline);
Context_->set_deadline(deadline);
if (AuthTokenProvider_) {
Context_->AddMetadata("authorization", "Bearer " + AuthTokenProvider_->GetAuthInfo());
}

(Stub_->async()->*Rpc_)(&context, &req, response.get(), std::move(cb));
(Stub_->async()->*Rpc_)(Context_.get(), &req, response.get(), std::move(cb));

if (sync) {
resultPromise.GetFuture().Wait(2 * IamEndpoint_.RequestTimeout);
Expand Down Expand Up @@ -125,6 +132,7 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {

private:
void ProcessIamResponse(grpc::Status&& status, TResponse&& result, bool sync) {
Context_.reset();
if (!status.ok()) {
TDuration sleepDuration;
{
Expand Down Expand Up @@ -163,6 +171,8 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
std::shared_ptr<grpc::Channel> Channel_;
std::shared_ptr<typename TService::Stub> Stub_;
TAsyncRpc Rpc_;
std::unique_ptr<grpc::ClientContext> Context_;

std::string Ticket_;
TInstant NextTicketUpdate_;
const TIamEndpoint IamEndpoint_;
Expand All @@ -172,11 +182,15 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
bool NeedStop_;
TDuration BackoffTimeout_;
TAdaptiveLock Lock_;
TCredentialsProviderPtr AuthTokenProvider_;
};

public:
TGrpcIamCredentialsProvider(const TIamEndpoint& endpoint, const TRequestFiller& requestFiller, TAsyncRpc rpc)
: Impl_(std::make_shared<TImpl>(endpoint, requestFiller, rpc))
TGrpcIamCredentialsProvider(const TIamEndpoint& endpoint,
const TRequestFiller& requestFiller,
TAsyncRpc rpc,
TCredentialsProviderPtr authTokenProvider = nullptr)
: Impl_(std::make_shared<TImpl>(endpoint, requestFiller, rpc, authTokenProvider))
{
Impl_->UpdateTicket(true);
}
Expand Down
2 changes: 1 addition & 1 deletion include/ydb-cpp-sdk/client/iam/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <fstream>
#include <string>

namespace NYdb {
namespace NYdb::inline V3 {
namespace NIam {

constexpr std::string_view DEFAULT_ENDPOINT = "iam.api.cloud.yandex.net";
Expand Down
2 changes: 2 additions & 0 deletions include/ydb-cpp-sdk/client/iam_private/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace NYdb::inline V3 {

struct TIamServiceParams : TIamEndpoint {
TCredentialsProviderFactoryPtr SystemServiceAccountCredentials;

std::string ServiceId;
std::string MicroserviceId;
std::string ResourceId;
Expand Down
1 change: 1 addition & 0 deletions include/ydb-cpp-sdk/client/scheme/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum class ESchemeEntryType : i32 {
ResourcePool = 21,
SysView = 22,
Transfer = 23,
StreamingQuery = 24,
};

struct TVirtualTimestamp {
Expand Down
12 changes: 12 additions & 0 deletions include/ydb-cpp-sdk/client/table/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ class TColumnFamilyDescription {
const std::string& GetName() const;
std::optional<std::string> GetData() const;
std::optional<EColumnFamilyCompression> GetCompression() const;
std::optional<EColumnFamilyCacheMode> GetCacheMode() const;
std::optional<bool> GetKeepInMemory() const;

private:
Expand Down Expand Up @@ -829,6 +830,7 @@ class TColumnFamilyBuilder {

TColumnFamilyBuilder& SetData(const std::string& media);
TColumnFamilyBuilder& SetCompression(EColumnFamilyCompression compression);
TColumnFamilyBuilder& SetCacheMode(EColumnFamilyCacheMode cacheMode);
TColumnFamilyBuilder& SetKeepInMemory(bool enabled);

TColumnFamilyDescription Build() const;
Expand Down Expand Up @@ -895,6 +897,11 @@ class TTableColumnFamilyBuilder {
return *this;
}

TTableColumnFamilyBuilder& SetCacheMode(EColumnFamilyCacheMode cacheMode) {
Builder_.SetCacheMode(cacheMode);
return *this;
}

TTableColumnFamilyBuilder& SetKeepInMemory(bool enabled) {
Builder_.SetKeepInMemory(enabled);
return *this;
Expand Down Expand Up @@ -1519,6 +1526,11 @@ class TAlterColumnFamilyBuilder {
return *this;
}

TAlterColumnFamilyBuilder& SetCacheMode(EColumnFamilyCacheMode cacheMode) {
Builder_.SetCacheMode(cacheMode);
return *this;
}

TAlterColumnFamilyBuilder& SetKeepInMemory(bool enabled) {
Builder_.SetKeepInMemory(enabled);
return *this;
Expand Down
6 changes: 6 additions & 0 deletions include/ydb-cpp-sdk/client/table/table_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ enum class EColumnFamilyCompression {
LZ4,
};

//! Column family cache mode
enum class EColumnFamilyCacheMode {
Regular,
InMemory,
};

//! State of build index operation
enum class EBuildIndexState {
Unspecified = 0,
Expand Down
7 changes: 7 additions & 0 deletions src/api/protos/ydb_monitoring.proto
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,18 @@ message LoadAverageStatus {
uint32 cores = 3;
}

message ClockSkewStatus {
StatusFlag.Status overall = 1;
float clock_skew = 2; // ms
}

message ComputeNodeStatus {
string id = 1;
StatusFlag.Status overall = 2;
repeated ComputeTabletStatus tablets = 3;
repeated ThreadPoolStatus pools = 4;
LoadAverageStatus load = 5;
ClockSkewStatus clock_skew = 6;
}

message ComputeStatus {
Expand All @@ -121,6 +127,7 @@ message ComputeStatus {
repeated ComputeTabletStatus tablets = 3;
float paths_quota_usage = 4;
float shards_quota_usage = 5;
ClockSkewStatus clock_skew = 6;
}

message LocationNode {
Expand Down
1 change: 1 addition & 0 deletions src/api/protos/ydb_scheme.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ message Entry {
RESOURCE_POOL = 21;
TRANSFER = 23;
SYS_VIEW = 24;
STREAMING_QUERY = 25;
}

// Name of scheme entry (dir2 of /dir1/dir2)
Expand Down
17 changes: 17 additions & 0 deletions src/api/protos/ydb_table.proto
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ message ColumnFamilyPolicy {
COMPRESSED = 2;
}

enum CacheMode {
CACHE_MODE_UNSPECIFIED = 0;
CACHE_MODE_REGULAR = 1;
CACHE_MODE_IN_MEMORY = 2;
}

// Name of the column family, the name "default" must be used for the
// primary column family that contains as least primary key columns
string name = 1;
Expand All @@ -315,6 +321,9 @@ message ColumnFamilyPolicy {

// Optionally specify whether data should be compressed
Compression compression = 5;

// When IN_MEMORY tries to keep the colums of the family in memory (default is REGULAR)
CacheMode cache_mode = 6;
}

message CompactionPolicy {
Expand Down Expand Up @@ -553,6 +562,12 @@ message ColumnFamily {
COMPRESSION_ZSTD = 3;
}

enum CacheMode {
CACHE_MODE_UNSPECIFIED = 0;
CACHE_MODE_REGULAR = 1;
CACHE_MODE_IN_MEMORY = 2;
}

// Name of the column family
string name = 1;

Expand All @@ -570,6 +585,8 @@ message ColumnFamily {
// For ZSTD compression level must be in range [-131072:22]
// For other compression types compression level must be empty
optional int32 compression_level = 5;

CacheMode cache_mode = 6;
}

message PartitioningSettings {
Expand Down
17 changes: 0 additions & 17 deletions src/client/arrow/accessor.cpp

This file was deleted.

4 changes: 3 additions & 1 deletion src/client/iam_private/common/iam.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class TIamServiceCredentialsProviderFactory : public ICredentialsProviderFactory
req.set_resource_id(params.ResourceId);
req.set_resource_type(params.ResourceType);
req.set_target_service_account_id(params.TargetServiceAccountId);
}, &TService::Stub::async_interface::CreateForService) {}
},
&TService::Stub::async_interface::CreateForService,
params.SystemServiceAccountCredentials->CreateProvider()) {}
};

public:
Expand Down
Loading
Loading