Skip to content

YQ-3597 disable metadata objects on serverless #8921

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
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <ydb/core/kqp/ut/common/kqp_ut_common.h>
#include <ydb/core/kqp/ut/common/columnshard.h>
#include <ydb/core/kqp/workload_service/ut/common/kqp_workload_service_ut_common.h>
#include <ydb/core/tx/columnshard/hooks/testing/controller.h>
#include <ydb/core/formats/arrow/arrow_helpers.h>
#include <ydb/core/tx/tx_proxy/proxy.h>
Expand Down
1 change: 1 addition & 0 deletions ydb/core/kqp/ut/scheme/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ PEERDIR(
library/cpp/threading/local_executor
ydb/core/kqp
ydb/core/kqp/ut/common
ydb/core/kqp/workload_service/ut/common
ydb/core/tx/columnshard/hooks/testing
ydb/library/yql/sql/pg
ydb/library/yql/parser/pg_wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,15 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
TAppConfig GetAppConfig() const {
TAppConfig appConfig;
appConfig.MutableFeatureFlags()->SetEnableResourcePools(Settings_.EnableResourcePools_);
appConfig.MutableFeatureFlags()->SetEnableMetadataObjectsOnServerless(Settings_.EnableMetadataObjectsOnServerless_);

return appConfig;
}

void SetLoggerSettings(TServerSettings& serverSettings) const {
auto loggerInitializer = [](TTestActorRuntime& runtime) {
runtime.SetLogPriority(NKikimrServices::KQP_WORKLOAD_SERVICE, NLog::EPriority::PRI_TRACE);
runtime.SetLogPriority(NKikimrServices::KQP_SESSION, NLog::EPriority::PRI_DEBUG);
runtime.SetLogPriority(NKikimrServices::KQP_SESSION, NLog::EPriority::PRI_TRACE);
};

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

if (Settings_.CreateSampleTenants_) {
serverSettings
.SetDynamicNodeCount(2)
.AddStoragePoolType(Settings_.GetDedicatedTenantName())
.AddStoragePoolType(Settings_.GetSharedTenantName());
}

SetLoggerSettings(serverSettings);

return serverSettings;
}

void SetupResourcesTenant(Ydb::Cms::CreateDatabaseRequest& request, Ydb::Cms::StorageUnits* storage, const TString& name) {
request.set_path(name);
storage->set_unit_kind(name);
storage->set_count(1);
}

void CreateTenants() {
{ // Dedicated
Ydb::Cms::CreateDatabaseRequest request;
SetupResourcesTenant(request, request.mutable_resources()->add_storage_units(), Settings_.GetDedicatedTenantName());
Tenants_->CreateTenant(std::move(request));
}

{ // Shared
Ydb::Cms::CreateDatabaseRequest request;
SetupResourcesTenant(request, request.mutable_shared_resources()->add_storage_units(), Settings_.GetSharedTenantName());
Tenants_->CreateTenant(std::move(request));
}

{ // Serverless
Ydb::Cms::CreateDatabaseRequest request;
request.set_path(Settings_.GetServerlessTenantName());
request.mutable_serverless_resources()->set_shared_database_path(Settings_.GetSharedTenantName());
Tenants_->CreateTenant(std::move(request));
}
}

void InitializeServer() {
ui32 grpcPort = PortManager_.GetPort();
TServerSettings serverSettings = GetServerSettings(grpcPort);

Server_ = std::make_unique<TServer>(serverSettings);
Server_ = MakeIntrusive<TServer>(serverSettings);
Server_->EnableGRpc(grpcPort);
GetRuntime()->SetDispatchTimeout(FUTURE_WAIT_TIMEOUT);

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

TableClient_ = std::make_unique<NYdb::NTable::TTableClient>(*YdbDriver_, NYdb::NTable::TClientSettings().AuthToken("user@" BUILTIN_SYSTEM_DOMAIN));
TableClientSession_ = std::make_unique<NYdb::NTable::TSession>(TableClient_->CreateSession().GetValueSync().GetSession());

Tenants_ = std::make_unique<TTenants>(Server_);
if (Settings_.CreateSampleTenants_) {
CreateTenants();
}
}

void CreateSamplePool() const {
if (!Settings_.EnableResourcePools_) {
if (!Settings_.EnableResourcePools_ || Settings_.CreateSampleTenants_) {
return;
}

Expand Down Expand Up @@ -529,9 +569,10 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
const TYdbSetupSettings Settings_;

TPortManager PortManager_;
std::unique_ptr<TServer> Server_;
TServer::TPtr Server_;
std::unique_ptr<TClient> Client_;
std::unique_ptr<TDriver> YdbDriver_;
std::unique_ptr<TTenants> Tenants_;

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

TString TYdbSetupSettings::GetDedicatedTenantName() const {
return TStringBuilder() << CanonizePath(DomainName_) << "/test-dedicated";
}

TString TYdbSetupSettings::GetSharedTenantName() const {
return TStringBuilder() << CanonizePath(DomainName_) << "/test-shared";
}

TString TYdbSetupSettings::GetServerlessTenantName() const {
return TStringBuilder() << CanonizePath(DomainName_) << "/test-serverless";
}

//// IYdbSetup

void IYdbSetup::WaitFor(TDuration timeout, TString description, std::function<bool(TString&)> callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct TQueryRunnerSettings {
FLUENT_SETTING_DEFAULT(ui32, NodeIndex, 0);
FLUENT_SETTING_DEFAULT(TString, PoolId, "");
FLUENT_SETTING_DEFAULT(TString, UserSID, "user@" BUILTIN_SYSTEM_DOMAIN);
FLUENT_SETTING_DEFAULT(TString, Database, "");

// Runner settings
FLUENT_SETTING_DEFAULT(bool, HangUpDuringExecution, false);
Expand Down Expand Up @@ -66,7 +67,9 @@ struct TYdbSetupSettings {
// Cluster settings
FLUENT_SETTING_DEFAULT(ui32, NodeCount, 1);
FLUENT_SETTING_DEFAULT(TString, DomainName, "Root");
FLUENT_SETTING_DEFAULT(bool, CreateSampleTenants, false);
FLUENT_SETTING_DEFAULT(bool, EnableResourcePools, true);
FLUENT_SETTING_DEFAULT(bool, EnableMetadataObjectsOnServerless, true);

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

TIntrusivePtr<IYdbSetup> Create() const;

TString GetDedicatedTenantName() const;
TString GetSharedTenantName() const;
TString GetServerlessTenantName() const;
};

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

template <typename TResult>
static void CheckNotFound(const TResult& result, const TString& poolId) {
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::NOT_FOUND, result.GetIssues().ToString());
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), TStringBuilder() << "Resource pool " << poolId << " not found or you don't have access permissions");
}

struct TSelect42 {
static constexpr char Query[] = "SELECT 42;";

Expand Down
1 change: 1 addition & 0 deletions ydb/core/protos/feature_flags.proto
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@ message TFeatureFlags {
optional bool EnableResourcePoolsCounters = 135 [default = false];
optional bool EnableOptionalColumnsInColumnShard = 136 [default = false];
optional bool EnablePgSyntax = 139 [default = false];
optional bool EnableMetadataObjectsOnServerless = 141 [default = true];
}
1 change: 1 addition & 0 deletions ydb/core/testlib/basics/feature_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class TTestFeatureFlagsHolder {
FEATURE_FLAG_SETTER(EnableResourcePools)
FEATURE_FLAG_SETTER(EnableChangefeedsOnIndexTables)
FEATURE_FLAG_SETTER(EnablePgSyntax)
FEATURE_FLAG_SETTER(EnableMetadataObjectsOnServerless)

#undef FEATURE_FLAG_SETTER
};
Expand Down
44 changes: 44 additions & 0 deletions ydb/core/testlib/test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,50 @@ namespace Tests {
return Server->DynamicNodes();
}

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

// Create new tenant
auto& runtime = *Server->GetRuntime();
const auto result = NKikimr::NRpcService::DoLocalRpc<NKikimr::NGRpcService::TGrpcRequestOperationCall<Ydb::Cms::CreateDatabaseRequest, Ydb::Cms::CreateDatabaseResponse>>(
std::move(request), "", "", runtime.GetActorSystem(0), true
).ExtractValueSync();

if (result.operation().status() != Ydb::StatusIds::SUCCESS) {
NYql::TIssues issues;
NYql::IssuesFromMessage(result.operation().issues(), issues);
ythrow yexception() << "Failed to create tenant " << path << ", " << result.operation().status() << ", reason:\n" << issues.ToString();
}

// Run new tenant
if (!serverless) {
Run(path, nodes);
}

// Wait tenant is up
Ydb::Cms::GetDatabaseStatusResult getTenantResult;
const TActorId edgeActor = runtime.AllocateEdgeActor();
const TInstant start = TInstant::Now();
while (TInstant::Now() - start <= timeout) {
auto getTenantRequest = std::make_unique<NConsole::TEvConsole::TEvGetTenantStatusRequest>();
getTenantRequest->Record.MutableRequest()->set_path(path);
runtime.SendToPipe(MakeConsoleID(), edgeActor, getTenantRequest.release(), 0, GetPipeConfigWithRetries());

auto response = runtime.GrabEdgeEvent<NConsole::TEvConsole::TEvGetTenantStatusResponse>(edgeActor, timeout);
if (!response) {
ythrow yexception() << "Waiting CMS get tenant response timeout. Last tenant description:\n" << getTenantResult.DebugString();
}
response->Get()->Record.GetResponse().operation().result().UnpackTo(&getTenantResult);
if (getTenantResult.state() == Ydb::Cms::GetDatabaseStatusResult::RUNNING) {
return;
}

Sleep(TDuration::MilliSeconds(100));
}
ythrow yexception() << "Waiting tenant status RUNNING timeout. Spent time " << TInstant::Now() - start << " exceeds limit " << timeout << ". Last tenant description:\n" << getTenantResult.DebugString();
}

TVector<ui32> &TTenants::Nodes(const TString &name) {
return Tenants[name];
}
Expand Down
2 changes: 2 additions & 0 deletions ydb/core/testlib/test_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ namespace Tests {
ui32 Availabe() const;
ui32 Capacity() const;

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

private:
TVector<ui32>& Nodes(const TString &name);
void StopNode(const TString /*name*/, ui32 nodeIdx);
Expand Down
26 changes: 26 additions & 0 deletions ydb/services/metadata/manager/alter_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "abstract.h"
#include "fetch_database.h"
#include "modification_controller.h"
#include "preparation_controller.h"
#include "restore.h"
Expand Down Expand Up @@ -111,6 +112,7 @@ class TModificationActorImpl: public NActors::TActorBootstrapped<TModificationAc
hFunc(NRequest::TEvRequestFailed, Handle);
hFunc(TEvRestoreProblem, Handle);
hFunc(TEvAlterPreparationProblem, Handle);
hFunc(TEvFetchDatabaseResponse, Handle);
default:
break;
}
Expand All @@ -126,6 +128,30 @@ class TModificationActorImpl: public NActors::TActorBootstrapped<TModificationAc
return TBase::PassAway();
}

if (!AppData()->FeatureFlags.GetEnableMetadataObjectsOnServerless() && Context.GetActivityType() != IOperationsManager::EActivityType::Drop) {
TBase::Register(CreateDatabaseFetcherActor(Context.GetExternalData().GetDatabase()));
} else {
CreateSession();
}
}

