Skip to content

YQ-3597 disable metadata objects on serverless #8922

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
143 changes: 143 additions & 0 deletions ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <ydb/core/kqp/gateway/behaviour/resource_pool_classifier/fetcher.h>
#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 Expand Up @@ -6225,6 +6226,57 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
"Path does not exist");
}

Y_UNIT_TEST(DisableResourcePoolsOnServerless) {
auto ydb = NWorkload::TYdbSetupSettings()
.CreateSampleTenants(true)
.EnableResourcePoolsOnServerless(false)
.Create();

auto checkDisabled = [](const auto& result) {
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::GENERIC_ERROR, result.GetIssues().ToString());
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Resource pools are disabled for serverless domains. Please contact your system administrator to enable it");
};

auto checkNotFound = [](const auto& result) {
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::GENERIC_ERROR, result.GetIssues().ToString());
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Path does not exist");
};

const auto& createSql = R"(
CREATE RESOURCE POOL MyResourcePool WITH (
CONCURRENT_QUERY_LIMIT=20,
QUEUE_SIZE=1000
);)";

const auto& alterSql = R"(
ALTER RESOURCE POOL MyResourcePool
SET (CONCURRENT_QUERY_LIMIT = 30, QUEUE_SIZE = 100),
RESET (QUERY_MEMORY_LIMIT_PERCENT_PER_NODE);
)";

const auto& dropSql = "DROP RESOURCE POOL MyResourcePool;";

auto settings = NWorkload::TQueryRunnerSettings().PoolId("");

// Dedicated, enabled
settings.Database(ydb->GetSettings().GetDedicatedTenantName()).NodeIndex(1);
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(createSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(alterSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(dropSql, settings));

// Shared, enabled
settings.Database(ydb->GetSettings().GetSharedTenantName()).NodeIndex(2);
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(createSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(alterSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(dropSql, settings));

// Serverless, disabled
settings.Database(ydb->GetSettings().GetServerlessTenantName()).NodeIndex(2);
checkDisabled(ydb->ExecuteQuery(createSql, settings));
checkNotFound(ydb->ExecuteQuery(alterSql, settings));
checkNotFound(ydb->ExecuteQuery(dropSql, settings));
}

Y_UNIT_TEST(ResourcePoolsValidation) {
NKikimrConfig::TAppConfig config;
config.MutableFeatureFlags()->SetEnableResourcePools(true);
Expand Down Expand Up @@ -6494,6 +6546,57 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
"Classifier with name MyResourcePoolClassifier not found in database /Root");
}

Y_UNIT_TEST(DisableResourcePoolClassifiersOnServerless) {
auto ydb = NWorkload::TYdbSetupSettings()
.CreateSampleTenants(true)
.EnableResourcePoolsOnServerless(false)
.Create();

auto checkDisabled = [](const auto& result) {
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::GENERIC_ERROR, result.GetIssues().ToString());
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Resource pool classifiers are disabled for serverless domains. Please contact your system administrator to enable it");
};

auto checkNotFound = [](const auto& result) {
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::GENERIC_ERROR, result.GetIssues().ToString());
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Classifier with name MyResourcePoolClassifier not found in database");
};

const auto& createSql = R"(
CREATE RESOURCE POOL CLASSIFIER MyResourcePoolClassifier WITH (
RANK=20,
RESOURCE_POOL="test_pool"
);)";

const auto& alterSql = R"(
ALTER RESOURCE POOL CLASSIFIER MyResourcePoolClassifier
SET (RANK = 1, MEMBERNAME = "test@user"),
RESET (RESOURCE_POOL);
)";

const auto& dropSql = "DROP RESOURCE POOL CLASSIFIER MyResourcePoolClassifier;";

auto settings = NWorkload::TQueryRunnerSettings().PoolId("");

// Dedicated, enabled
settings.Database(ydb->GetSettings().GetDedicatedTenantName()).NodeIndex(1);
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(createSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(alterSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(dropSql, settings));

// Shared, enabled
settings.Database(ydb->GetSettings().GetSharedTenantName()).NodeIndex(2);
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(createSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(alterSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(dropSql, settings));

// Serverless, disabled
settings.Database(ydb->GetSettings().GetServerlessTenantName()).NodeIndex(2);
checkDisabled(ydb->ExecuteQuery(createSql, settings));
checkDisabled(ydb->ExecuteQuery(alterSql, settings));
checkNotFound(ydb->ExecuteQuery(dropSql, settings));
}

Y_UNIT_TEST(ResourcePoolClassifiersValidation) {
NKikimrConfig::TAppConfig config;
config.MutableFeatureFlags()->SetEnableResourcePools(true);
Expand Down Expand Up @@ -6782,6 +6885,46 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::GENERIC_ERROR, result.GetIssues().ToString());
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Classifier with name MyResourcePoolClassifier not found in database /Root");
}

