Skip to content

Commit d93a17b

Browse files
authored
YQ-4092 KqpRun improve tenants flags (#14279)
1 parent 3d05c5c commit d93a17b

File tree

4 files changed

+192
-74
lines changed

4 files changed

+192
-74
lines changed

ydb/tests/tools/kqprun/kqprun.cpp

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct TExecutionOptions {
9595
.TraceId = DefaultTraceId,
9696
.PoolId = "",
9797
.UserSID = BUILTIN_ACL_ROOT,
98-
.Database = "",
98+
.Database = GetValue(0, Databases, TString()),
9999
.Timeout = TDuration::Zero()
100100
};
101101
}
@@ -135,15 +135,15 @@ struct TExecutionOptions {
135135

136136
private:
137137
void ValidateOptionsSizes(const TRunnerOptions& runnerOptions) const {
138-
const auto checker = [numberQueries = ScriptQueries.size()](size_t checkSize, const TString& optionName) {
139-
if (checkSize > numberQueries) {
138+
const auto checker = [numberQueries = ScriptQueries.size()](size_t checkSize, const TString& optionName, bool useInSchemeQuery = false) {
139+
if (checkSize > std::max(numberQueries, static_cast<size_t>(useInSchemeQuery ? 1 : 0))) {
140140
ythrow yexception() << "Too many " << optionName << ". Specified " << checkSize << ", when number of script queries is " << numberQueries;
141141
}
142142
};
143143

144144
checker(ExecutionCases.size(), "execution cases");
145145
checker(ScriptQueryActions.size(), "script query actions");
146-
checker(Databases.size(), "databases");
146+
checker(Databases.size(), "databases", true);
147147
checker(TraceIds.size(), "trace ids");
148148
checker(PoolIds.size(), "pool ids");
149149
checker(UserSIDs.size(), "user SIDs");
@@ -257,7 +257,7 @@ struct TExecutionOptions {
257257

258258
static void ValidateStorageSettings(const TYdbSetupSettings& ydbSettings) {
259259
if (ydbSettings.DisableDiskMock) {
260-
if (ydbSettings.NodeCount + ydbSettings.SharedTenants.size() + ydbSettings.DedicatedTenants.size() > 1) {
260+
if (ydbSettings.NodeCount + ydbSettings.Tenants.size() > 1) {
261261
ythrow yexception() << "Disable disk mock cannot be used for multi node clusters (already disabled)";
262262
} else if (ydbSettings.PDisksPath) {
263263
ythrow yexception() << "Disable disk mock cannot be used with real PDisks (already disabled)";
@@ -876,17 +876,50 @@ class TMain : public TMainClassArgs {
876876
.DefaultValue(RunnerOptions.YdbSettings.DomainName)
877877
.StoreResult(&RunnerOptions.YdbSettings.DomainName);
878878

879-
options.AddLongOption("dedicated", "Dedicated tenant path, relative inside domain")
879+
const auto addTenant = [this](const TString& type, TStorageMeta::TTenant::EType protoType, const NLastGetopt::TOptsParser* option) {
880+
TStringBuf tenant;
881+
TStringBuf nodesCountStr;
882+
TStringBuf(option->CurVal()).Split(':', tenant, nodesCountStr);
883+
if (tenant.empty()) {
884+
ythrow yexception() << type << " tenant name should not be empty";
885+
}
886+
887+
TStorageMeta::TTenant tenantInfo;
888+
tenantInfo.SetType(protoType);
889+
tenantInfo.SetNodesCount(nodesCountStr ? FromString<ui32>(nodesCountStr) : 1);
890+
if (tenantInfo.GetNodesCount() == 0) {
891+
ythrow yexception() << type << " tenant should have at least one node";
892+
}
893+
894+
if (!RunnerOptions.YdbSettings.Tenants.emplace(tenant, tenantInfo).second) {
895+
ythrow yexception() << "Got duplicated tenant name: " << tenant;
896+
}
897+
};
898+
options.AddLongOption("dedicated", "Dedicated tenant path, relative inside domain (for node count use dedicated-name:node-count)")
880899
.RequiredArgument("path")
881-
.InsertTo(&RunnerOptions.YdbSettings.DedicatedTenants);
900+
.Handler1(std::bind(addTenant, "Dedicated", TStorageMeta::TTenant::DEDICATED, std::placeholders::_1));
882901

883-
options.AddLongOption("shared", "Shared tenant path, relative inside domain")
902+
options.AddLongOption("shared", "Shared tenant path, relative inside domain (for node count use dedicated-name:node-count)")
884903
.RequiredArgument("path")
885-
.InsertTo(&RunnerOptions.YdbSettings.SharedTenants);
904+
.Handler1(std::bind(addTenant, "Shared", TStorageMeta::TTenant::SHARED, std::placeholders::_1));
886905

887906
options.AddLongOption("serverless", "Serverless tenant path, relative inside domain (use string serverless-name@shared-name to specify shared database)")
888907
.RequiredArgument("path")
889-
.InsertTo(&RunnerOptions.YdbSettings.ServerlessTenants);
908+
.Handler1([this](const NLastGetopt::TOptsParser* option) {
909+
TStringBuf serverless;
910+
TStringBuf shared;
911+
TStringBuf(option->CurVal()).Split('@', serverless, shared);
912+
if (serverless.empty()) {
913+
ythrow yexception() << "Serverless tenant name should not be empty";
914+
}
915+
916+
TStorageMeta::TTenant tenantInfo;
917+
tenantInfo.SetType(TStorageMeta::TTenant::SERVERLESS);
918+
tenantInfo.SetSharedTenant(TString(shared));
919+
if (!RunnerOptions.YdbSettings.Tenants.emplace(serverless, tenantInfo).second) {
920+
ythrow yexception() << "Got duplicated tenant name: " << serverless;
921+
}
922+
});
890923

891924
options.AddLongOption("storage-size", TStringBuilder() << "Domain storage size in gigabytes (" << NKikimr::NBlobDepot::FormatByteSize(DEFAULT_STORAGE_SIZE) << " by default)")
892925
.RequiredArgument("uint")

ydb/tests/tools/kqprun/src/common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <ydb/public/api/protos/ydb_cms.pb.h>
1010
#include <ydb/public/lib/ydb_cli/common/formats.h>
1111

12+
#include <ydb/tests/tools/kqprun/src/proto/storage_meta.pb.h>
13+
1214
#include <yql/essentials/minikql/computation/mkql_computation_node.h>
1315
#include <yql/essentials/minikql/mkql_function_registry.h>
1416

@@ -48,9 +50,7 @@ struct TYdbSetupSettings {
4850

4951
ui32 NodeCount = 1;
5052
TString DomainName = "Root";
51-
std::unordered_set<TString> DedicatedTenants;
52-
std::unordered_set<TString> SharedTenants;
53-
std::unordered_set<TString> ServerlessTenants;
53+
std::map<TString, TStorageMeta::TTenant> Tenants;
5454
TDuration HealthCheckTimeout = TDuration::Seconds(10);
5555
EHealthCheck HealthCheckLevel = EHealthCheck::NodesCount;
5656
bool SameSession = false;

ydb/tests/tools/kqprun/src/proto/storage_meta.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ syntax = "proto3";
33
package NKqpRun;
44

55
message TStorageMeta {
6+
message TTenant {
7+
enum EType {
8+
DEDICATED = 0;
9+
SHARED = 1;
10+
SERVERLESS = 2;
11+
}
12+
13+
EType Type = 1;
14+
uint32 NodesCount = 2;
15+
string SharedTenant = 3; // Only for serverless tenants
16+
}
17+
618
uint64 StorageGeneration = 1;
719
uint64 StorageSize = 2;
20+
string DomainName = 3;
21+
map<string, TTenant> Tenants = 4;
822
}

0 commit comments

Comments
 (0)