void Handle(TEvFetchDatabaseResponse::TPtr& ev) {
TString errorMessage;
if (const auto& errorString = ev->Get()->GetErrorString()) {
errorMessage = TStringBuilder() << "Cannot fetch database '" << Context.GetExternalData().GetDatabase() << "': " << *errorString;
} else if (ev->Get()->GetServerless()) {
errorMessage = TStringBuilder() << "Objects " << TObject::GetTypeId() << " are disabled for serverless domains. Please contact your system administrator to enable it";
}

if (errorMessage) {
auto g = TBase::PassAwayGuard();
ExternalController->OnAlteringProblem(errorMessage);
} else {
CreateSession();
}
}

void CreateSession() const {
TBase::Register(new NRequest::TYDBCallbackRequest<NRequest::TDialogCreateSession>(
NRequest::TDialogCreateSession::TRequest(), UserToken, TBase::SelfId()));
}
Expand Down
1 change: 1 addition & 0 deletions ydb/services/metadata/manager/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum EEvents {
EvAlterProblem,
EvAlterPreparationFinished,
EvAlterPreparationProblem,
EvFetchDatabaseResponse,
EvEnd
};
static_assert(EEvents::EvEnd < EventSpaceEnd(TKikimrEvents::ES_METADATA_MANAGER), "expect EvEnd < EventSpaceEnd(TKikimrEvents::ES_METADATA_MANAGER)");
Expand Down
Loading
Loading