Skip to content
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

Implemented limit on olap table columnt count #8742

Merged
merged 7 commits into from
Sep 9, 2024
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
2 changes: 2 additions & 0 deletions ydb/core/protos/flat_tx_scheme.proto
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ message TSchemeLimits {

optional uint64 MaxExports = 16;
optional uint64 MaxImports = 17;

optional uint64 MaxColumnTableColumns = 18;
}

message TEvInitTenantSchemeShard {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ NKikimr::TConclusionStatus TStandaloneSchemaUpdate::DoInitializeImpl(const TUpda
return TConclusionStatus::Fail("schema update error: " + collector->GetErrorMessage() + ". in alter constructor STANDALONE_UPDATE");
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно не только для standalone, но и для in_store

const TString& parentPathStr = context.GetModification()->GetWorkingDir();
if (parentPathStr) { // Not empty only if called from Propose, not from ProgressState
NSchemeShard::TPath parentPath = NSchemeShard::TPath::Resolve(parentPathStr, context.GetSSOperationContext()->SS);
auto domainInfo = parentPath.DomainInfo();
const TSchemeLimits& limits = domainInfo->GetSchemeLimits();
if (targetSchema.GetColumns().GetColumns().size() > limits.MaxColumnTableColumns) {
TString errStr = TStringBuilder()
<< "Too many columns"
<< ": new: " << targetSchema.GetColumns().GetColumns().size()
<< ". Limit: " << limits.MaxColumnTableColumns;
return TConclusionStatus::Fail(errStr);
}
}

auto description = originalTable.GetTableInfoVerified().Description;
targetSchema.Serialize(*description.MutableSchema());
auto ttl = originalTable.GetTableTTLOptional() ? *originalTable.GetTableTTLOptional() : TOlapTTL();
Expand Down
14 changes: 13 additions & 1 deletion ydb/core/tx/schemeshard/olap/operations/alter_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <ydb/core/tx/schemeshard/schemeshard__operation_common.h>
#include <ydb/core/tx/schemeshard/schemeshard_impl.h>

#include "checks.h"

namespace {

using namespace NKikimr;
Expand Down Expand Up @@ -458,7 +460,8 @@ class TAlterOlapStore: public TSubOperation {
return result;
}

TPath path = TPath::Resolve(parentPathStr, context.SS).Dive(name);
TPath parentPath = TPath::Resolve(parentPathStr, context.SS);
TPath path = parentPath.Dive(name);
{
TPath::TChecker checks = path.Check();
checks
Expand Down Expand Up @@ -504,6 +507,15 @@ class TAlterOlapStore: public TSubOperation {
if (!alterData) {
return result;
}

auto domainInfo = parentPath.DomainInfo();
const TSchemeLimits& limits = domainInfo->GetSchemeLimits();

if (!NKikimr::NSchemeShard::NOlap::CheckLimits(limits, alterData, errStr)) {
result->SetError(NKikimrScheme::StatusSchemeError, errStr);
return result;
}

storeInfo->AlterData = alterData;

NIceDb::TNiceDb db(context.GetDB());
Expand Down
19 changes: 19 additions & 0 deletions ydb/core/tx/schemeshard/olap/operations/checks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

namespace NKikimr::NSchemeShard::NOlap {
inline bool CheckLimits(const TSchemeLimits& limits, TOlapStoreInfo::TPtr alterData, TString& errStr) {
for (auto& [_, preset]: alterData->SchemaPresets) {
ui64 columnCount = preset.GetColumns().GetColumns().size();
if (columnCount > limits.MaxColumnTableColumns) {
errStr = TStringBuilder()
<< "Too many columns"
<< ". new: " << columnCount
<< ". Limit: " << limits.MaxColumnTableColumns;
return false;
}
}
return true;
}
}


10 changes: 10 additions & 0 deletions ydb/core/tx/schemeshard/olap/operations/create_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <ydb/core/tx/columnshard/columnshard.h>
#include <ydb/core/mind/hive/hive.h>

#include "checks.h"

using namespace NKikimr;
using namespace NKikimr::NSchemeShard;

Expand Down Expand Up @@ -394,12 +396,20 @@ class TCreateOlapStore: public TSubOperation {
return result;
}

auto domainInfo = parentPath.DomainInfo();
const TSchemeLimits& limits = domainInfo->GetSchemeLimits();

TProposeErrorCollector errors(*result);
TOlapStoreInfo::TPtr storeInfo = std::make_shared<TOlapStoreInfo>();
if (!storeInfo->ParseFromRequest(createDescription, errors)) {
return result;
}

if (!NKikimr::NSchemeShard::NOlap::CheckLimits(limits, storeInfo, errStr)) {
result->SetError(NKikimrScheme::StatusSchemeError, errStr);
return result;
}

// Construct channels bindings for columnshards
TChannelsBindings channelsBindings;
if (!context.SS->GetOlapChannelsBindings(dstPath.GetPathIdForDomain(), storeInfo->GetStorageConfig(), channelsBindings, errStr)) {
Expand Down
12 changes: 12 additions & 0 deletions ydb/core/tx/schemeshard/olap/operations/create_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,23 @@ class TCreateColumnTable: public TSubOperation {
TProposeErrorCollector errors(*result);
TColumnTableInfo::TPtr tableInfo;
bool needUpdateObject = false;
auto domainInfo = parentPath.DomainInfo();
const TSchemeLimits& limits = domainInfo->GetSchemeLimits();

if (storeInfo) {
TOlapPresetConstructor tableConstructor(*storeInfo);
tableInfo = tableConstructor.BuildTableInfo(createDescription, context, errors);
needUpdateObject = tableConstructor.GetNeedUpdateObject();
} else {
ui64 columnCount = createDescription.schema().columns().size();
if (columnCount > limits.MaxColumnTableColumns) {
TString errStr = TStringBuilder()
<< "Too many columns"
<< ". new: " << columnCount
<< ". Limit: " << limits.MaxColumnTableColumns;
result->SetError(NKikimrScheme::StatusSchemeError, errStr);
return result;
}
TOlapTableConstructor tableConstructor;
tableInfo = tableConstructor.BuildTableInfo(createDescription, context, errors);
}
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/schemeshard/schemeshard__init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
.MaxPathElementLength = rowSet.template GetValueOrDefault<Schema::SubDomains::PathElementLength>(defaults.MaxPathElementLength),
.ExtraPathSymbolsAllowed = rowSet.template GetValueOrDefault<Schema::SubDomains::ExtraPathSymbolsAllowed>(defaults.ExtraPathSymbolsAllowed),
.MaxTableColumns = rowSet.template GetValueOrDefault<Schema::SubDomains::TableColumnsLimit>(defaults.MaxTableColumns),
.MaxColumnTableColumns = rowSet.template GetValueOrDefault<Schema::SubDomains::ColumnTableColumnsLimit>(defaults.MaxColumnTableColumns),
.MaxTableColumnNameLength = rowSet.template GetValueOrDefault<Schema::SubDomains::TableColumnNameLengthLimit>(defaults.MaxTableColumnNameLength),
.MaxTableKeyColumns = rowSet.template GetValueOrDefault<Schema::SubDomains::TableKeyColumnsLimit>(defaults.MaxTableKeyColumns),
.MaxTableIndices = rowSet.template GetValueOrDefault<Schema::SubDomains::TableIndicesLimit>(defaults.MaxTableIndices),
Expand Down
4 changes: 3 additions & 1 deletion ydb/core/tx/schemeshard/schemeshard_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ struct Schema : NIceDb::Schema {
struct ImportsLimit : Column<29, NScheme::NTypeIds::Uint64> {};
struct AuditSettings : Column<30, NScheme::NTypeIds::String> {};
struct ServerlessComputeResourcesMode : Column<31, NScheme::NTypeIds::Uint32> { using Type = EServerlessComputeResourcesMode; };
struct ColumnTableColumnsLimit : Column<32, NScheme::NTypeIds::Uint64> {};

using TKey = TableKey<PathId>;
using TColumns = TableColumns<
Expand Down Expand Up @@ -801,7 +802,8 @@ struct Schema : NIceDb::Schema {
ExportsLimit,
ImportsLimit,
AuditSettings,
ServerlessComputeResourcesMode
ServerlessComputeResourcesMode,
ColumnTableColumnsLimit
>;
};

Expand Down
4 changes: 4 additions & 0 deletions ydb/core/tx/schemeshard/schemeshard_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ TSchemeLimits TSchemeLimits::FromProto(const NKikimrScheme::TSchemeLimits& proto
if (proto.HasMaxTableColumns()) {
result.MaxTableColumns = proto.GetMaxTableColumns();
}
if (proto.HasMaxColumnTableColumns()) {
result.MaxColumnTableColumns = proto.GetMaxColumnTableColumns();
}
if (proto.HasMaxTableColumnNameLength()) {
result.MaxTableColumnNameLength = proto.GetMaxTableColumnNameLength();
}
Expand Down Expand Up @@ -69,6 +72,7 @@ NKikimrScheme::TSchemeLimits TSchemeLimits::AsProto() const {
result.SetMaxAclBytesSize(MaxAclBytesSize);

result.SetMaxTableColumns(MaxTableColumns);
result.SetMaxColumnTableColumns(MaxColumnTableColumns);
result.SetMaxTableColumnNameLength(MaxTableColumnNameLength);
result.SetMaxTableKeyColumns(MaxTableKeyColumns);
result.SetMaxTableIndices(MaxTableIndices);
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/schemeshard/schemeshard_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct TSchemeLimits {

// table
ui64 MaxTableColumns = 200;
ui64 MaxColumnTableColumns = 10000;
ui64 MaxTableColumnNameLength = 255;
ui64 MaxTableKeyColumns = 20;
ui64 MaxTableIndices = 20;
Expand Down
5 changes: 3 additions & 2 deletions ydb/core/tx/schemeshard/ut_helpers/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,7 @@ namespace NSchemeShardUT_Private {
(let child '('ChildrenLimit (Uint64 '%lu)))
(let acl '('AclByteSizeLimit (Uint64 '%lu)))
(let columns '('TableColumnsLimit (Uint64 '%lu)))
(let columnColumns '('ColumnTableColumnsLimit (Uint64 '%lu)))
(let colName '('TableColumnNameLengthLimit (Uint64 '%lu)))
(let keyCols '('TableKeyColumnsLimit (Uint64 '%lu)))
(let indices '('TableIndicesLimit (Uint64 '%lu)))
Expand All @@ -1518,11 +1519,11 @@ namespace NSchemeShardUT_Private {
(let pqPartitions '('PQPartitionsLimit (Uint64 '%lu)))
(let exports '('ExportsLimit (Uint64 '%lu)))
(let imports '('ImportsLimit (Uint64 '%lu)))
(let ret (AsList (UpdateRow 'SubDomains key '(depth paths child acl columns colName keyCols indices streams shards pathShards consCopy maxPathLength extraSymbols pqPartitions exports imports))))
(let ret (AsList (UpdateRow 'SubDomains key '(depth paths child acl columns columnColumns colName keyCols indices streams shards pathShards consCopy maxPathLength extraSymbols pqPartitions exports imports))))
(return ret)
)
)", domainId, limits.MaxDepth, limits.MaxPaths, limits.MaxChildrenInDir, limits.MaxAclBytesSize,
limits.MaxTableColumns, limits.MaxTableColumnNameLength, limits.MaxTableKeyColumns,
limits.MaxTableColumns, limits.MaxColumnTableColumns, limits.MaxTableColumnNameLength, limits.MaxTableKeyColumns,
limits.MaxTableIndices, limits.MaxTableCdcStreams,
limits.MaxShards, limits.MaxShardsInPath, limits.MaxConsistentCopyTargets,
limits.MaxPathElementLength, escapedStr.c_str(), limits.MaxPQPartitions,
Expand Down
150 changes: 150 additions & 0 deletions ydb/core/tx/schemeshard/ut_subdomain/ut_subdomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardSubDomainTest) {

}


//clear subdomain
{
TestDescribeResult(DescribePath(runtime, "/MyRoot"),
Expand All @@ -2585,6 +2586,155 @@ Y_UNIT_TEST_SUITE(TSchemeShardSubDomainTest) {
}
}

Y_UNIT_TEST(ColumnSchemeLimitsRejects) {
TTestBasicRuntime runtime;
TTestEnv env(runtime);
ui64 txId = 100;

TSchemeLimits lowLimits;
lowLimits.MaxDepth = 4;
lowLimits.MaxPaths = 3;
lowLimits.MaxChildrenInDir = 3;
lowLimits.MaxAclBytesSize = 25;
lowLimits.MaxTableColumns = 3;
lowLimits.MaxColumnTableColumns = 3;
lowLimits.MaxTableColumnNameLength = 10;
lowLimits.MaxTableKeyColumns = 1;
lowLimits.MaxShards = 6;
lowLimits.MaxShardsInPath = 4;
lowLimits.MaxPQPartitions = 20;


//lowLimits.ExtraPathSymbolsAllowed = "!\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~";
SetSchemeshardSchemaLimits(runtime, lowLimits);
TestDescribeResult(DescribePath(runtime, "/MyRoot"),
{NLs::PathExist,
NLs::DomainLimitsIs(lowLimits.MaxPaths, lowLimits.MaxShards, lowLimits.MaxPQPartitions)});

{
TestCreateSubDomain(runtime, txId++, "/MyRoot",
"PlanResolution: 50 "
"Coordinators: 1 "
"Mediators: 1 "
"TimeCastBucketsPerMediator: 2 "
"Name: \"USER_0\""
" DatabaseQuotas {"
" data_stream_shards_quota: 2"
" data_stream_reserved_storage_quota: 200000"
"}");
}

//create column tables, column limits
{
TestMkDir(runtime, txId++, "/MyRoot/USER_0", "C");
env.TestWaitNotification(runtime, txId - 1);

// MaxColumnTableColumns
TestCreateColumnTable(runtime, txId++, "/MyRoot/USER_0/C", R"(
Name: "C2"
ColumnShardCount: 1
Schema {
Columns { Name: "RowId" Type: "Uint64", NotNull: true }
Columns { Name: "Value0" Type: "Utf8" }
Columns { Name: "Value1" Type: "Utf8" }
KeyColumnNames: "RowId"
Engine: COLUMN_ENGINE_REPLACING_TIMESERIES
}
)", {NKikimrScheme::StatusAccepted});
env.TestWaitNotification(runtime, txId - 1);

TestAlterColumnTable(runtime, txId++, "/MyRoot/USER_0/C", R"(
Name: "C2"
AlterSchema {
DropColumns {Name: "Value0"}
}
)", {NKikimrScheme::StatusAccepted});
env.TestWaitNotification(runtime, txId - 1);

TestAlterColumnTable(runtime, txId++, "/MyRoot/USER_0/C", R"(
Name: "C2"
AlterSchema {
DropColumns {Name: "Value1"}
AddColumns { Name: "Value2" Type: "Utf8" }
AddColumns { Name: "Value3" Type: "Utf8" }
AddColumns { Name: "Value4" Type: "Utf8" }
}
)", {NKikimrScheme::StatusSchemeError});
env.TestWaitNotification(runtime, txId - 1);

TestCreateColumnTable(runtime, txId++, "/MyRoot/USER_0/C", R"(
Name: "C1"
ColumnShardCount: 1
Schema {
Columns { Name: "RowId" Type: "Uint64", NotNull: true }
Columns { Name: "Value0" Type: "Utf8" }
Columns { Name: "Value1" Type: "Utf8" }
Columns { Name: "Value2" Type: "Utf8" }
KeyColumnNames: "RowId"
Engine: COLUMN_ENGINE_REPLACING_TIMESERIES
}
)", {NKikimrScheme::StatusSchemeError});

TString olapSchema = R"(
Name: "OlapStore1"
ColumnShardCount: 1
SchemaPresets {
Name: "default"
Schema {
Columns { Name: "timestamp" Type: "Timestamp" NotNull: true }
Columns { Name: "data" Type: "Utf8" }
KeyColumnNames: "timestamp"
Engine: COLUMN_ENGINE_REPLACING_TIMESERIES
}
}
)";

TestCreateOlapStore(runtime, txId++, "/MyRoot", olapSchema, {NKikimrScheme::StatusAccepted});
env.TestWaitNotification(runtime, txId - 1);

TString olapSchemaBig = R"(
Name: "OlapStoreBig"
ColumnShardCount: 1
SchemaPresets {
Name: "default"
Schema {
Columns { Name: "timestamp" Type: "Timestamp" NotNull: true }
Columns { Name: "data" Type: "Utf8" }
Columns { Name: "data2" Type: "Utf8" }
Columns { Name: "data3" Type: "Utf8" }
KeyColumnNames: "timestamp"
Engine: COLUMN_ENGINE_REPLACING_TIMESERIES
}
}
)";

TestCreateOlapStore(runtime, txId++, "/MyRoot", olapSchemaBig, {NKikimrScheme::StatusSchemeError});
env.TestWaitNotification(runtime, txId - 1);

TestAlterOlapStore(runtime, txId++, "/MyRoot", R"(
Name: "OlapStore1"
AlterSchemaPresets {
Name: "default"
AlterSchema {
AddColumns { Name: "comment" Type: "Utf8" }
}
}
)", {NKikimrScheme::StatusAccepted});
env.TestWaitNotification(runtime, txId - 1);

TestAlterOlapStore(runtime, txId++, "/MyRoot", R"(
Name: "OlapStore1"
AlterSchemaPresets {
Name: "default"
AlterSchema {
AddColumns { Name: "comment2" Type: "Utf8" }
}
}
)", {NKikimrScheme::StatusSchemeError});
env.TestWaitNotification(runtime, txId - 1);
}
}

Y_UNIT_TEST(SchemeLimitsRejectsWithIndexedTables) {
TTestBasicRuntime runtime;
TTestEnv env(runtime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,11 @@
"ColumnId": 31,
"ColumnName": "ServerlessComputeResourcesMode",
"ColumnType": "Uint32"
},
{
"ColumnId": 32,
"ColumnName": "ColumnTableColumnsLimit",
"ColumnType": "Uint64"
}
],
"ColumnsDropped": [],
Expand Down Expand Up @@ -1490,7 +1495,8 @@
28,
29,
30,
31
31,
32
],
"RoomID": 0,
"Codec": 0,
Expand Down
Loading