aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorilnaz <ilnaz@ydb.tech>2022-09-19 17:18:18 +0300
committerilnaz <ilnaz@ydb.tech>2022-09-19 17:18:18 +0300
commitd69ea1ca9cf78805ffa76b93fd854c829355781a (patch)
tree98af23f246590167f66e3dfc192163174007c4d5
parent9605d5b8512fc5cde8e5a00cd42187b96bccbbdb (diff)
downloadydb-d69ea1ca9cf78805ffa76b93fd854c829355781a.tar.gz
Use TChecker to check limits
-rw-r--r--ydb/core/tx/schemeshard/schemeshard__operation_create_indexed_table.cpp27
-rw-r--r--ydb/core/tx/schemeshard/schemeshard__table_stats.cpp28
-rw-r--r--ydb/core/tx/schemeshard/ut_base.cpp93
3 files changed, 106 insertions, 42 deletions
diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_indexed_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_indexed_table.cpp
index a789376f988..b3cf6625016 100644
--- a/ydb/core/tx/schemeshard/schemeshard__operation_create_indexed_table.cpp
+++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_indexed_table.cpp
@@ -73,14 +73,6 @@ TVector<ISubOperationBase::TPtr> CreateIndexedTable(TOperationId nextId, const T
<< " GetShardsInside: " << domainInfo->GetShardsInside()
<< " MaxShards: " << domainInfo->GetSchemeLimits().MaxShards);
- if (domainInfo->GetShardsInside() + shardsToCreate > domainInfo->GetSchemeLimits().MaxShards) {
- auto msg = TStringBuilder() << "shards count has reached maximum value in the domain"
- << ", paths limit for domain: " << domainInfo->GetSchemeLimits().MaxShards
- << ", paths count inside domain: " << domainInfo->GetShardsInside()
- << ", intention to create new paths: " << shardsToCreate;
- return {CreateReject(nextId, NKikimrScheme::EStatus::StatusResourceExhausted, msg)};
- }
-
if (indexesCount > domainInfo->GetSchemeLimits().MaxTableIndices) {
auto msg = TStringBuilder() << "indexes count has reached maximum value in the table"
<< ", children limit for dir in domain: " << domainInfo->GetSchemeLimits().MaxTableIndices
@@ -88,18 +80,15 @@ TVector<ISubOperationBase::TPtr> CreateIndexedTable(TOperationId nextId, const T
return {CreateReject(nextId, NKikimrScheme::EStatus::StatusResourceExhausted, msg)};
}
- if (domainInfo->GetPathsInside() + pathToCreate > domainInfo->GetSchemeLimits().MaxPaths) {
- auto msg = TStringBuilder() << "paths count has reached maximum value in the domain"
- << ", paths limit for domain: " << domainInfo->GetSchemeLimits().MaxPaths
- << ", paths count inside domain: " << domainInfo->GetPathsInside()
- << ", intention to create new paths: " << pathToCreate;
- return {CreateReject(nextId, NKikimrScheme::EStatus::StatusResourceExhausted, msg)};
- }
+ auto checks = baseTablePath.Check();
+ checks
+ .PathShardsLimit(baseShards)
+ .PathsLimit(pathToCreate)
+ .ShardsLimit(shardsToCreate);
- if (baseShards > domainInfo->GetSchemeLimits().MaxShardsInPath) {
- auto msg = TStringBuilder() << "shards count has reached maximum value in the path"
- << ", shards limit for path: " << domainInfo->GetSchemeLimits().MaxShardsInPath
- << ", intention to create new shards: " << baseShards;
+ if (!checks) {
+ TString msg;
+ checks.GetStatus(&msg);
return {CreateReject(nextId, NKikimrScheme::EStatus::StatusResourceExhausted, msg)};
}
diff --git a/ydb/core/tx/schemeshard/schemeshard__table_stats.cpp b/ydb/core/tx/schemeshard/schemeshard__table_stats.cpp
index 446495fff7d..7f1449f0e32 100644
--- a/ydb/core/tx/schemeshard/schemeshard__table_stats.cpp
+++ b/ydb/core/tx/schemeshard/schemeshard__table_stats.cpp
@@ -383,29 +383,21 @@ bool TTxStorePartitionStats::PersistSingleStats(TTransactionContext& txc, const
}
{
- constexpr ui64 deltaShards = 2;
- TPathElement::TPtr path = Self->PathsById.at(pathId);
- TSubDomainInfo::TPtr domainInfo = Self->ResolveDomainInfo(pathId);
+ auto path = TPath::Init(pathId, Self);
+ auto checks = path.Check();
- if (domainInfo->GetShardsInside() + deltaShards > domainInfo->GetSchemeLimits().MaxShards) {
- LOG_NOTICE_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
- "Do not request full stats from datashard"
- << ", datashard: " << datashardId
- << ", reason: shards count has reached maximum value in the domain"
- << ", shards limit for domain: " << domainInfo->GetSchemeLimits().MaxShards
- << ", shards count inside domain: " << domainInfo->GetShardsInside()
- << ", intention to create new shards: " << deltaShards);
- return true;
- }
+ constexpr ui64 deltaShards = 2;
+ checks
+ .PathShardsLimit(deltaShards)
+ .ShardsLimit(deltaShards);
- if (path->GetShardsInside() + deltaShards > domainInfo->GetSchemeLimits().MaxShardsInPath) {
+ if (!checks) {
+ TString reason;
+ checks.GetStatus(&reason);
LOG_NOTICE_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
"Do not request full stats from datashard"
<< ", datashard: " << datashardId
- << ", reason: shards count has reached maximum value in the path"
- << ", shards limit for path: " << domainInfo->GetSchemeLimits().MaxShardsInPath
- << ", shards count inside path: " << path->GetShardsInside()
- << ", intention to create new shards: " << deltaShards);
+ << ", reason: " << reason);
return true;
}
}
diff --git a/ydb/core/tx/schemeshard/ut_base.cpp b/ydb/core/tx/schemeshard/ut_base.cpp
index dc4e61efc72..970fdf18808 100644
--- a/ydb/core/tx/schemeshard/ut_base.cpp
+++ b/ydb/core/tx/schemeshard/ut_base.cpp
@@ -3488,16 +3488,24 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {
TTestEnv env(runtime);
ui64 txId = 100;
- // used to sanity check at the end of the test
- THashSet<ui64> deletedShardIdxs;
+ bool splitStarted = false;
+ THashSet<ui64> deletedShardIdxs; // used to sanity check at the end of the test
+
runtime.SetObserverFunc([&](TTestActorRuntimeBase&, TAutoPtr<IEventHandle>& ev) {
- if (ev->GetTypeRewrite() == TEvHive::EvDeleteTabletReply) {
+ switch (ev->GetTypeRewrite()) {
+ case TEvHive::EvDeleteTabletReply:
for (const ui64 shardIdx : ev->Get<TEvHive::TEvDeleteTabletReply>()->Record.GetShardLocalIdx()) {
deletedShardIdxs.insert(shardIdx);
}
- }
+ return TTestActorRuntime::EEventAction::PROCESS;
- return TTestActorRuntime::EEventAction::PROCESS;
+ case TEvDataShard::EvGetTableStats:
+ splitStarted = true;
+ return TTestActorRuntime::EEventAction::DROP; // prevent splitting
+
+ default:
+ return TTestActorRuntime::EEventAction::PROCESS;
+ }
});
// these limits should have no effect on backup tables
@@ -3513,6 +3521,11 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {
Columns { Name: "key" Type: "Uint32"}
Columns { Name: "value" Type: "Utf8"}
KeyColumnNames: ["key"]
+ PartitionConfig {
+ PartitioningPolicy {
+ SizeToSplit: 100
+ }
+ }
)");
env.TestWaitNotification(runtime, txId);
@@ -3546,6 +3559,30 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {
NLs::IsBackupTable(true),
});
+ // write some data...
+ for (ui32 i = 0; i < 100; ++i) {
+ const auto query = Sprintf(R"(
+ (
+ (let key '('('key (Uint32 '%u)) ) )
+ (let value '('('value (Utf8 'foobar)) ) )
+ (return (AsList (UpdateRow '__user__Table key value) ))
+ )
+ )", i);
+ NKikimrMiniKQL::TResult result;
+ TString err;
+ const auto status = LocalMiniKQL(runtime, TTestTxConfig::FakeHiveTablets, query, result, err);
+ UNIT_ASSERT_VALUES_EQUAL(status, NKikimrProto::EReplyStatus::OK);
+ }
+
+ // ... and wait for the split to start
+ if (!splitStarted) {
+ TDispatchOptions opts;
+ opts.FinalEvents.emplace_back([&splitStarted](IEventHandle&) {
+ return splitStarted;
+ });
+ runtime.DispatchEvents(opts);
+ }
+
// negative tests
// shards limit
@@ -3688,6 +3725,52 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {
env.TestWaitNotification(runtime, txId);
}
+ Y_UNIT_TEST(CreateIndexedTableAfterBackup) {
+ TTestBasicRuntime runtime;
+ TTestEnv env(runtime);
+ ui64 txId = 100;
+
+ TSchemeLimits limits;
+ limits.MaxShards = 3; // for table + table + index
+ SetSchemeshardSchemaLimits(runtime, limits);
+
+ TestCreateTable(runtime, ++txId, "/MyRoot", R"(
+ Name: "Table"
+ Columns { Name: "key" Type: "Uint32"}
+ Columns { Name: "value" Type: "Utf8"}
+ KeyColumnNames: ["key"]
+ PartitionConfig {
+ PartitioningPolicy {
+ SizeToSplit: 100
+ }
+ }
+ )");
+ env.TestWaitNotification(runtime, txId);
+
+ for (int i = 1; i <= 2; ++i) {
+ TestCreateTable(runtime, ++txId, "/MyRoot", Sprintf(R"(
+ Name: "CopyTable%i"
+ CopyFromTable: "/MyRoot/Table"
+ IsBackup: true
+ )", i));
+ env.TestWaitNotification(runtime, txId);
+ }
+
+ TestCreateIndexedTable(runtime, ++txId, "/MyRoot", R"(
+ TableDescription {
+ Name: "Table2"
+ Columns { Name: "key" Type: "Uint32"}
+ Columns { Name: "value" Type: "Utf8"}
+ KeyColumnNames: ["key"]
+ }
+ IndexDescription {
+ Name: "UserDefinedIndexByValue"
+ KeyColumnNames: ["value"]
+ }
+ )");
+ env.TestWaitNotification(runtime, txId);
+ }
+
Y_UNIT_TEST(AlterTableAndConcurrentSplit) { //+
TTestBasicRuntime runtime;
TTestEnv env(runtime);