diff --git a/ydb/core/statistics/aggregator/ut/ut_analyze_columnshard.cpp b/ydb/core/statistics/aggregator/ut/ut_analyze_columnshard.cpp index 0911a52a3818..f0279f3fe50c 100644 --- a/ydb/core/statistics/aggregator/ut/ut_analyze_columnshard.cpp +++ b/ydb/core/statistics/aggregator/ut/ut_analyze_columnshard.cpp @@ -29,9 +29,12 @@ Y_UNIT_TEST_SUITE(AnalyzeColumnshard) { auto sender = runtime.AllocateEdgeActor(); ui64 columnShardId = GetColumnTableShards(runtime, sender, "/Root/Database/Table").at(0); - auto pathId = ResolvePathId(runtime, "/Root/Database/Table", nullptr); + ui64 saTabletId = 0; + auto pathId = ResolvePathId(runtime, "/Root/Database/Table", nullptr, &saTabletId); AnalyzeTable(runtime, pathId, columnShardId); + + Analyze(runtime, {pathId}, saTabletId); } } diff --git a/ydb/core/statistics/aggregator/ut/ut_analyze_datashard.cpp b/ydb/core/statistics/aggregator/ut/ut_analyze_datashard.cpp index fe9ae1d01e41..3f77cb85e612 100644 --- a/ydb/core/statistics/aggregator/ut/ut_analyze_datashard.cpp +++ b/ydb/core/statistics/aggregator/ut/ut_analyze_datashard.cpp @@ -19,7 +19,7 @@ namespace { Y_UNIT_TEST_SUITE(AnalyzeDatashard) { - Y_UNIT_TEST(ScanOneTable) { + Y_UNIT_TEST(AnalyzeOneTable) { TTestEnv env(1, 1); auto init = [&] () { CreateDatabase(env, "Database"); @@ -36,18 +36,12 @@ Y_UNIT_TEST_SUITE(AnalyzeDatashard) { runtime.SimulateSleep(TDuration::Seconds(30)); - auto ev = std::make_unique(); - auto& record = ev->Record; - PathIdFromPathId(pathId, record.AddTables()->MutablePathId()); - - auto sender = runtime.AllocateEdgeActor(); - runtime.SendToPipe(saTabletId, sender, ev.release()); - runtime.GrabEdgeEventRethrow(sender); + Analyze(runtime, {{pathId}}, saTabletId); ValidateCountMin(runtime, pathId); } - Y_UNIT_TEST(ScanTwoTables) { + Y_UNIT_TEST(AnalyzeTwoTables) { TTestEnv env(1, 1); auto init = [&] () { CreateDatabase(env, "Database"); @@ -68,116 +62,12 @@ Y_UNIT_TEST_SUITE(AnalyzeDatashard) { auto pathId1 = ResolvePathId(runtime, "/Root/Database/Table1", nullptr, &saTabletId1); auto pathId2 = ResolvePathId(runtime, "/Root/Database/Table2"); - auto ev = std::make_unique(); - auto& record = ev->Record; - PathIdFromPathId(pathId1, record.AddTables()->MutablePathId()); - PathIdFromPathId(pathId2, record.AddTables()->MutablePathId()); - - auto sender = runtime.AllocateEdgeActor(); - runtime.SendToPipe(saTabletId1, sender, ev.release()); - runtime.GrabEdgeEventRethrow(sender); - runtime.GrabEdgeEventRethrow(sender); + Analyze(runtime, {pathId1, pathId2}, saTabletId1); ValidateCountMin(runtime, pathId1); ValidateCountMin(runtime, pathId2); } - Y_UNIT_TEST(ScanOneTableServerless) { - TTestEnv env(1, 1); - - auto init = [&] () { - CreateDatabase(env, "Shared"); - }; - std::thread initThread(init); - - auto& runtime = *env.GetServer().GetRuntime(); - runtime.SimulateSleep(TDuration::Seconds(5)); - initThread.join(); - - TPathId domainKey; - ResolvePathId(runtime, "/Root/Shared", &domainKey); - - auto init2 = [&] () { - CreateServerlessDatabase(env, "Serverless", domainKey); - CreateUniformTable(env, "Serverless", "Table"); - }; - std::thread init2Thread(init2); - - runtime.SimulateSleep(TDuration::Seconds(5)); - init2Thread.join(); - - runtime.SimulateSleep(TDuration::Seconds(60)); - - auto pathId = ResolvePathId(runtime, "/Root/Serverless/Table"); - ValidateCountMin(runtime, pathId); - } - - Y_UNIT_TEST(ScanTwoTablesServerless) { - TTestEnv env(1, 1); - - auto init = [&] () { - CreateDatabase(env, "Shared"); - }; - std::thread initThread(init); - - auto& runtime = *env.GetServer().GetRuntime(); - runtime.SimulateSleep(TDuration::Seconds(5)); - initThread.join(); - - TPathId domainKey; - ResolvePathId(runtime, "/Root/Shared", &domainKey); - - auto init2 = [&] () { - CreateServerlessDatabase(env, "Serverless", domainKey); - CreateUniformTable(env, "Serverless", "Table1"); - CreateUniformTable(env, "Serverless", "Table2"); - }; - std::thread init2Thread(init2); - - runtime.SimulateSleep(TDuration::Seconds(5)); - init2Thread.join(); - - runtime.SimulateSleep(TDuration::Seconds(60)); - - auto pathId1 = ResolvePathId(runtime, "/Root/Serverless/Table1"); - auto pathId2 = ResolvePathId(runtime, "/Root/Serverless/Table2"); - ValidateCountMin(runtime, pathId1); - ValidateCountMin(runtime, pathId2); - } - - Y_UNIT_TEST(ScanTwoTablesTwoServerlessDbs) { - TTestEnv env(1, 1); - - auto init = [&] () { - CreateDatabase(env, "Shared"); - }; - std::thread initThread(init); - - auto& runtime = *env.GetServer().GetRuntime(); - runtime.SimulateSleep(TDuration::Seconds(5)); - initThread.join(); - - TPathId domainKey; - ResolvePathId(runtime, "/Root/Shared", &domainKey); - - auto init2 = [&] () { - CreateServerlessDatabase(env, "Serverless1", domainKey); - CreateServerlessDatabase(env, "Serverless2", domainKey); - CreateUniformTable(env, "Serverless1", "Table1"); - CreateUniformTable(env, "Serverless2", "Table2"); - }; - std::thread init2Thread(init2); - - runtime.SimulateSleep(TDuration::Seconds(5)); - init2Thread.join(); - - runtime.SimulateSleep(TDuration::Seconds(60)); - - auto pathId1 = ResolvePathId(runtime, "/Root/Serverless1/Table1"); - auto pathId2 = ResolvePathId(runtime, "/Root/Serverless2/Table2"); - ValidateCountMin(runtime, pathId1); - ValidateCountMin(runtime, pathId2); - } Y_UNIT_TEST(DropTableNavigateError) { TTestEnv env(1, 1); @@ -202,12 +92,7 @@ Y_UNIT_TEST_SUITE(AnalyzeDatashard) { runtime.SimulateSleep(TDuration::Seconds(5)); init2Thread.join(); - auto ev = std::make_unique(); - auto& record = ev->Record; - PathIdFromPathId(pathId, record.AddTables()->MutablePathId()); - - auto sender = runtime.AllocateEdgeActor(); - runtime.SendToPipe(saTabletId, sender, ev.release()); + Analyze(runtime, {pathId}, saTabletId); runtime.SimulateSleep(TDuration::Seconds(60)); diff --git a/ydb/core/statistics/aggregator/ut/ut_traverse_datashard.cpp b/ydb/core/statistics/aggregator/ut/ut_traverse_datashard.cpp new file mode 100644 index 000000000000..747826dcac84 --- /dev/null +++ b/ydb/core/statistics/aggregator/ut/ut_traverse_datashard.cpp @@ -0,0 +1,161 @@ +#include + +#include + +#include +#include +#include +#include + +#include + +namespace NKikimr { +namespace NStat { + +namespace { + + +} // namespace + +Y_UNIT_TEST_SUITE(TraverseDatashard) { + + Y_UNIT_TEST(TraverseOneTable) { + TTestEnv env(1, 1); + auto init = [&] () { + CreateDatabase(env, "Database"); + CreateUniformTable(env, "Database", "Table"); + }; + std::thread initThread(init); + + auto& runtime = *env.GetServer().GetRuntime(); + runtime.SimulateSleep(TDuration::Seconds(5)); + initThread.join(); + + runtime.SimulateSleep(TDuration::Seconds(60)); + + auto pathId = ResolvePathId(runtime, "/Root/Database/Table"); + ValidateCountMin(runtime, pathId); + } + + Y_UNIT_TEST(TraverseTwoTables) { + TTestEnv env(1, 1); + auto init = [&] () { + CreateDatabase(env, "Database"); + CreateUniformTable(env, "Database", "Table1"); + CreateUniformTable(env, "Database", "Table2"); + }; + std::thread initThread(init); + + auto& runtime = *env.GetServer().GetRuntime(); + runtime.SimulateSleep(TDuration::Seconds(5)); + initThread.join(); + + runtime.SimulateSleep(TDuration::Seconds(60)); + + auto pathId1 = ResolvePathId(runtime, "/Root/Database/Table1"); + auto pathId2 = ResolvePathId(runtime, "/Root/Database/Table2"); + ValidateCountMin(runtime, pathId1); + ValidateCountMin(runtime, pathId2); + } + + Y_UNIT_TEST(TraverseOneTableServerless) { + TTestEnv env(1, 1); + + auto init = [&] () { + CreateDatabase(env, "Shared"); + }; + std::thread initThread(init); + + auto& runtime = *env.GetServer().GetRuntime(); + runtime.SimulateSleep(TDuration::Seconds(5)); + initThread.join(); + + TPathId domainKey; + ResolvePathId(runtime, "/Root/Shared", &domainKey); + + auto init2 = [&] () { + CreateServerlessDatabase(env, "Serverless", domainKey); + CreateUniformTable(env, "Serverless", "Table"); + }; + std::thread init2Thread(init2); + + runtime.SimulateSleep(TDuration::Seconds(5)); + init2Thread.join(); + + runtime.SimulateSleep(TDuration::Seconds(60)); + + auto pathId = ResolvePathId(runtime, "/Root/Serverless/Table"); + ValidateCountMin(runtime, pathId); + } + + Y_UNIT_TEST(TraverseTwoTablesServerless) { + TTestEnv env(1, 1); + + auto init = [&] () { + CreateDatabase(env, "Shared"); + }; + std::thread initThread(init); + + auto& runtime = *env.GetServer().GetRuntime(); + runtime.SimulateSleep(TDuration::Seconds(5)); + initThread.join(); + + TPathId domainKey; + ResolvePathId(runtime, "/Root/Shared", &domainKey); + + auto init2 = [&] () { + CreateServerlessDatabase(env, "Serverless", domainKey); + CreateUniformTable(env, "Serverless", "Table1"); + CreateUniformTable(env, "Serverless", "Table2"); + }; + std::thread init2Thread(init2); + + runtime.SimulateSleep(TDuration::Seconds(5)); + init2Thread.join(); + + runtime.SimulateSleep(TDuration::Seconds(60)); + + auto pathId1 = ResolvePathId(runtime, "/Root/Serverless/Table1"); + auto pathId2 = ResolvePathId(runtime, "/Root/Serverless/Table2"); + ValidateCountMin(runtime, pathId1); + ValidateCountMin(runtime, pathId2); + } + + Y_UNIT_TEST(TraverseTwoTablesTwoServerlessDbs) { + TTestEnv env(1, 1); + + auto init = [&] () { + CreateDatabase(env, "Shared"); + }; + std::thread initThread(init); + + auto& runtime = *env.GetServer().GetRuntime(); + runtime.SimulateSleep(TDuration::Seconds(5)); + initThread.join(); + + TPathId domainKey; + ResolvePathId(runtime, "/Root/Shared", &domainKey); + + auto init2 = [&] () { + CreateServerlessDatabase(env, "Serverless1", domainKey); + CreateServerlessDatabase(env, "Serverless2", domainKey); + CreateUniformTable(env, "Serverless1", "Table1"); + CreateUniformTable(env, "Serverless2", "Table2"); + }; + std::thread init2Thread(init2); + + runtime.SimulateSleep(TDuration::Seconds(5)); + init2Thread.join(); + + runtime.SimulateSleep(TDuration::Seconds(60)); + + auto pathId1 = ResolvePathId(runtime, "/Root/Serverless1/Table1"); + auto pathId2 = ResolvePathId(runtime, "/Root/Serverless2/Table2"); + ValidateCountMin(runtime, pathId1); + ValidateCountMin(runtime, pathId2); + } + +} + +} // NStat +} // NKikimr diff --git a/ydb/core/statistics/aggregator/ut/ya.make b/ydb/core/statistics/aggregator/ut/ya.make index ccc1d79b9058..830728bf21fd 100644 --- a/ydb/core/statistics/aggregator/ut/ya.make +++ b/ydb/core/statistics/aggregator/ut/ya.make @@ -23,6 +23,7 @@ PEERDIR( SRCS( ut_analyze_datashard.cpp ut_analyze_columnshard.cpp + ut_traverse_datashard.cpp ut_traverse_columnshard.cpp ) diff --git a/ydb/core/statistics/ut_common/ut_common.cpp b/ydb/core/statistics/ut_common/ut_common.cpp index d28a1e1c05fe..df32740beb5b 100644 --- a/ydb/core/statistics/ut_common/ut_common.cpp +++ b/ydb/core/statistics/ut_common/ut_common.cpp @@ -323,14 +323,25 @@ void ValidateCountMinAbsense(TTestActorRuntime& runtime, TPathId pathId) { UNIT_ASSERT(!rsp.Success); } -void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 tabletId) { +void Analyze(TTestActorRuntime& runtime, const std::vector& pathIds, ui64 saTabletId) { + auto ev = std::make_unique(); + auto& record = ev->Record; + for (const TPathId& pathId : pathIds) + PathIdFromPathId(pathId, record.AddTables()->MutablePathId()); + + auto sender = runtime.AllocateEdgeActor(); + runtime.SendToPipe(saTabletId, sender, ev.release()); + runtime.GrabEdgeEventRethrow(sender); +} + +void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 shardTabletId) { auto ev = std::make_unique(); auto& record = ev->Record; PathIdFromPathId(pathId, record.MutableTable()->MutablePathId()); record.AddTypes(NKikimrStat::EColumnStatisticType::TYPE_COUNT_MIN_SKETCH); auto sender = runtime.AllocateEdgeActor(); - runtime.SendToPipe(tabletId, sender, ev.release()); + runtime.SendToPipe(shardTabletId, sender, ev.release()); runtime.GrabEdgeEventRethrow(sender); } diff --git a/ydb/core/statistics/ut_common/ut_common.h b/ydb/core/statistics/ut_common/ut_common.h index bbe704f9526a..f03bb695d30e 100644 --- a/ydb/core/statistics/ut_common/ut_common.h +++ b/ydb/core/statistics/ut_common/ut_common.h @@ -74,7 +74,8 @@ std::shared_ptr ExtractCountMin(TTestActorRuntime& runtime, TPa void ValidateCountMin(TTestActorRuntime& runtime, TPathId pathId); void ValidateCountMinAbsense(TTestActorRuntime& runtime, TPathId pathId); -void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 tabletId); +void Analyze(TTestActorRuntime& runtime, const std::vector& pathIds, ui64 saTabletId); +void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 shardTabletId); } // namespace NStat } // namespace NKikimr