Skip to content

Made SchemeShard tests robust to changing of PathIds #19992

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
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
20 changes: 13 additions & 7 deletions ydb/core/tx/schemeshard/ut_cdc_stream/ut_cdc_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"(
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"(
Expand Down Expand Up @@ -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));
Expand Down
34 changes: 23 additions & 11 deletions ydb/core/tx/schemeshard/ut_column_build/ut_column_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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\" "
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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\" "
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);

Expand All @@ -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\" "
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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");
Expand All @@ -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));
Expand All @@ -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\" "
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions ydb/core/tx/schemeshard/ut_compaction/ut_compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"(
Expand Down
64 changes: 62 additions & 2 deletions ydb/core/tx/schemeshard/ut_helpers/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"(
Expand All @@ -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);
}
}
}
12 changes: 11 additions & 1 deletion ydb/core/tx/schemeshard/ut_helpers/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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});

{
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
Loading
Loading