Skip to content

Commit dbba599

Browse files
committed
YQ-3644 added validations for resource pool parametres (#8831)
1 parent 67ff852 commit dbba599

13 files changed

+79
-10
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6316,6 +6316,20 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
63166316
);)").GetValueSync();
63176317
UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::GENERIC_ERROR);
63186318
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Failed to parse property concurrent_query_limit:");
6319+
6320+
result = session.ExecuteSchemeQuery(TStringBuilder() << R"(
6321+
CREATE RESOURCE POOL MyResourcePool WITH (
6322+
CONCURRENT_QUERY_LIMIT=)" << NResourcePool::POOL_MAX_CONCURRENT_QUERY_LIMIT + 1 << R"(
6323+
);)").GetValueSync();
6324+
UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::SCHEME_ERROR);
6325+
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), TStringBuilder() << "Invalid resource pool configuration, concurrent_query_limit is " << NResourcePool::POOL_MAX_CONCURRENT_QUERY_LIMIT + 1 << ", that exceeds limit in " << NResourcePool::POOL_MAX_CONCURRENT_QUERY_LIMIT);
6326+
6327+
result = session.ExecuteSchemeQuery(R"(
6328+
CREATE RESOURCE POOL MyResourcePool WITH (
6329+
QUEUE_SIZE=1
6330+
);)").GetValueSync();
6331+
UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::SCHEME_ERROR);
6332+
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Invalid resource pool configuration, queue_size unsupported without concurrent_query_limit or database_load_cpu_threshold");
63196333
}
63206334

