Skip to content

Commit 6e413ab

Browse files
authored
YQ-3597 disable metadata objects on serverless (ydb-platform#8921)
1 parent 84e30aa commit 6e413ab

File tree

13 files changed

+285
-4
lines changed

13 files changed

+285
-4
lines changed

ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <ydb/core/kqp/ut/common/kqp_ut_common.h>
22
#include <ydb/core/kqp/ut/common/columnshard.h>
3+
#include <ydb/core/kqp/workload_service/ut/common/kqp_workload_service_ut_common.h>
34
#include <ydb/core/tx/columnshard/hooks/testing/controller.h>
45
#include <ydb/core/formats/arrow/arrow_helpers.h>
56
#include <ydb/core/tx/tx_proxy/proxy.h>

ydb/core/kqp/ut/scheme/ya.make

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PEERDIR(
2222
library/cpp/threading/local_executor
2323
ydb/core/kqp
2424
ydb/core/kqp/ut/common
25+
ydb/core/kqp/workload_service/ut/common
2526
ydb/core/tx/columnshard/hooks/testing
2627
ydb/library/yql/sql/pg
2728
ydb/library/yql/parser/pg_wrapper

ydb/core/kqp/workload_service/ut/common/kqp_workload_service_ut_common.cpp

+57-4
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,15 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
230230
TAppConfig GetAppConfig() const {
231231
TAppConfig appConfig;
232232
appConfig.MutableFeatureFlags()->SetEnableResourcePools(Settings_.EnableResourcePools_);
233+
appConfig.MutableFeatureFlags()->SetEnableMetadataObjectsOnServerless(Settings_.EnableMetadataObjectsOnServerless_);
233234

234235
return appConfig;
235236
}
236237

237238
void SetLoggerSettings(TServerSettings& serverSettings) const {
238239
auto loggerInitializer = [](TTestActorRuntime& runtime) {
239240
runtime.SetLogPriority(NKikimrServices::KQP_WORKLOAD_SERVICE, NLog::EPriority::PRI_TRACE);
240-
runtime.SetLogPriority(NKikimrServices::KQP_SESSION, NLog::EPriority::PRI_DEBUG);
241+
runtime.SetLogPriority(NKikimrServices::KQP_SESSION, NLog::EPriority::PRI_TRACE);
241242
};
242243

243244
serverSettings.SetLoggerInitializer(loggerInitializer);
@@ -254,16 +255,50 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
254255
.SetAppConfig(appConfig)
255256
.SetFeatureFlags(appConfig.GetFeatureFlags());
256257

258+
if (Settings_.CreateSampleTenants_) {
259+
serverSettings
260+
.SetDynamicNodeCount(2)
261+
.AddStoragePoolType(Settings_.GetDedicatedTenantName())
262+
.AddStoragePoolType(Settings_.GetSharedTenantName());
263+
}
264+
257265
SetLoggerSettings(serverSettings);
258266

259267
return serverSettings;
260268
}
261269

270+
void SetupResourcesTenant(Ydb::Cms::CreateDatabaseRequest& request, Ydb::Cms::StorageUnits* storage, const TString& name) {
271+
request.set_path(name);
272+
storage->set_unit_kind(name);
273+
storage->set_count(1);
274+
}
275+
276+
void CreateTenants() {
277+
{ // Dedicated
278+
Ydb::Cms::CreateDatabaseRequest request;
279+
SetupResourcesTenant(request, request.mutable_resources()->add_storage_units(), Settings_.GetDedicatedTenantName());
280+
Tenants_->CreateTenant(std::move(request));
281+
}
282+
283+
{ // Shared
284+
Ydb::Cms::CreateDatabaseRequest request;
285+
SetupResourcesTenant(request, request.mutable_shared_resources()->add_storage_units(), Settings_.GetSharedTenantName());
286+
Tenants_->CreateTenant(std::move(request));
287+
}
288+
289+
{ // Serverless
290+
Ydb::Cms::CreateDatabaseRequest request;
291+
request.set_path(Settings_.GetServerlessTenantName());
292+
request.mutable_serverless_resources()->set_shared_database_path(Settings_.GetSharedTenantName());
293+
Tenants_->CreateTenant(std::move(request));
294+
}
295+
}
296+
262297
void InitializeServer() {
263298
ui32 grpcPort = PortManager_.GetPort();
264299
TServerSettings serverSettings = GetServerSettings(grpcPort);
265300

266-
Server_ = std::make_unique<TServer>(serverSettings);
301+
Server_ = MakeIntrusive<TServer>(serverSettings);
267302
Server_->EnableGRpc(grpcPort);
268303
GetRuntime()->SetDispatchTimeout(FUTURE_WAIT_TIMEOUT);
269304

@@ -276,10 +311,15 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
276311

277312
TableClient_ = std::make_unique<NYdb::NTable::TTableClient>(*YdbDriver_, NYdb::NTable::TClientSettings().AuthToken("user@" BUILTIN_SYSTEM_DOMAIN));
278313
TableClientSession_ = std::make_unique<NYdb::NTable::TSession>(TableClient_->CreateSession().GetValueSync().GetSession());
314+
315+
Tenants_ = std::make_unique<TTenants>(Server_);
316+
if (Settings_.CreateSampleTenants_) {
317+
CreateTenants();
318+
}
279319
}
280320

281321
void CreateSamplePool() const {
282-
if (!Settings_.EnableResourcePools_) {
322+
if (!Settings_.EnableResourcePools_ || Settings_.CreateSampleTenants_) {
283323
return;
284324
}
285325

@@ -529,9 +569,10 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
529569
const TYdbSetupSettings Settings_;
530570

531571
TPortManager PortManager_;
532-
std::unique_ptr<TServer> Server_;
572+
TServer::TPtr Server_;
533573
std::unique_ptr<TClient> Client_;
534574
std::unique_ptr<TDriver> YdbDriver_;
575+
std::unique_ptr<TTenants> Tenants_;
535576

536577
std::unique_ptr<NYdb::NTable::TTableClient> TableClient_;
537578
std::unique_ptr<NYdb::NTable::TSession> TableClientSession_;
@@ -580,6 +621,18 @@ TIntrusivePtr<IYdbSetup> TYdbSetupSettings::Create() const {
580621
return MakeIntrusive<TWorkloadServiceYdbSetup>(*this);
581622
}
582623

624+
TString TYdbSetupSettings::GetDedicatedTenantName() const {
625+
return TStringBuilder() << CanonizePath(DomainName_) << "/test-dedicated";
626+
}
627+
628+
TString TYdbSetupSettings::GetSharedTenantName() const {
629+
return TStringBuilder() << CanonizePath(DomainName_) << "/test-shared";
630+
}
631+
632+
TString TYdbSetupSettings::GetServerlessTenantName() const {
633+
return TStringBuilder() << CanonizePath(DomainName_) << "/test-serverless";
634+
}
635+
583636
//// IYdbSetup
584637

585638
void IYdbSetup::WaitFor(TDuration timeout, TString description, std::function<bool(TString&)> callback) {

ydb/core/kqp/workload_service/ut/common/kqp_workload_service_ut_common.h

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct TQueryRunnerSettings {
2626
FLUENT_SETTING_DEFAULT(ui32, NodeIndex, 0);
2727
FLUENT_SETTING_DEFAULT(TString, PoolId, "");
2828
FLUENT_SETTING_DEFAULT(TString, UserSID, "user@" BUILTIN_SYSTEM_DOMAIN);
29+
FLUENT_SETTING_DEFAULT(TString, Database, "");
2930

3031
// Runner settings
3132
FLUENT_SETTING_DEFAULT(bool, HangUpDuringExecution, false);
@@ -66,7 +67,9 @@ struct TYdbSetupSettings {
6667
// Cluster settings
6768
FLUENT_SETTING_DEFAULT(ui32, NodeCount, 1);
6869
FLUENT_SETTING_DEFAULT(TString, DomainName, "Root");
70+
FLUENT_SETTING_DEFAULT(bool, CreateSampleTenants, false);
6971
FLUENT_SETTING_DEFAULT(bool, EnableResourcePools, true);
72+
FLUENT_SETTING_DEFAULT(bool, EnableMetadataObjectsOnServerless, true);
7073

7174
// Default pool settings
7275
FLUENT_SETTING_DEFAULT(TString, PoolId, "sample_pool_id");
@@ -77,6 +80,10 @@ struct TYdbSetupSettings {
7780
FLUENT_SETTING_DEFAULT(double, DatabaseLoadCpuThreshold, -1);
7881

7982
TIntrusivePtr<IYdbSetup> Create() const;
83+
84+
TString GetDedicatedTenantName() const;
85+
TString GetSharedTenantName() const;
86+
TString GetServerlessTenantName() const;
8087
};
8188

8289
class IYdbSetup : public TThrRefBase {
@@ -132,6 +139,12 @@ struct TSampleQueries {
132139
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Request timeout exceeded, cancelling after");
133140
}
134141

142+
template <typename TResult>
143+
static void CheckNotFound(const TResult& result, const TString& poolId) {
144+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::NOT_FOUND, result.GetIssues().ToString());
145+
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), TStringBuilder() << "Resource pool " << poolId << " not found or you don't have access permissions");
146+
}
147+
135148
struct TSelect42 {
136149
static constexpr char Query[] = "SELECT 42;";
137150

ydb/core/protos/feature_flags.proto

+1
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,5 @@ message TFeatureFlags {
149149
optional bool EnableResourcePoolsCounters = 135 [default = false];
150150
optional bool EnableOptionalColumnsInColumnShard = 136 [default = false];
151151
optional bool EnablePgSyntax = 139 [default = false];
152+
optional bool EnableMetadataObjectsOnServerless = 141 [default = true];
152153
}

ydb/core/testlib/basics/feature_flags.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class TTestFeatureFlagsHolder {
6363
FEATURE_FLAG_SETTER(EnableResourcePools)
6464
FEATURE_FLAG_SETTER(EnableChangefeedsOnIndexTables)
6565
FEATURE_FLAG_SETTER(EnablePgSyntax)
66+
FEATURE_FLAG_SETTER(EnableMetadataObjectsOnServerless)
6667

6768
#undef FEATURE_FLAG_SETTER
6869
};

ydb/core/testlib/test_client.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,50 @@ namespace Tests {
26942694
return Server->DynamicNodes();
26952695
}
26962696

2697+
void TTenants::CreateTenant(Ydb::Cms::CreateDatabaseRequest request, ui32 nodes, TDuration timeout) {
2698+
const TString path = request.path();
2699+
const bool serverless = request.has_serverless_resources();
2700+
2701+
// Create new tenant
2702+
auto& runtime = *Server->GetRuntime();
2703+
const auto result = NKikimr::NRpcService::DoLocalRpc<NKikimr::NGRpcService::TGrpcRequestOperationCall<Ydb::Cms::CreateDatabaseRequest, Ydb::Cms::CreateDatabaseResponse>>(
2704+
std::move(request), "", "", runtime.GetActorSystem(0), true
2705+
).ExtractValueSync();
2706+
2707+
if (result.operation().status() != Ydb::StatusIds::SUCCESS) {
2708+
NYql::TIssues issues;
2709+
NYql::IssuesFromMessage(result.operation().issues(), issues);
2710+
ythrow yexception() << "Failed to create tenant " << path << ", " << result.operation().status() << ", reason:\n" << issues.ToString();
2711+
}
2712+
2713+
// Run new tenant
2714+
if (!serverless) {
2715+
Run(path, nodes);
2716+
}
2717+
2718+
// Wait tenant is up
2719+
Ydb::Cms::GetDatabaseStatusResult getTenantResult;
2720+
const TActorId edgeActor = runtime.AllocateEdgeActor();
2721+
const TInstant start = TInstant::Now();
2722+
while (TInstant::Now() - start <= timeout) {
2723+
auto getTenantRequest = std::make_unique<NConsole::TEvConsole::TEvGetTenantStatusRequest>();
2724+
getTenantRequest->Record.MutableRequest()->set_path(path);
2725+
runtime.SendToPipe(MakeConsoleID(), edgeActor, getTenantRequest.release(), 0, GetPipeConfigWithRetries());
2726+
2727+
auto response = runtime.GrabEdgeEvent<NConsole::TEvConsole::TEvGetTenantStatusResponse>(edgeActor, timeout);
2728+
if (!response) {
2729+
ythrow yexception() << "Waiting CMS get tenant response timeout. Last tenant description:\n" << getTenantResult.DebugString();
2730+
}
2731+
response->Get()->Record.GetResponse().operation().result().UnpackTo(&getTenantResult);
2732+
if (getTenantResult.state() == Ydb::Cms::GetDatabaseStatusResult::RUNNING) {
2733+
return;
2734+
}
2735+
2736+
Sleep(TDuration::MilliSeconds(100));
2737+
}
2738+
ythrow yexception() << "Waiting tenant status RUNNING timeout. Spent time " << TInstant::Now() - start << " exceeds limit " << timeout << ". Last tenant description:\n" << getTenantResult.DebugString();
2739+
}
2740+
26972741
TVector<ui32> &TTenants::Nodes(const TString &name) {
26982742
return Tenants[name];
26992743
}

ydb/core/testlib/test_client.h

+2
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,8 @@ namespace Tests {
630630
ui32 Availabe() const;
631631
ui32 Capacity() const;
632632

633+
void CreateTenant(Ydb::Cms::CreateDatabaseRequest request, ui32 nodes = 1, TDuration timeout = TDuration::Seconds(30));
634+
633635
private:
634636
TVector<ui32>& Nodes(const TString &name);
635637
void StopNode(const TString /*name*/, ui32 nodeIdx);

ydb/services/metadata/manager/alter_impl.h

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include "abstract.h"
3+
#include "fetch_database.h"
34
#include "modification_controller.h"
45
#include "preparation_controller.h"
56
#include "restore.h"
@@ -111,6 +112,7 @@ class TModificationActorImpl: public NActors::TActorBootstrapped<TModificationAc
111112
hFunc(NRequest::TEvRequestFailed, Handle);
112113
hFunc(TEvRestoreProblem, Handle);
113114
hFunc(TEvAlterPreparationProblem, Handle);
115+
hFunc(TEvFetchDatabaseResponse, Handle);
114116
default:
115117
break;
116118
}
@@ -126,6 +128,30 @@ class TModificationActorImpl: public NActors::TActorBootstrapped<TModificationAc
126128
return TBase::PassAway();
127129
}
128130

131+
if (!AppData()->FeatureFlags.GetEnableMetadataObjectsOnServerless() && Context.GetActivityType() != IOperationsManager::EActivityType::Drop) {
132+
TBase::Register(CreateDatabaseFetcherActor(Context.GetExternalData().GetDatabase()));
133+
} else {
134+
CreateSession();
135+
}
136+
}
137+
138+
void Handle(TEvFetchDatabaseResponse::TPtr& ev) {
139+
TString errorMessage;
140+
if (const auto& errorString = ev->Get()->GetErrorString()) {
141+
errorMessage = TStringBuilder() << "Cannot fetch database '" << Context.GetExternalData().GetDatabase() << "': " << *errorString;
142+
} else if (ev->Get()->GetServerless()) {
143+
errorMessage = TStringBuilder() << "Objects " << TObject::GetTypeId() << " are disabled for serverless domains. Please contact your system administrator to enable it";
144+
}
145+
146+
if (errorMessage) {
147+
auto g = TBase::PassAwayGuard();
148+
ExternalController->OnAlteringProblem(errorMessage);
149+
} else {
150+
CreateSession();
151+
}
152+
}
153+
154+
void CreateSession() const {
129155
TBase::Register(new NRequest::TYDBCallbackRequest<NRequest::TDialogCreateSession>(
130156
NRequest::TDialogCreateSession::TRequest(), UserToken, TBase::SelfId()));
131157
}

ydb/services/metadata/manager/common.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ enum EEvents {
3535
EvAlterProblem,
3636
EvAlterPreparationFinished,
3737
EvAlterPreparationProblem,
38+
EvFetchDatabaseResponse,
3839
EvEnd
3940
};
4041
static_assert(EEvents::EvEnd < EventSpaceEnd(TKikimrEvents::ES_METADATA_MANAGER), "expect EvEnd < EventSpaceEnd(TKikimrEvents::ES_METADATA_MANAGER)");

0 commit comments

Comments
 (0)