Y_UNIT_TEST(DisableMetadataObjectsOnServerless) {
auto ydb = NWorkload::TYdbSetupSettings()
.CreateSampleTenants(true)
.EnableMetadataObjectsOnServerless(false)
.Create();

auto checkDisabled = [](const auto& result) {
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::GENERIC_ERROR, result.GetIssues().ToString());
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Objects SECRET are disabled for serverless domains. Please contact your system administrator to enable it");
};

const auto& createSql = "CREATE OBJECT MySecretObject (TYPE SECRET) WITH (value=\"qwerty\");";
const auto& alterSql = "ALTER OBJECT MySecretObject (TYPE SECRET) SET value = \"abcde\";";
const auto& upsertSql = "UPSERT OBJECT MySecretObject (TYPE SECRET) WITH value = \"edcba\";";
const auto& dropSql = "DROP OBJECT MySecretObject (TYPE SECRET);";

auto settings = NWorkload::TQueryRunnerSettings().PoolId("");

// Dedicated, enabled
settings.Database(ydb->GetSettings().GetDedicatedTenantName()).NodeIndex(1);
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(createSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(alterSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(upsertSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(dropSql, settings));

// Shared, enabled
settings.Database(ydb->GetSettings().GetSharedTenantName()).NodeIndex(2);
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(createSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(alterSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(upsertSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(dropSql, settings));

// Serverless, disabled
settings.Database(ydb->GetSettings().GetServerlessTenantName()).NodeIndex(2);
checkDisabled(ydb->ExecuteQuery(createSql, settings));
checkDisabled(ydb->ExecuteQuery(alterSql, settings));
checkDisabled(ydb->ExecuteQuery(upsertSql, settings));
NWorkload::TSampleQueries::CheckSuccess(ydb->ExecuteQuery(dropSql, settings));
}
}

Y_UNIT_TEST_SUITE(KqpOlapScheme) {
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,6 +230,8 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
TAppConfig GetAppConfig() const {
TAppConfig appConfig;
appConfig.MutableFeatureFlags()->SetEnableResourcePools(Settings_.EnableResourcePools_);
appConfig.MutableFeatureFlags()->SetEnableResourcePoolsOnServerless(Settings_.EnableResourcePoolsOnServerless_);
appConfig.MutableFeatureFlags()->SetEnableMetadataObjectsOnServerless(Settings_.EnableMetadataObjectsOnServerless_);
appConfig.MutableFeatureFlags()->SetEnableResourcePoolsCounters(true);

return appConfig;
Expand All @@ -238,7 +240,7 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
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 @@ -255,16 +257,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 @@ -277,10 +313,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 @@ -483,7 +524,7 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
request->SetQuery(query);
request->SetType(NKikimrKqp::QUERY_TYPE_SQL_GENERIC_QUERY);
request->SetAction(NKikimrKqp::QUERY_ACTION_EXECUTE);
request->SetDatabase(Settings_.DomainName_);
request->SetDatabase(settings.Database_ ? settings.Database_ : Settings_.DomainName_);
request->SetPoolId(*settings.PoolId_);

return event;
Expand Down Expand Up @@ -525,9 +566,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 @@ -586,6 +628,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(std::optional<TString>, PoolId, std::nullopt);
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,10 @@ 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, EnableResourcePoolsOnServerless, false);
FLUENT_SETTING_DEFAULT(bool, EnableMetadataObjectsOnServerless, true);

// Default pool settings
FLUENT_SETTING_DEFAULT(TString, PoolId, "sample_pool_id");
Expand All @@ -78,6 +82,10 @@ struct TYdbSetupSettings {

NResourcePool::TPoolSettings GetDefaultPoolSettings() const;
TIntrusivePtr<IYdbSetup> Create() const;

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

class IYdbSetup : public TThrRefBase {
Expand Down Expand Up @@ -127,6 +135,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
Loading
Loading