63216335
Y_UNIT_TEST(CreateResourcePool) {

ydb/core/kqp/workload_service/common/helpers.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ NYql::TIssues GroupIssues(const NYql::TIssues& issues, const TString& message) {
1212
}
1313

1414
void ParsePoolSettings(const NKikimrSchemeOp::TResourcePoolDescription& description, NResourcePool::TPoolSettings& poolConfig) {
15-
const auto& properties = description.GetProperties().GetProperties();
16-
for (auto& [property, value] : poolConfig.GetPropertiesMap()) {
17-
if (auto propertyIt = properties.find(property); propertyIt != properties.end()) {
18-
std::visit(NResourcePool::TPoolSettings::TParser{propertyIt->second}, value);
19-
}
20-
}
15+
poolConfig = NResourcePool::TPoolSettings(description.GetProperties().GetProperties());
2116
}
2217

2318
ui64 SaturationSub(ui64 x, ui64 y) {

ydb/core/kqp/workload_service/ut/kqp_workload_service_actors_ut.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Y_UNIT_TEST_SUITE(KqpWorkloadServiceActors) {
132132
// Check alter access
133133
TSampleQueries::CheckSuccess(ydb->ExecuteQuery(TStringBuilder() << R"(
134134
ALTER RESOURCE POOL )" << NResourcePool::DEFAULT_POOL_ID << R"( SET (
135-
QUEUE_SIZE=1
135+
QUERY_MEMORY_LIMIT_PERCENT_PER_NODE=1
136136
);
137137
)", settings));
138138

@@ -205,7 +205,7 @@ Y_UNIT_TEST_SUITE(KqpWorkloadServiceSubscriptions) {
205205

206206
ydb->ExecuteSchemeQuery(TStringBuilder() << R"(
207207
ALTER RESOURCE POOL )" << ydb->GetSettings().PoolId_ << R"( SET (
208-
QUEUE_SIZE=42
208+
CONCURRENT_QUERY_LIMIT=42
209209
);
210210
)");
211211

@@ -214,7 +214,7 @@ Y_UNIT_TEST_SUITE(KqpWorkloadServiceSubscriptions) {
214214

215215
const auto& config = response->Get()->Config;
216216
UNIT_ASSERT_C(config, "Pool config not found");
217-
UNIT_ASSERT_VALUES_EQUAL(config->QueueSize, 42);
217+
UNIT_ASSERT_VALUES_EQUAL(config->ConcurrentQueryLimit, 42);
218218
}
219219

220220
Y_UNIT_TEST(TestResourcePoolSubscriptionAfterAclChange) {

ydb/core/kqp/workload_service/ut/kqp_workload_service_tables_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Y_UNIT_TEST_SUITE(KqpWorkloadServiceTables) {
7676
Y_UNIT_TEST(TestTablesIsNotCreatingForUnlimitedPool) {
7777
auto ydb = TYdbSetupSettings()
7878
.ConcurrentQueryLimit(-1)
79-
.QueueSize(10)
79+
.QueryMemoryLimitPercentPerNode(50)
8080
.Create();
8181

8282
TSampleQueries::TSelect42::CheckResult(ydb->ExecuteQuery(TSampleQueries::TSelect42::Query));

ydb/core/resource_pools/resource_pool_settings.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ TString TPoolSettings::TExtractor::operator()(TDuration* setting) const {
4343

4444
//// TPoolSettings
4545

46+
TPoolSettings::TPoolSettings(const google::protobuf::Map<TString, TString>& properties) {
47+
for (auto& [property, value] : GetPropertiesMap()) {
48+
if (auto propertyIt = properties.find(property); propertyIt != properties.end()) {
49+
std::visit(TPoolSettings::TParser{propertyIt->second}, value);
50+
}
51+
}
52+
}
53+
4654
std::unordered_map<TString, TPoolSettings::TProperty> TPoolSettings::GetPropertiesMap(bool restricted) {
4755
std::unordered_map<TString, TProperty> properties = {
4856
{"concurrent_query_limit", &ConcurrentQueryLimit},
@@ -56,4 +64,13 @@ std::unordered_map<TString, TPoolSettings::TProperty> TPoolSettings::GetProperti
5664
return properties;
5765
}
5866

67+
void TPoolSettings::Validate() const {
68+
if (ConcurrentQueryLimit > POOL_MAX_CONCURRENT_QUERY_LIMIT) {
69+
throw yexception() << "Invalid resource pool configuration, concurrent_query_limit is " << ConcurrentQueryLimit << ", that exceeds limit in " << POOL_MAX_CONCURRENT_QUERY_LIMIT;
70+
}
71+
if (QueueSize != -1 && ConcurrentQueryLimit == -1 && DatabaseLoadCpuThreshold < 0.0) {
72+
throw yexception() << "Invalid resource pool configuration, queue_size unsupported without concurrent_query_limit or database_load_cpu_threshold";
73+
}
74+
}
75+
5976
} // namespace NKikimr::NResourcePool

ydb/core/resource_pools/resource_pool_settings.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
#include "settings_common.h"
44

5+
#include <contrib/libs/protobuf/src/google/protobuf/map.h>
6+
57
#include <util/datetime/base.h>
68

79

810
namespace NKikimr::NResourcePool {
911

1012
inline constexpr char DEFAULT_POOL_ID[] = "default";
1113

14+
inline constexpr i64 POOL_MAX_CONCURRENT_QUERY_LIMIT = 1000;
15+
1216
struct TPoolSettings : public TSettingsBase {
1317
typedef double TPercent;
1418

@@ -27,8 +31,13 @@ struct TPoolSettings : public TSettingsBase {
2731
TString operator()(TDuration* setting) const;
2832
};
2933

34+
TPoolSettings() = default;
35+
TPoolSettings(const google::protobuf::Map<TString, TString>& properties);
36+
3037
bool operator==(const TPoolSettings& other) const = default;
38+
3139
std::unordered_map<TString, TProperty> GetPropertiesMap(bool restricted = false);
40+
void Validate() const;
3241

3342
i32 ConcurrentQueryLimit = -1; // -1 = disabled
3443
i32 QueueSize = -1; // -1 = disabled

ydb/core/resource_pools/resource_pool_settings_ut.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ Y_UNIT_TEST_SUITE(ResourcePoolTest) {
7373
UNIT_ASSERT_VALUES_EQUAL(std::visit(extractor, propertiesMap["query_cancel_after_seconds"]), "15");
7474
UNIT_ASSERT_VALUES_EQUAL(std::visit(extractor, propertiesMap["query_memory_limit_percent_per_node"]), "0.5");
7575
}
76+
77+
Y_UNIT_TEST(SettingsValidation) {
78+
{ // Max concurrent query limit validation
79+
TPoolSettings settings;
80+
settings.ConcurrentQueryLimit = POOL_MAX_CONCURRENT_QUERY_LIMIT + 1;
81+
UNIT_ASSERT_EXCEPTION_CONTAINS(settings.Validate(), yexception, TStringBuilder() << "Invalid resource pool configuration, concurrent_query_limit is " << settings.ConcurrentQueryLimit << ", that exceeds limit in " << POOL_MAX_CONCURRENT_QUERY_LIMIT);
82+
}
83+
84+
{ // Unused queue size validation
85+
86+
TPoolSettings settings;
87+
settings.QueueSize = 1;
88+
UNIT_ASSERT_EXCEPTION_CONTAINS(settings.Validate(), yexception, TStringBuilder() << "Invalid resource pool configuration, queue_size unsupported without concurrent_query_limit or database_load_cpu_threshold");
89+
}
90+
}
7691
}
7792

7893
} // namespace NKikimr

ydb/core/resource_pools/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ SRCS(
66
)
77

88
PEERDIR(
9+
contrib/libs/protobuf
910
util
1011
)
1112

ydb/core/tx/schemeshard/schemeshard__operation_alter_resource_pool.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class TAlterResourcePool : public TSubOperation {
149149
Y_ABORT_UNLESS(oldResourcePoolInfo);
150150
const TResourcePoolInfo::TPtr resourcePoolInfo = NResourcePool::ModifyResourcePool(resourcePoolDescription, oldResourcePoolInfo);
151151
Y_ABORT_UNLESS(resourcePoolInfo);
152+
RETURN_RESULT_UNLESS(NResourcePool::IsResourcePoolInfoValid(result, resourcePoolInfo));
152153

153154
result->SetPathId(dstPath.Base()->PathId.LocalPathId);
154155
const TPathElement::TPtr resourcePool = ReplaceResourcePoolPathElement(dstPath);

ydb/core/tx/schemeshard/schemeshard__operation_common_resource_pool.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "schemeshard__operation_common_resource_pool.h"
22
#include "schemeshard_impl.h"
33

4+
#include <ydb/core/resource_pools/resource_pool_settings.h>
5+
46

57
namespace NKikimr::NSchemeShard::NResourcePool {
68

@@ -90,6 +92,17 @@ bool IsDescriptionValid(const THolder<TProposeResponse>& result, const NKikimrSc
9092
return true;
9193
}
9294

95+
bool IsResourcePoolInfoValid(const THolder<TProposeResponse>& result, const TResourcePoolInfo::TPtr& info) {
96+
try {
97+
NKikimr::NResourcePool::TPoolSettings settings(info->Properties.GetProperties());
98+
settings.Validate();
99+
} catch (...) {
100+
result->SetError(NKikimrScheme::StatusSchemeError, CurrentExceptionMessage());
101+
return false;
102+
}
103+
return true;
104+
}
105+
93106
TTxState& CreateTransaction(const TOperationId& operationId, const TOperationContext& context, const TPathId& resourcePoolPathId, TTxState::ETxType txType) {
94107
Y_ABORT_UNLESS(!context.SS->FindTx(operationId));
95108
TTxState& txState = context.SS->CreateTx(operationId, txType, resourcePoolPathId);

ydb/core/tx/schemeshard/schemeshard__operation_common_resource_pool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ bool IsApplyIfChecksPassed(const TTxTransaction& transaction, const THolder<TPro
2424

2525
bool IsDescriptionValid(const THolder<TProposeResponse>& result, const NKikimrSchemeOp::TResourcePoolDescription& description);
2626

27+
bool IsResourcePoolInfoValid(const THolder<TProposeResponse>& result, const TResourcePoolInfo::TPtr& info);
28+
2729
TTxState& CreateTransaction(const TOperationId& operationId, const TOperationContext& context, const TPathId& resourcePoolPathId, TTxState::ETxType txType);
2830

2931
void RegisterParentPathDependencies(const TOperationId& operationId, const TOperationContext& context, const TPath& parentPath);

ydb/core/tx/schemeshard/schemeshard__operation_create_resource_pool.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class TCreateResourcePool : public TSubOperation {
173173

174174
const TResourcePoolInfo::TPtr resourcePoolInfo = NResourcePool::CreateResourcePool(resourcePoolDescription, 1);
175175
Y_ABORT_UNLESS(resourcePoolInfo);
176+
RETURN_RESULT_UNLESS(NResourcePool::IsResourcePoolInfoValid(result, resourcePoolInfo));
176177

177178
AddPathInSchemeShard(result, dstPath, owner);
178179
const TPathElement::TPtr resourcePool = CreateResourcePoolPathElement(dstPath);

ydb/core/tx/schemeshard/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ PEERDIR(
262262
ydb/core/persqueue/events
263263
ydb/core/persqueue/writer
264264
ydb/core/protos
265+
ydb/core/resource_pools
265266
ydb/core/scheme
266267
ydb/core/statistics
267268
ydb/core/sys_view/partition_stats

0 commit comments

Comments
 (0)