Skip to content

YDBD binary args: added database quotas limits #496

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

Merged
merged 7 commits into from
Jan 22, 2024
Merged
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
62 changes: 61 additions & 1 deletion ydb/core/driver_lib/cli_utils/cli_cmds_tenant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,39 @@ class TClientCommandTenantStatus
for (auto &unit : result.registered_resources()) {
Cout << " " << unit.host() << ":" << unit.port() << " - " << unit.unit_kind() << Endl;
}
Cout << " Data size hard quota: " << result.database_quotas().data_size_hard_quota() << Endl;
Cout << " Data size soft quota: " << result.database_quotas().data_size_soft_quota() << Endl;
}
}
};

class TClientCommandTenantQuotasBase {
uint64_t DataSizeHardQuota;
uint64_t DataSizeSoftQuota;
public:
void Config(auto& config) {
config.Opts->AddLongOption("data-size-hard-quota", "A maximum data size in bytes, new data will be rejected when exceeded")
.OptionalArgument("NUM").StoreResult(&DataSizeHardQuota);
config.Opts->AddLongOption("data-size-soft-quota", "Data size in bytes (lower than data_size_hard_quota), at this value new data ingestion is re-enabled again")
.OptionalArgument("NUM").StoreResult(&DataSizeSoftQuota);
}

void Parse(auto& config, auto& gRpcRequest)
{
if (config.ParseResult->Has("data-size-hard-quota"))
gRpcRequest.mutable_database_quotas()->set_data_size_hard_quota(DataSizeHardQuota);
if (config.ParseResult->Has("data-size-soft-quota"))
gRpcRequest.mutable_database_quotas()->set_data_size_soft_quota(DataSizeSoftQuota);
}
};

class TClientCommandTenantCreate
: public TTenantClientGRpcCommand<Ydb::Cms::V1::CmsService,
Ydb::Cms::CreateDatabaseRequest,
Ydb::Cms::CreateDatabaseResponse,
decltype(&Ydb::Cms::V1::CmsService::Stub::AsyncCreateDatabase),
&Ydb::Cms::V1::CmsService::Stub::AsyncCreateDatabase> {
&Ydb::Cms::V1::CmsService::Stub::AsyncCreateDatabase>,
TClientCommandTenantQuotasBase {
TVector<TString> Attributes;
bool Shared = false;
bool Serverless = false;
Expand All @@ -326,6 +349,7 @@ class TClientCommandTenantCreate
void Config(TConfig &config) override
{
TTenantClientGRpcCommand::Config(config);
TClientCommandTenantQuotasBase::Config(config);

config.Opts->AddLongOption("no-tx", "Disable tenant services for database")
.NoArgument();
Expand All @@ -342,6 +366,7 @@ class TClientCommandTenantCreate
void Parse(TConfig& config) override
{
TTenantClientGRpcCommand::Parse(config);
TClientCommandTenantQuotasBase::Parse(config, GRpcRequest);

GRpcRequest.set_path(config.Tenant);
if (config.ParseResult->Has("no-tx"))
Expand Down Expand Up @@ -606,6 +631,31 @@ class TClientCommandTenantAddPools
}
};

class TClientCommandTenantChangeQuotas
: public TTenantClientGRpcCommand<Ydb::Cms::V1::CmsService,
Ydb::Cms::AlterDatabaseRequest,
Ydb::Cms::AlterDatabaseResponse,
decltype(&Ydb::Cms::V1::CmsService::Stub::AsyncAlterDatabase),
&Ydb::Cms::V1::CmsService::Stub::AsyncAlterDatabase>,
TClientCommandTenantQuotasBase {
public:
TClientCommandTenantChangeQuotas()
: TTenantClientGRpcCommand("change", {}, "Change data size quotas for database")
{}

void Config(TConfig& config) override {
TTenantClientGRpcCommand::Config(config);
TClientCommandTenantQuotasBase::Config(config);
config.SetFreeArgsMin(0);
}

void Parse(TConfig& config) override
{
TTenantClientGRpcCommand::Parse(config);
TClientCommandTenantQuotasBase::Parse(config, GRpcRequest);
}
};

class TClientCommandTenantUnits : public TClientCommandTree {
public:
TClientCommandTenantUnits()
Expand All @@ -627,6 +677,15 @@ class TClientCommandTenantPools : public TClientCommandTree {
}
};

class TClientCommandTenantQuotas : public TClientCommandTree {
public:
TClientCommandTenantQuotas()
: TClientCommandTree("quotas", {}, "Manage database size quotas")
{
AddCommand(std::make_unique<TClientCommandTenantChangeQuotas>());
}
};

class TClientCommandTenantName : public TClientCommandTree {
public:
TClientCommandTenantName()
Expand All @@ -637,6 +696,7 @@ class TClientCommandTenantName : public TClientCommandTree {
AddCommand(std::make_unique<TClientCommandTenantRemove>());
AddCommand(std::make_unique<TClientCommandTenantStatus>());
AddCommand(std::make_unique<TClientCommandTenantUnits>());
AddCommand(std::make_unique<TClientCommandTenantQuotas>());
}

virtual void Parse(TConfig& config) override {
Expand Down