Skip to content

Commit 82981cc

Browse files
authored
YQ-4101 KqpRun fixed storage and tenants creation (#14472)
1 parent 8e21656 commit 82981cc

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

ydb/core/testlib/test_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,7 @@ namespace Tests {
32223222
return Server->DynamicNodes();
32233223
}
32243224

3225-
void TTenants::CreateTenant(Ydb::Cms::CreateDatabaseRequest request, ui32 nodes, TDuration timeout) {
3225+
void TTenants::CreateTenant(Ydb::Cms::CreateDatabaseRequest request, ui32 nodes, TDuration timeout, bool acceptAlreadyExist) {
32263226
const TString path = request.path();
32273227
const bool serverless = request.has_serverless_resources();
32283228

@@ -3232,7 +3232,7 @@ namespace Tests {
32323232
std::move(request), "", "", runtime.GetActorSystem(0), true
32333233
).ExtractValueSync();
32343234

3235-
if (result.operation().status() != Ydb::StatusIds::SUCCESS) {
3235+
if (result.operation().status() != Ydb::StatusIds::SUCCESS && (!acceptAlreadyExist || result.operation().status() != Ydb::StatusIds::ALREADY_EXISTS)) {
32363236
NYql::TIssues issues;
32373237
NYql::IssuesFromMessage(result.operation().issues(), issues);
32383238
ythrow yexception() << "Failed to create tenant " << path << ", " << result.operation().status() << ", reason:\n" << issues.ToString();

ydb/core/testlib/test_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ namespace Tests {
709709
ui32 Availabe() const;
710710
ui32 Capacity() const;
711711

712-
void CreateTenant(Ydb::Cms::CreateDatabaseRequest request, ui32 nodes = 1, TDuration timeout = TDuration::Seconds(30));
712+
void CreateTenant(Ydb::Cms::CreateDatabaseRequest request, ui32 nodes = 1, TDuration timeout = TDuration::Seconds(30), bool acceptAlreadyExist = false);
713713

714714
private:
715715
TVector<ui32>& Nodes(const TString &name);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace NKqpRun {
2020

2121
constexpr char YQL_TOKEN_VARIABLE[] = "YQL_TOKEN";
2222
constexpr ui64 DEFAULT_STORAGE_SIZE = 32_GB;
23+
constexpr TDuration TENANT_CREATION_TIMEOUT = TDuration::Seconds(30);
2324

2425
struct TAsyncQueriesSettings {
2526
enum class EVerbose {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ message TStorageMeta {
1313
EType Type = 1;
1414
uint32 NodesCount = 2;
1515
string SharedTenant = 3; // Only for serverless tenants
16+
bool CreationInProgress = 4;
1617
}
1718

1819
uint64 StorageGeneration = 1;

ydb/tests/tools/kqprun/src/ydb_setup.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ class TYdbSetup::TImpl {
192192
if (!google::protobuf::TextFormat::ParseFromString(TFileInput(StorageMetaPath_.GetPath()).ReadAll(), &StorageMeta_)) {
193193
ythrow yexception() << "Storage meta is corrupted, please use --format-storage";
194194
}
195-
StorageMeta_.SetStorageGeneration(StorageMeta_.GetStorageGeneration() + 1);
196195
formatDisk = false;
197196
}
198197

@@ -289,11 +288,17 @@ class TYdbSetup::TImpl {
289288
void CreateTenant(Ydb::Cms::CreateDatabaseRequest&& request, const TString& relativePath, const TString& type, TStorageMeta::TTenant tenantInfo) {
290289
const auto absolutePath = request.path();
291290
const auto [it, inserted] = StorageMeta_.MutableTenants()->emplace(relativePath, tenantInfo);
292-
if (inserted) {
291+
if (inserted || it->second.GetCreationInProgress()) {
293292
if (Settings_.VerboseLevel >= EVerbose::Info) {
294293
Cout << CoutColors_.Yellow() << TInstant::Now().ToIsoStringLocal() << " Creating " << type << " tenant " << absolutePath << "..." << CoutColors_.Default() << Endl;
295294
}
296-
Tenants_->CreateTenant(std::move(request), tenantInfo.GetNodesCount());
295+
296+
it->second.SetCreationInProgress(true);
297+
UpdateStorageMeta();
298+
299+
Tenants_->CreateTenant(std::move(request), tenantInfo.GetNodesCount(), TENANT_CREATION_TIMEOUT, true);
300+
301+
it->second.SetCreationInProgress(false);
297302
UpdateStorageMeta();
298303
} else {
299304
if (it->second.GetType() != tenantInfo.GetType()) {
@@ -378,6 +383,10 @@ class TYdbSetup::TImpl {
378383
NKikimr::Tests::TServerSettings serverSettings = GetServerSettings(grpcPort);
379384

380385
Server_ = MakeIntrusive<NKikimr::Tests::TServer>(serverSettings);
386+
387+
StorageMeta_.SetStorageGeneration(StorageMeta_.GetStorageGeneration() + 1);
388+
UpdateStorageMeta();
389+
381390
Server_->GetRuntime()->SetDispatchTimeout(TDuration::Max());
382391

383392
if (Settings_.GrpcEnabled) {

0 commit comments

Comments
 (0)