Skip to content

Commit

Permalink
Analyze statistics tests (#7227)
Browse files Browse the repository at this point in the history
  • Loading branch information
azevaykin authored Jul 30, 2024
1 parent a544002 commit 8beeb7f
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 124 deletions.
5 changes: 4 additions & 1 deletion ydb/core/statistics/aggregator/ut/ut_analyze_columnshard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
125 changes: 5 additions & 120 deletions ydb/core/statistics/aggregator/ut/ut_analyze_datashard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -36,18 +36,12 @@ Y_UNIT_TEST_SUITE(AnalyzeDatashard) {

runtime.SimulateSleep(TDuration::Seconds(30));

auto ev = std::make_unique<TEvStatistics::TEvAnalyze>();
auto& record = ev->Record;
PathIdFromPathId(pathId, record.AddTables()->MutablePathId());

auto sender = runtime.AllocateEdgeActor();
runtime.SendToPipe(saTabletId, sender, ev.release());
runtime.GrabEdgeEventRethrow<TEvStatistics::TEvAnalyzeResponse>(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");
Expand All @@ -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<TEvStatistics::TEvAnalyze>();
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<TEvStatistics::TEvAnalyzeResponse>(sender);
runtime.GrabEdgeEventRethrow<TEvStatistics::TEvAnalyzeResponse>(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);
Expand All @@ -202,12 +92,7 @@ Y_UNIT_TEST_SUITE(AnalyzeDatashard) {
runtime.SimulateSleep(TDuration::Seconds(5));
init2Thread.join();

auto ev = std::make_unique<TEvStatistics::TEvAnalyze>();
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));

Expand Down
161 changes: 161 additions & 0 deletions ydb/core/statistics/aggregator/ut/ut_traverse_datashard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#include <ydb/core/statistics/ut_common/ut_common.h>

#include <ydb/library/actors/testlib/test_runtime.h>

#include <ydb/core/testlib/tablet_helpers.h>
#include <ydb/core/tx/scheme_cache/scheme_cache.h>
#include <ydb/core/statistics/events.h>
#include <ydb/core/statistics/service/service.h>

#include <thread>

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
1 change: 1 addition & 0 deletions ydb/core/statistics/aggregator/ut/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ PEERDIR(
SRCS(
ut_analyze_datashard.cpp
ut_analyze_columnshard.cpp
ut_traverse_datashard.cpp
ut_traverse_columnshard.cpp
)

Expand Down
15 changes: 13 additions & 2 deletions ydb/core/statistics/ut_common/ut_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TPathId>& pathIds, ui64 saTabletId) {
auto ev = std::make_unique<TEvStatistics::TEvAnalyze>();
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<TEvStatistics::TEvAnalyzeResponse>(sender);
}

void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 shardTabletId) {
auto ev = std::make_unique<TEvStatistics::TEvAnalyzeTable>();
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<TEvStatistics::TEvAnalyzeTableResponse>(sender);
}

Expand Down
3 changes: 2 additions & 1 deletion ydb/core/statistics/ut_common/ut_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ std::shared_ptr<TCountMinSketch> 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<TPathId>& pathIds, ui64 saTabletId);
void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 shardTabletId);

} // namespace NStat
} // namespace NKikimr

0 comments on commit 8beeb7f

Please sign in to comment.