diff options
| author | Andrey Zaspa <[email protected]> | 2025-06-23 11:12:34 +0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-23 11:12:34 +0400 |
| commit | 0046f6ce4aa2b08eaee791816a73b16ac733a9c6 (patch) | |
| tree | 9ad75f0e2f7c3a334110fd2d0251cffca48e3f9f | |
| parent | 7e2446459dcce6056d6c31a781b1dabf215727da (diff) | |
Made SchemeShard tests robust to changing of PathIds (#19992)
11 files changed, 198 insertions, 73 deletions
diff --git a/ydb/core/tx/schemeshard/ut_cdc_stream/ut_cdc_stream.cpp b/ydb/core/tx/schemeshard/ut_cdc_stream/ut_cdc_stream.cpp index 1fbedaf6a9c..dabedc8cd2e 100644 --- a/ydb/core/tx/schemeshard/ut_cdc_stream/ut_cdc_stream.cpp +++ b/ydb/core/tx/schemeshard/ut_cdc_stream/ut_cdc_stream.cpp @@ -1083,6 +1083,9 @@ Y_UNIT_TEST_SUITE(TCdcStreamTests) { )"); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/Shared"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( Name: "Shared" StoragePools { @@ -1107,9 +1110,9 @@ Y_UNIT_TEST_SUITE(TCdcStreamTests) { Name: "Serverless" ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } - )", TTestTxConfig::SchemeShard)); + )", TTestTxConfig::SchemeShard, subDomainPathId)); env.TestWaitNotification(runtime, txId); TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( @@ -1928,6 +1931,9 @@ Y_UNIT_TEST_SUITE(TCdcStreamWithInitialScanTests) { )"); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/Shared"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( Name: "Shared" StoragePools { @@ -1958,9 +1964,9 @@ Y_UNIT_TEST_SUITE(TCdcStreamWithInitialScanTests) { Name: "Serverless" ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } - )", TTestTxConfig::SchemeShard), attrs); + )", TTestTxConfig::SchemeShard, subDomainPathId), attrs); env.TestWaitNotification(runtime, txId); TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( @@ -2042,14 +2048,14 @@ Y_UNIT_TEST_SUITE(TCdcStreamWithInitialScanTests) { runtime.DispatchEvents(opts); } - UNIT_ASSERT_STRINGS_EQUAL(meteringRecord, TBillRecord() + auto expectedBill = TBillRecord() .Id("cdc_stream_scan-72075186233409549-3-72075186233409549-4") .CloudId("CLOUD_ID_VAL") .FolderId("FOLDER_ID_VAL") .ResourceId("DATABASE_ID_VAL") .SourceWt(TInstant::FromValue(0)) - .Usage(TBillRecord::RequestUnits(1, TInstant::FromValue(0))) - .ToString()); + .Usage(TBillRecord::RequestUnits(1, TInstant::FromValue(0))); + MeteringDataEqual(meteringRecord, expectedBill.ToString()); } else { for (int i = 0; i < 10; ++i) { env.SimulateSleep(runtime, TDuration::Seconds(1)); diff --git a/ydb/core/tx/schemeshard/ut_column_build/ut_column_build.cpp b/ydb/core/tx/schemeshard/ut_column_build/ut_column_build.cpp index 5ede1a9c75f..f12bd4af8f5 100644 --- a/ydb/core/tx/schemeshard/ut_column_build/ut_column_build.cpp +++ b/ydb/core/tx/schemeshard/ut_column_build/ut_column_build.cpp @@ -19,6 +19,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { "Name: \"ResourceDB\""); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", "StoragePools { " " Name: \"pool-1\" " @@ -46,9 +49,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { Name: "ServerLessDB" ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } - )", TTestTxConfig::SchemeShard), attrs); + )", TTestTxConfig::SchemeShard, subDomainPathId), attrs); env.TestWaitNotification(runtime, txId); TString alterData = TStringBuilder() @@ -125,6 +128,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { "Name: \"ResourceDB\""); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", "StoragePools { " " Name: \"pool-1\" " @@ -152,9 +158,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { Name: "ServerLessDB" ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } - )", TTestTxConfig::SchemeShard), attrs); + )", TTestTxConfig::SchemeShard, subDomainPathId), attrs); env.TestWaitNotification(runtime, txId); TString alterData = TStringBuilder() @@ -219,7 +225,7 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { defaultValue.mutable_value()->set_uint64_value(1111); // TODO: check invalid value TestBuildColumn(runtime, ++txId, tenantSchemeShard, "/MyRoot/ServerLessDB", "/MyRoot/ServerLessDB/Table", "ColumnValue", defaultValue, Ydb::StatusIds::SUCCESS); - + auto listing = TestListBuildIndex(runtime, tenantSchemeShard, "/MyRoot/ServerLessDB"); Y_ASSERT(listing.EntriesSize() == 1); @@ -238,6 +244,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { "Name: \"ResourceDB\""); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", "StoragePools { " " Name: \"pool-1\" " @@ -265,9 +274,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { Name: "ServerLessDB" ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } - )", TTestTxConfig::SchemeShard), attrs); + )", TTestTxConfig::SchemeShard, subDomainPathId), attrs); env.TestWaitNotification(runtime, txId); TString alterData = TStringBuilder() @@ -379,7 +388,7 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { for (const auto& ev: delayedUpsertRows) { runtime.Send(ev); } - + enabledCapture = false; auto listing = TestListBuildIndex(runtime, tenantSchemeShard, "/MyRoot/ServerLessDB"); @@ -388,7 +397,7 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { env.TestWaitNotification(runtime, txId, tenantSchemeShard); auto descr = TestGetBuildIndex(runtime, tenantSchemeShard, "/MyRoot/ServerLessDB", txId); - Y_ASSERT(descr.GetIndexBuild().GetState() == Ydb::Table::IndexBuildState::STATE_DONE); + Y_ASSERT(descr.GetIndexBuild().GetState() == Ydb::Table::IndexBuildState::STATE_DONE); for (ui32 delta = 50; delta < 101; ++delta) { UNIT_ASSERT(CheckLocalRowExists(runtime, TTestTxConfig::FakeHiveTablets + 6, "__user__Table", "key", 1 + delta)); @@ -408,6 +417,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { "Name: \"ResourceDB\""); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", "StoragePools { " " Name: \"pool-1\" " @@ -435,9 +447,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) { Name: "ServerLessDB" ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } - )", TTestTxConfig::SchemeShard), attrs); + )", TTestTxConfig::SchemeShard, subDomainPathId), attrs); env.TestWaitNotification(runtime, txId); TString alterData = TStringBuilder() diff --git a/ydb/core/tx/schemeshard/ut_compaction/ut_compaction.cpp b/ydb/core/tx/schemeshard/ut_compaction/ut_compaction.cpp index f5884ec8433..fe9626126b7 100644 --- a/ydb/core/tx/schemeshard/ut_compaction/ut_compaction.cpp +++ b/ydb/core/tx/schemeshard/ut_compaction/ut_compaction.cpp @@ -454,6 +454,9 @@ ui64 TestServerless( )"); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/Shared"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( PlanResolution: 50 Coordinators: 1 @@ -482,9 +485,9 @@ ui64 TestServerless( Name: "User" ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } - )", schemeshardId), attrs); + )", schemeshardId, subDomainPathId), attrs); env.TestWaitNotification(runtime, txId); TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( diff --git a/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp b/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp index a95b86ae7a2..606c5fc9a8a 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp +++ b/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp @@ -1429,6 +1429,13 @@ namespace NSchemeShardUT_Private { }; } + TLocalPathId GetNextLocalPathId(TTestActorRuntime& runtime, ui64& txId) { + TestMkDir(runtime, ++txId, "/MyRoot", "test42"); + TLocalPathId res = DescribePath(runtime, "/MyRoot/test42").GetPathId() + 1; + TestRmDir(runtime, ++txId, "/MyRoot", "test42"); + return res; + } + TString SetAllowLogBatching(TTestActorRuntime& runtime, ui64 tabletId, bool v) { NTabletFlatScheme::TSchemeChanges scheme; TString errStr; @@ -2738,6 +2745,9 @@ namespace NSchemeShardUT_Private { TestCreateExtSubDomain(runtime, ++txId, "/MyRoot", "Name: \"ResourceDB\""); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( StoragePools { Name: "pool-1" @@ -2765,9 +2775,9 @@ namespace NSchemeShardUT_Private { Name: "ServerLessDB" ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } - )", TTestTxConfig::SchemeShard), attrs); + )", TTestTxConfig::SchemeShard, subDomainPathId), attrs); env.TestWaitNotification(runtime, txId); TString alterData = R"( @@ -2792,4 +2802,54 @@ namespace NSchemeShardUT_Private { NLs::ExtractTenantSchemeshard(&tenantSchemeShard)}); } + void MeteringDataEqual(const TString& leftMsg, const TString& rightMsg) { + const auto leftMeteringData = NJson::ReadJsonFastTree(leftMsg); + const auto rightMeteringData = NJson::ReadJsonFastTree(rightMsg); + + const auto leftIdParts = SplitString(leftMeteringData["id"].GetString(), "-"); + const auto rightIdParts = SplitString(rightMeteringData["id"].GetString(), "-"); + UNIT_ASSERT_VALUES_EQUAL(leftIdParts.size(), rightIdParts.size()); + + size_t localPathIdIndex = 2; + if (leftMeteringData["source_id"] == "sless-docapi-ydb-storage") { + localPathIdIndex = 1; + } + + for (size_t i = 0; i < leftIdParts.size(); ++i) { + if (i != localPathIdIndex) { // no need to compare localPathIds + UNIT_ASSERT_VALUES_EQUAL(leftIdParts[i], rightIdParts[i]); + } + } + + const auto& leftUsage = leftMeteringData["usage"]; + const auto& rightUsage = rightMeteringData["usage"]; + for (const auto& field : {"quantity", "unit", "type"}) { + Cerr << field << ": " << leftUsage[field] << ", " << rightUsage[field] << Endl; + UNIT_ASSERT_VALUES_EQUAL(leftUsage[field], rightUsage[field]); + } + + for (const auto& field : {"version", "schema", "cloud_id", "folder_id", "resource_id", "source_id"}) { + UNIT_ASSERT_VALUES_EQUAL(leftMeteringData[field], rightMeteringData[field]); + } + + const auto& leftTags = leftMeteringData["tags"].GetMap(); + const auto& rightTags = rightMeteringData["tags"].GetMap(); + UNIT_ASSERT_VALUES_EQUAL(leftTags.size(), rightTags.size()); + + for (const auto& [tag, value] : leftTags) { + auto it = rightTags.find(tag); + UNIT_ASSERT(it != rightTags.end()); + UNIT_ASSERT_VALUES_EQUAL(value, it->second); + } + + const auto& leftLabels = leftMeteringData["labels"].GetMap(); + const auto& rightLabels = rightMeteringData["labels"].GetMap(); + UNIT_ASSERT_VALUES_EQUAL(leftLabels.size(), rightLabels.size()); + + for (const auto& [label, value] : leftLabels) { + auto it = rightLabels.find(label); + UNIT_ASSERT(it != rightLabels.end()); + UNIT_ASSERT_VALUES_EQUAL(value, it->second); + } + } } diff --git a/ydb/core/tx/schemeshard/ut_helpers/helpers.h b/ydb/core/tx/schemeshard/ut_helpers/helpers.h index 739fd7b74e6..082134f54d8 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/helpers.h +++ b/ydb/core/tx/schemeshard/ut_helpers/helpers.h @@ -486,6 +486,8 @@ namespace NSchemeShardUT_Private { TVector<ui64> GetTableShards(TTestActorRuntime& runtime, ui64 schemeShard, const TString& path); NLs::TCheckFunc ShardsIsReady(TTestActorRuntime& runtime); + TLocalPathId GetNextLocalPathId(TTestActorRuntime& runtime, ui64& txId); + template <typename TCreateFunc> void CreateWithIntermediateDirs(TCreateFunc func) { TTestWithReboots t; @@ -508,8 +510,14 @@ namespace NSchemeShardUT_Private { void CreateWithIntermediateDirsForceDrop(TCreateFunc func) { TTestWithReboots t; t.Run([&](TTestActorRuntime& runtime, bool& activeZone) { + TLocalPathId nextPathId; + { + TInactiveZone inactive(activeZone); + nextPathId = GetNextLocalPathId(runtime, t.TxId); + } + func(runtime, ++t.TxId, "/MyRoot"); - AsyncForceDropUnsafe(runtime, ++t.TxId, 3); + AsyncForceDropUnsafe(runtime, ++t.TxId, nextPathId); t.TestEnv->TestWaitNotification(runtime, {t.TxId - 1, t.TxId}); { @@ -667,4 +675,6 @@ namespace NSchemeShardUT_Private { void TestCreateServerLessDb(TTestActorRuntime& runtime, TTestEnv& env, ui64& txId, ui64& tenantSchemeShard); + void MeteringDataEqual(const TString& leftMsg, const TString& rightMsg); + } //NSchemeShardUT_Private diff --git a/ydb/core/tx/schemeshard/ut_index_build/ut_index_build.cpp b/ydb/core/tx/schemeshard/ut_index_build/ut_index_build.cpp index ea36119a66b..9d09091f76d 100644 --- a/ydb/core/tx/schemeshard/ut_index_build/ut_index_build.cpp +++ b/ydb/core/tx/schemeshard/ut_index_build/ut_index_build.cpp @@ -248,7 +248,7 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) { const TString meteringData = R"({"usage":{"start":0,"quantity":179,"finish":0,"unit":"request_unit","type":"delta"},"tags":{},"id":"106-72075186233409549-2-0-0-0-0-101-101-1818-1818","cloud_id":"CLOUD_ID_VAL","source_wt":0,"source_id":"sless-docapi-ydb-ss","resource_id":"DATABASE_ID_VAL","schema":"ydb.serverless.requests.v1","folder_id":"FOLDER_ID_VAL","version":"1.0.0"})"; - UNIT_ASSERT_NO_DIFF(meteringMessages, meteringData + "\n"); + MeteringDataEqual(meteringMessages, meteringData); TestDescribeResult(DescribePath(runtime, tenantSchemeShard, "/MyRoot/ServerLessDB/Table"), {NLs::PathExist, diff --git a/ydb/core/tx/schemeshard/ut_index_build/ut_vector_index_build.cpp b/ydb/core/tx/schemeshard/ut_index_build/ut_vector_index_build.cpp index 297fc999869..0c3369544cf 100644 --- a/ydb/core/tx/schemeshard/ut_index_build/ut_vector_index_build.cpp +++ b/ydb/core/tx/schemeshard/ut_index_build/ut_vector_index_build.cpp @@ -567,7 +567,7 @@ Y_UNIT_TEST_SUITE (VectorIndexBuildTest) { .SourceWt(TInstant::Seconds(10)) .Usage(TBillRecord::RequestUnits(130, TInstant::Seconds(0), TInstant::Seconds(10))); UNIT_ASSERT_VALUES_EQUAL(meteringBlocker.size(), 1); - UNIT_ASSERT_VALUES_EQUAL(meteringBlocker[0]->Get()->MeteringJson, expectedBill.ToString()); + MeteringDataEqual(meteringBlocker[0]->Get()->MeteringJson, expectedBill.ToString()); previousBillId = newBillId; meteringBlocker.Unblock(); } @@ -638,7 +638,7 @@ Y_UNIT_TEST_SUITE (VectorIndexBuildTest) { .SourceWt(TInstant::Seconds(10)) .Usage(TBillRecord::RequestUnits(336, TInstant::Seconds(10), TInstant::Seconds(10))); UNIT_ASSERT_VALUES_EQUAL(meteringBlocker.size(), 1); - UNIT_ASSERT_VALUES_EQUAL(meteringBlocker[0]->Get()->MeteringJson, expectedBill.ToString()); + MeteringDataEqual(meteringBlocker[0]->Get()->MeteringJson, expectedBill.ToString()); previousBillId = newBillId; meteringBlocker.Stop().Unblock(); } diff --git a/ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp b/ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp index 77e001447e7..0e43c91546c 100644 --- a/ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp +++ b/ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp @@ -234,6 +234,7 @@ Y_UNIT_TEST_SUITE(TOlap) { TestLs(runtime, "/MyRoot/MyDir", false, NLs::PathExist); + const auto expectedTablePathId = GetNextLocalPathId(runtime, txId); TestCreateColumnTable(runtime, ++txId, "/MyRoot/MyDir", R"( Name: "MyTable" ColumnShardCount: 1 @@ -246,13 +247,13 @@ Y_UNIT_TEST_SUITE(TOlap) { )"); env.TestWaitNotification(runtime, txId); - TestLsPathId(runtime, 4, NLs::PathStringEqual("/MyRoot/MyDir/MyTable")); + TestLsPathId(runtime, expectedTablePathId, NLs::PathStringEqual("/MyRoot/MyDir/MyTable")); TestDropColumnTable(runtime, ++txId, "/MyRoot/MyDir", "MyTable"); env.TestWaitNotification(runtime, txId); TestLs(runtime, "/MyRoot/MyDir/MyTable", false, NLs::PathNotExist); - TestLsPathId(runtime, 4, NLs::PathStringEqual("")); + TestLsPathId(runtime, expectedTablePathId, NLs::PathStringEqual("")); } Y_UNIT_TEST(CreateTable) { @@ -415,11 +416,12 @@ Y_UNIT_TEST_SUITE(TOlap) { const TString& olapSchema = defaultStoreSchema; + const auto expectedStorePathId = GetNextLocalPathId(runtime, txId); TestCreateOlapStore(runtime, ++txId, "/MyRoot", olapSchema); env.TestWaitNotification(runtime, txId); TestLs(runtime, "/MyRoot/OlapStore", false, NLs::PathExist); - TestLsPathId(runtime, 2, NLs::PathStringEqual("/MyRoot/OlapStore")); + TestLsPathId(runtime, expectedStorePathId, NLs::PathStringEqual("/MyRoot/OlapStore")); TestMkDir(runtime, ++txId, "/MyRoot/OlapStore", "MyDir"); env.TestWaitNotification(runtime, txId); @@ -431,16 +433,17 @@ Y_UNIT_TEST_SUITE(TOlap) { ColumnShardCount: 1 )"; + const auto expectedTablePathId = GetNextLocalPathId(runtime, txId); TestCreateColumnTable(runtime, ++txId, "/MyRoot/OlapStore/MyDir", tableSchema); env.TestWaitNotification(runtime, txId); - TestLsPathId(runtime, 4, NLs::PathStringEqual("/MyRoot/OlapStore/MyDir/ColumnTable")); + TestLsPathId(runtime, expectedTablePathId, NLs::PathStringEqual("/MyRoot/OlapStore/MyDir/ColumnTable")); TestDropColumnTable(runtime, ++txId, "/MyRoot/OlapStore/MyDir", "ColumnTable"); env.TestWaitNotification(runtime, txId); TestLs(runtime, "/MyRoot/OlapStore/MyDir/ColumnTable", false, NLs::PathNotExist); - TestLsPathId(runtime, 4, NLs::PathStringEqual("")); + TestLsPathId(runtime, expectedTablePathId, NLs::PathStringEqual("")); TestDropOlapStore(runtime, ++txId, "/MyRoot", "OlapStore", {NKikimrScheme::StatusNameConflict}); TestRmDir(runtime, ++txId, "/MyRoot/OlapStore", "MyDir"); @@ -450,7 +453,7 @@ Y_UNIT_TEST_SUITE(TOlap) { env.TestWaitNotification(runtime, txId); TestLs(runtime, "/MyRoot/OlapStore", false, NLs::PathNotExist); - TestLsPathId(runtime, 2, NLs::PathStringEqual("")); + TestLsPathId(runtime, expectedStorePathId, NLs::PathStringEqual("")); } Y_UNIT_TEST(CreateDropStandaloneTable) { @@ -463,16 +466,17 @@ Y_UNIT_TEST_SUITE(TOlap) { TestLs(runtime, "/MyRoot/MyDir", false, NLs::PathExist); + auto expectedTablePathId = GetNextLocalPathId(runtime, txId); TestCreateColumnTable(runtime, ++txId, "/MyRoot/MyDir", defaultTableSchema); env.TestWaitNotification(runtime, txId); - TestLsPathId(runtime, 3, NLs::PathStringEqual("/MyRoot/MyDir/ColumnTable")); + TestLsPathId(runtime, expectedTablePathId, NLs::PathStringEqual("/MyRoot/MyDir/ColumnTable")); TestDropColumnTable(runtime, ++txId, "/MyRoot/MyDir", "ColumnTable"); env.TestWaitNotification(runtime, txId); TestLs(runtime, "/MyRoot/MyDir/ColumnTable", false, NLs::PathNotExist); - TestLsPathId(runtime, 3, NLs::PathStringEqual("")); + TestLsPathId(runtime, expectedTablePathId, NLs::PathStringEqual("")); // PARTITION BY () @@ -493,6 +497,7 @@ Y_UNIT_TEST_SUITE(TOlap) { } )"; + expectedTablePathId = GetNextLocalPathId(runtime, txId); TestCreateColumnTable(runtime, ++txId, "/MyRoot/MyDir", otherSchema); env.TestWaitNotification(runtime, txId); @@ -510,13 +515,13 @@ Y_UNIT_TEST_SUITE(TOlap) { UNIT_ASSERT_VALUES_EQUAL(hashSharding.GetColumns()[1], "data"); }; - TestLsPathId(runtime, 4, checkFn); + TestLsPathId(runtime, expectedTablePathId, checkFn); TestDropColumnTable(runtime, ++txId, "/MyRoot/MyDir", "ColumnTable"); env.TestWaitNotification(runtime, txId); TestLs(runtime, "/MyRoot/MyDir/ColumnTable", false, NLs::PathNotExist); - TestLsPathId(runtime, 4, NLs::PathStringEqual("")); + TestLsPathId(runtime, expectedTablePathId, NLs::PathStringEqual("")); } Y_UNIT_TEST(CreateDropStandaloneTableDefaultSharding) { @@ -529,16 +534,17 @@ Y_UNIT_TEST_SUITE(TOlap) { TestLs(runtime, "/MyRoot/MyDir", false, NLs::PathExist); + auto expectedTablePathId = GetNextLocalPathId(runtime, txId); TestCreateColumnTable(runtime, ++txId, "/MyRoot/MyDir", defaultTableSchema); env.TestWaitNotification(runtime, txId); - TestLsPathId(runtime, 3, NLs::PathStringEqual("/MyRoot/MyDir/ColumnTable")); + TestLsPathId(runtime, expectedTablePathId, NLs::PathStringEqual("/MyRoot/MyDir/ColumnTable")); TestDropColumnTable(runtime, ++txId, "/MyRoot/MyDir", "ColumnTable"); env.TestWaitNotification(runtime, txId); TestLs(runtime, "/MyRoot/MyDir/ColumnTable", false, NLs::PathNotExist); - TestLsPathId(runtime, 3, NLs::PathStringEqual("")); + TestLsPathId(runtime, expectedTablePathId, NLs::PathStringEqual("")); TString otherSchema = R"( Name: "ColumnTable" @@ -551,6 +557,7 @@ Y_UNIT_TEST_SUITE(TOlap) { } )"; + expectedTablePathId = GetNextLocalPathId(runtime, txId); TestCreateColumnTable(runtime, ++txId, "/MyRoot/MyDir", otherSchema); env.TestWaitNotification(runtime, txId); @@ -571,13 +578,13 @@ Y_UNIT_TEST_SUITE(TOlap) { UNIT_ASSERT_VALUES_EQUAL(hashSharding.GetColumns()[1], "data"); }; - TestLsPathId(runtime, 4, checkFn); + TestLsPathId(runtime, expectedTablePathId, checkFn); TestDropColumnTable(runtime, ++txId, "/MyRoot/MyDir", "ColumnTable"); env.TestWaitNotification(runtime, txId); TestLs(runtime, "/MyRoot/MyDir/ColumnTable", false, NLs::PathNotExist); - TestLsPathId(runtime, 4, NLs::PathStringEqual("")); + TestLsPathId(runtime, expectedTablePathId, NLs::PathStringEqual("")); } Y_UNIT_TEST(CreateTableTtl) { @@ -873,17 +880,19 @@ Y_UNIT_TEST_SUITE(TOlap) { const TString& olapSchema = defaultStoreSchema; + const auto expectedStorePathId = GetNextLocalPathId(runtime, txId); TestCreateOlapStore(runtime, ++txId, "/MyRoot", olapSchema); env.TestWaitNotification(runtime, txId); TestLs(runtime, "/MyRoot/OlapStore", false, NLs::PathExist); - TestLsPathId(runtime, 2, NLs::PathStringEqual("/MyRoot/OlapStore")); + TestLsPathId(runtime, expectedStorePathId, NLs::PathStringEqual("/MyRoot/OlapStore")); TString tableSchema = R"( Name: "ColumnTable" ColumnShardCount: 1 )"; + const auto expectedTablePathId = GetNextLocalPathId(runtime, txId); TestCreateColumnTable(runtime, ++txId, "/MyRoot/OlapStore", tableSchema); env.TestWaitNotification(runtime, txId); @@ -901,7 +910,7 @@ Y_UNIT_TEST_SUITE(TOlap) { UNIT_ASSERT_VALUES_EQUAL(record.GetPath(), "/MyRoot/OlapStore/ColumnTable"); }; - TestLsPathId(runtime, 3, checkFn); + TestLsPathId(runtime, expectedTablePathId, checkFn); UNIT_ASSERT(shardId); UNIT_ASSERT(pathId); UNIT_ASSERT(planStep.Val()); @@ -1048,17 +1057,19 @@ Y_UNIT_TEST_SUITE(TOlap) { const TString& olapSchema = defaultStoreSchema; + const auto expectedStorePathId = GetNextLocalPathId(runtime, txId); TestCreateOlapStore(runtime, ++txId, "/MyRoot/SomeDatabase", olapSchema); env.TestWaitNotification(runtime, txId); TestLs(runtime, "/MyRoot/SomeDatabase/OlapStore", false, NLs::PathExist); - TestLsPathId(runtime, 3, NLs::PathStringEqual("/MyRoot/SomeDatabase/OlapStore")); + TestLsPathId(runtime, expectedStorePathId, NLs::PathStringEqual("/MyRoot/SomeDatabase/OlapStore")); TString tableSchema = R"( Name: "ColumnTable" ColumnShardCount: 1 )"; + const auto expectedTablePathId = GetNextLocalPathId(runtime, txId); TestCreateColumnTable(runtime, ++txId, "/MyRoot/SomeDatabase/OlapStore", tableSchema); env.TestWaitNotification(runtime, txId); @@ -1076,7 +1087,7 @@ Y_UNIT_TEST_SUITE(TOlap) { UNIT_ASSERT_VALUES_EQUAL(record.GetPath(), "/MyRoot/SomeDatabase/OlapStore/ColumnTable"); }; - TestLsPathId(runtime, 4, checkFn); + TestLsPathId(runtime, expectedTablePathId, checkFn); UNIT_ASSERT(shardId); UNIT_ASSERT(pathId); UNIT_ASSERT(planStep.Val()); @@ -1205,9 +1216,9 @@ Y_UNIT_TEST_SUITE(TOlapNaming) { TTestBasicRuntime runtime; TTestEnv env(runtime); ui64 txId = 100; - + TVector<TString> notAllowedNames = {"mess age", "~!@#$%^&*()+=asdfa"}; - + for (const auto& colName: notAllowedNames) { TString tableSchema = Sprintf(tableSchemaFormat.c_str(), colName.c_str()); diff --git a/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp b/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp index d218de41e08..1a1e065fc2a 100644 --- a/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp +++ b/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp @@ -3042,6 +3042,9 @@ Y_UNIT_TEST_SUITE(TImportTests) { )", TStringBuf(serverless ? "/MyRoot/Shared" : dbName).RNextTok('/').data())); env.TestWaitNotification(runtime, id); + const auto describeResult = DescribePath(runtime, serverless ? "/MyRoot/Shared" : dbName); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++id, "/MyRoot", Sprintf(R"( PlanResolution: 50 Coordinators: 1 @@ -3071,9 +3074,9 @@ Y_UNIT_TEST_SUITE(TImportTests) { Name: "%s" ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } - )", TStringBuf(dbName).RNextTok('/').data(), TTestTxConfig::SchemeShard), attrs); + )", TStringBuf(dbName).RNextTok('/').data(), TTestTxConfig::SchemeShard, subDomainPathId), attrs); env.TestWaitNotification(runtime, id); TestAlterExtSubDomain(runtime, ++id, "/MyRoot", Sprintf(R"( @@ -3398,7 +3401,7 @@ Y_UNIT_TEST_SUITE(TImportTests) { const TString expectedBillRecord = R"({"usage":{"start":0,"quantity":50,"finish":0,"unit":"request_unit","type":"delta"},"tags":{},"id":"281474976725758-72075186233409549-2-72075186233409549-4","cloud_id":"CLOUD_ID_VAL","source_wt":0,"source_id":"sless-docapi-ydb-ss","resource_id":"DATABASE_ID_VAL","schema":"ydb.serverless.requests.v1","folder_id":"FOLDER_ID_VAL","version":"1.0.0"})"; UNIT_ASSERT_VALUES_EQUAL(billRecords.size(), 1); - UNIT_ASSERT_NO_DIFF(billRecords[0], expectedBillRecord + "\n"); + MeteringDataEqual(billRecords[0], expectedBillRecord); } Y_UNIT_TEST(ShouldNotWriteBillRecordOnCommonDb) { diff --git a/ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp b/ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp index 4dcfd566ebf..c704d8e10b6 100644 --- a/ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp +++ b/ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp @@ -22,6 +22,9 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { "Name: \"SharedDB\""); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/SharedDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", "StoragePools { " " Name: \"pool-1\" " @@ -50,7 +53,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { && sharedHive != TTestTxConfig::Hive); TString createData = TStringBuilder() - << "ResourcesDomainKey { SchemeShard: " << TTestTxConfig::SchemeShard << " PathId: " << 2 << " } " + << "ResourcesDomainKey { SchemeShard: " << TTestTxConfig::SchemeShard << " PathId: " << subDomainPathId << " } " << "Name: \"ServerLess0\""; TestCreateExtSubDomain(runtime, ++txId, "/MyRoot", createData); env.TestWaitNotification(runtime, txId); @@ -134,6 +137,9 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { "Name: \"ResourceDB\""); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", "StoragePools { " " Name: \"pool-1\" " @@ -155,7 +161,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { runtime.UpdateCurrentTime(now); TString createData = TStringBuilder() - << "ResourcesDomainKey { SchemeShard: " << TTestTxConfig::SchemeShard << " PathId: " << 2 << " } " + << "ResourcesDomainKey { SchemeShard: " << TTestTxConfig::SchemeShard << " PathId: " << subDomainPathId << " } " << "Name: \"ServerLessDB\""; TestCreateExtSubDomain(runtime, ++txId, "/MyRoot", createData); env.TestWaitNotification(runtime, txId); @@ -242,8 +248,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { { TString meteringData = R"({"usage":{"start":1600452120,"quantity":59,"finish":1600452179,"type":"delta","unit":"byte*second"},"tags":{"ydb_size":13280},"id":"72057594046678944-3-1600452120-1600452179-13280","cloud_id":"CLOUD_ID_VAL","source_wt":1600452180,"source_id":"sless-docapi-ydb-storage","resource_id":"DATABASE_ID_VAL","schema":"ydb.serverless.v1","folder_id":"FOLDER_ID_VAL","version":"1.0.0"})"; - meteringData += "\n"; - UNIT_ASSERT_NO_DIFF(meteringMessages, meteringData); + MeteringDataEqual(meteringMessages, meteringData); } runtime.SetObserverFunc(prevObserver); @@ -258,8 +263,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { { TString meteringData = R"({"usage":{"start":1600452180,"quantity":59,"finish":1600452239,"type":"delta","unit":"byte*second"},"tags":{"ydb_size":0},"id":"72057594046678944-3-1600452180-1600452239-0","cloud_id":"CLOUD_ID_VAL","source_wt":1600452240,"source_id":"sless-docapi-ydb-storage","resource_id":"DATABASE_ID_VAL","schema":"ydb.serverless.v1","folder_id":"FOLDER_ID_VAL","version":"1.0.0"})"; - meteringData += "\n"; - UNIT_ASSERT_NO_DIFF(meteringMessages, meteringData); + MeteringDataEqual(meteringMessages, meteringData); } } @@ -274,6 +278,9 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { )"); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/SharedDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( Name: "SharedDB" StoragePools { @@ -292,9 +299,9 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { Name: "ServerlessDB" ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } - )", TTestTxConfig::SchemeShard)); + )", TTestTxConfig::SchemeShard, subDomainPathId)); env.TestWaitNotification(runtime, txId); TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( @@ -339,6 +346,9 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { ); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/SharedDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( StoragePools { @@ -384,11 +394,11 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { R"( ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } Name: "ServerLess0" )", - TTestTxConfig::SchemeShard + TTestTxConfig::SchemeShard, subDomainPathId ); TestCreateExtSubDomain(runtime, ++txId, "/MyRoot", createData); env.TestWaitNotification(runtime, txId); @@ -457,6 +467,9 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { ); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/SharedDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( StoragePools { @@ -482,11 +495,11 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { R"( ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } Name: "ServerLess0" )", - TTestTxConfig::SchemeShard + TTestTxConfig::SchemeShard, subDomainPathId ); TestCreateExtSubDomain(runtime, ++txId, "/MyRoot", createData); env.TestWaitNotification(runtime, txId); @@ -538,6 +551,9 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { ); env.TestWaitNotification(runtime, txId); + const auto describeResult = DescribePath(runtime, "/MyRoot/SharedDB"); + const auto subDomainPathId = describeResult.GetPathId(); + TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"( StoragePools { @@ -563,11 +579,11 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) { R"( ResourcesDomainKey { SchemeShard: %lu - PathId: 2 + PathId: %lu } Name: "ServerLess0" )", - TTestTxConfig::SchemeShard + TTestTxConfig::SchemeShard, subDomainPathId ); TestCreateExtSubDomain(runtime, ++txId, "/MyRoot", createData); env.TestWaitNotification(runtime, txId); diff --git a/ydb/core/tx/schemeshard/ut_serverless_reboots/ut_serverless_reboots.cpp b/ydb/core/tx/schemeshard/ut_serverless_reboots/ut_serverless_reboots.cpp index 317144fa252..24eda75e7a0 100644 --- a/ydb/core/tx/schemeshard/ut_serverless_reboots/ut_serverless_reboots.cpp +++ b/ydb/core/tx/schemeshard/ut_serverless_reboots/ut_serverless_reboots.cpp @@ -18,7 +18,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLessReboots) { if (checkFunction(describeResult)) { checkPassed = true; break; - } + } t.TestEnv->SimulateSleep(runtime, TDuration::MilliSeconds(10)); } UNIT_ASSERT(checkPassed); @@ -41,7 +41,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLessReboots) { Y_UNIT_TEST(TestServerlessComputeResourcesModeWithReboots) { TTestWithReboots t; t.GetTestEnvOptions().EnableServerlessExclusiveDynamicNodes(true); - + t.Run([&](TTestActorRuntime& runtime, bool& activeZone) { ui64 sharedHive = 0; ui64 tenantSchemeShard = 0; @@ -72,24 +72,28 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLessReboots) { ); t.TestEnv->TestWaitNotification(runtime, t.TxId); + ui64 subDomainPathId = 0; + { TInactiveZone inactive(activeZone); ui64 sharedDbSchemeShard = 0; - TestDescribeResult(DescribePath(runtime, "/MyRoot/SharedDB"), + const auto describeResult = DescribePath(runtime, "/MyRoot/SharedDB"); + subDomainPathId = describeResult.GetPathId(); + TestDescribeResult(describeResult, {NLs::PathExist, NLs::ExtractTenantSchemeshard(&sharedDbSchemeShard), NLs::ExtractDomainHive(&sharedHive), NLs::ServerlessComputeResourcesMode(EServerlessComputeResourcesModeUnspecified)}); - + UNIT_ASSERT(sharedHive != 0 && sharedHive != (ui64)-1 && sharedHive != TTestTxConfig::Hive); - + UNIT_ASSERT(sharedDbSchemeShard != 0 && sharedDbSchemeShard != (ui64)-1 && sharedDbSchemeShard != TTestTxConfig::SchemeShard); - + TestDescribeResult(DescribePath(runtime, sharedDbSchemeShard, "/MyRoot/SharedDB"), {NLs::PathExist, NLs::ServerlessComputeResourcesMode(EServerlessComputeResourcesModeUnspecified)}); @@ -99,11 +103,11 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLessReboots) { R"( ResourcesDomainKey { SchemeShard: %lu - PathId: 3 + PathId: %lu } Name: "ServerLess0" )", - TTestTxConfig::SchemeShard + TTestTxConfig::SchemeShard, subDomainPathId ); TestCreateExtSubDomain(runtime, ++t.TxId, "/MyRoot", createData); t.TestEnv->TestWaitNotification(runtime, t.TxId); @@ -124,7 +128,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLessReboots) { )" ); t.TestEnv->TestWaitNotification(runtime, t.TxId); - + { TInactiveZone inactive(activeZone); TestDescribeResult(DescribePath(runtime, "/MyRoot/ServerLess0"), @@ -132,7 +136,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLessReboots) { NLs::IsExternalSubDomain("ServerLess0"), NLs::ServerlessComputeResourcesMode(EServerlessComputeResourcesModeShared), NLs::ExtractTenantSchemeshard(&tenantSchemeShard)}); - + UNIT_ASSERT(tenantSchemeShard != 0 && tenantSchemeShard != (ui64)-1 && tenantSchemeShard != TTestTxConfig::SchemeShard); |
