Skip to content

Commit

Permalink
YQ-4101 KqpRun fixed storage and tenants creation (ydb-platform#14472)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoriyPA authored and Kamil Khamitov committed Feb 14, 2025
1 parent 7313435 commit c22699e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ydb/core/testlib/test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3219,7 +3219,7 @@ namespace Tests {
return Server->DynamicNodes();
}

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

Expand All @@ -3229,7 +3229,7 @@ namespace Tests {
std::move(request), "", "", runtime.GetActorSystem(0), true
).ExtractValueSync();

if (result.operation().status() != Ydb::StatusIds::SUCCESS) {
if (result.operation().status() != Ydb::StatusIds::SUCCESS && (!acceptAlreadyExist || result.operation().status() != Ydb::StatusIds::ALREADY_EXISTS)) {
NYql::TIssues issues;
NYql::IssuesFromMessage(result.operation().issues(), issues);
ythrow yexception() << "Failed to create tenant " << path << ", " << result.operation().status() << ", reason:\n" << issues.ToString();
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/testlib/test_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ namespace Tests {
ui32 Availabe() const;
ui32 Capacity() const;

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

private:
TVector<ui32>& Nodes(const TString &name);
Expand Down
1 change: 1 addition & 0 deletions ydb/tests/tools/kqprun/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace NKqpRun {

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

struct TAsyncQueriesSettings {
enum class EVerbose {
Expand Down
1 change: 1 addition & 0 deletions ydb/tests/tools/kqprun/src/proto/storage_meta.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message TStorageMeta {
EType Type = 1;
uint32 NodesCount = 2;
string SharedTenant = 3; // Only for serverless tenants
bool CreationInProgress = 4;
}

uint64 StorageGeneration = 1;
Expand Down
15 changes: 12 additions & 3 deletions ydb/tests/tools/kqprun/src/ydb_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class TYdbSetup::TImpl {
if (!google::protobuf::TextFormat::ParseFromString(TFileInput(StorageMetaPath_.GetPath()).ReadAll(), &StorageMeta_)) {
ythrow yexception() << "Storage meta is corrupted, please use --format-storage";
}
StorageMeta_.SetStorageGeneration(StorageMeta_.GetStorageGeneration() + 1);
formatDisk = false;
}

Expand Down Expand Up @@ -289,11 +288,17 @@ class TYdbSetup::TImpl {
void CreateTenant(Ydb::Cms::CreateDatabaseRequest&& request, const TString& relativePath, const TString& type, TStorageMeta::TTenant tenantInfo) {
const auto absolutePath = request.path();
const auto [it, inserted] = StorageMeta_.MutableTenants()->emplace(relativePath, tenantInfo);
if (inserted) {
if (inserted || it->second.GetCreationInProgress()) {
if (Settings_.VerboseLevel >= EVerbose::Info) {
Cout << CoutColors_.Yellow() << TInstant::Now().ToIsoStringLocal() << " Creating " << type << " tenant " << absolutePath << "..." << CoutColors_.Default() << Endl;
}
Tenants_->CreateTenant(std::move(request), tenantInfo.GetNodesCount());

it->second.SetCreationInProgress(true);
UpdateStorageMeta();

Tenants_->CreateTenant(std::move(request), tenantInfo.GetNodesCount(), TENANT_CREATION_TIMEOUT, true);

it->second.SetCreationInProgress(false);
UpdateStorageMeta();
} else {
if (it->second.GetType() != tenantInfo.GetType()) {
Expand Down Expand Up @@ -378,6 +383,10 @@ class TYdbSetup::TImpl {
NKikimr::Tests::TServerSettings serverSettings = GetServerSettings(grpcPort);

Server_ = MakeIntrusive<NKikimr::Tests::TServer>(serverSettings);

StorageMeta_.SetStorageGeneration(StorageMeta_.GetStorageGeneration() + 1);
UpdateStorageMeta();

Server_->GetRuntime()->SetDispatchTimeout(TDuration::Max());

if (Settings_.GrpcEnabled) {
Expand Down

0 comments on commit c22699e

Please sign in to comment.