Skip to content

Commit 8beeb7f

Browse files
authored
Analyze statistics tests (#7227)
1 parent a544002 commit 8beeb7f

File tree

6 files changed

+186
-124
lines changed

6 files changed

+186
-124
lines changed

ydb/core/statistics/aggregator/ut/ut_analyze_columnshard.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ Y_UNIT_TEST_SUITE(AnalyzeColumnshard) {
2929
auto sender = runtime.AllocateEdgeActor();
3030
ui64 columnShardId = GetColumnTableShards(runtime, sender, "/Root/Database/Table").at(0);
3131

32-
auto pathId = ResolvePathId(runtime, "/Root/Database/Table", nullptr);
32+
ui64 saTabletId = 0;
33+
auto pathId = ResolvePathId(runtime, "/Root/Database/Table", nullptr, &saTabletId);
3334

3435
AnalyzeTable(runtime, pathId, columnShardId);
36+
37+
Analyze(runtime, {pathId}, saTabletId);
3538
}
3639
}
3740

ydb/core/statistics/aggregator/ut/ut_analyze_datashard.cpp

Lines changed: 5 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace {
1919

2020
Y_UNIT_TEST_SUITE(AnalyzeDatashard) {
2121

22-
Y_UNIT_TEST(ScanOneTable) {
22+
Y_UNIT_TEST(AnalyzeOneTable) {
2323
TTestEnv env(1, 1);
2424
auto init = [&] () {
2525
CreateDatabase(env, "Database");
@@ -36,18 +36,12 @@ Y_UNIT_TEST_SUITE(AnalyzeDatashard) {
3636

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

39-
auto ev = std::make_unique<TEvStatistics::TEvAnalyze>();
40-
auto& record = ev->Record;
41-
PathIdFromPathId(pathId, record.AddTables()->MutablePathId());
42-
43-
auto sender = runtime.AllocateEdgeActor();
44-
runtime.SendToPipe(saTabletId, sender, ev.release());
45-
runtime.GrabEdgeEventRethrow<TEvStatistics::TEvAnalyzeResponse>(sender);
39+
Analyze(runtime, {{pathId}}, saTabletId);
4640

4741
ValidateCountMin(runtime, pathId);
4842
}
4943

50-
Y_UNIT_TEST(ScanTwoTables) {
44+
Y_UNIT_TEST(AnalyzeTwoTables) {
5145
TTestEnv env(1, 1);
5246
auto init = [&] () {
5347
CreateDatabase(env, "Database");
@@ -68,116 +62,12 @@ Y_UNIT_TEST_SUITE(AnalyzeDatashard) {
6862
auto pathId1 = ResolvePathId(runtime, "/Root/Database/Table1", nullptr, &saTabletId1);
6963
auto pathId2 = ResolvePathId(runtime, "/Root/Database/Table2");
7064

71-
auto ev = std::make_unique<TEvStatistics::TEvAnalyze>();
72-
auto& record = ev->Record;
73-
PathIdFromPathId(pathId1, record.AddTables()->MutablePathId());
74-
PathIdFromPathId(pathId2, record.AddTables()->MutablePathId());
75-
76-
auto sender = runtime.AllocateEdgeActor();
77-
runtime.SendToPipe(saTabletId1, sender, ev.release());
78-
runtime.GrabEdgeEventRethrow<TEvStatistics::TEvAnalyzeResponse>(sender);
79-
runtime.GrabEdgeEventRethrow<TEvStatistics::TEvAnalyzeResponse>(sender);
65+
Analyze(runtime, {pathId1, pathId2}, saTabletId1);
8066

8167
ValidateCountMin(runtime, pathId1);
8268
ValidateCountMin(runtime, pathId2);
8369
}
8470

85-
Y_UNIT_TEST(ScanOneTableServerless) {
86-
TTestEnv env(1, 1);
87-
88-
auto init = [&] () {
89-
CreateDatabase(env, "Shared");
90-
};
91-
std::thread initThread(init);
92-
93-
auto& runtime = *env.GetServer().GetRuntime();
94-
runtime.SimulateSleep(TDuration::Seconds(5));
95-
initThread.join();
96-
97-
TPathId domainKey;
98-
ResolvePathId(runtime, "/Root/Shared", &domainKey);
99-
100-
auto init2 = [&] () {
101-
CreateServerlessDatabase(env, "Serverless", domainKey);
102-
CreateUniformTable(env, "Serverless", "Table");
103-
};
104-
std::thread init2Thread(init2);
105-
106-
runtime.SimulateSleep(TDuration::Seconds(5));
107-
init2Thread.join();
108-
109-
runtime.SimulateSleep(TDuration::Seconds(60));
110-
111-
auto pathId = ResolvePathId(runtime, "/Root/Serverless/Table");
112-
ValidateCountMin(runtime, pathId);
113-
}
114-
115-
Y_UNIT_TEST(ScanTwoTablesServerless) {
116-
TTestEnv env(1, 1);
117-
118-
auto init = [&] () {
119-
CreateDatabase(env, "Shared");
120-
};
121-
std::thread initThread(init);
122-
123-
auto& runtime = *env.GetServer().GetRuntime();
124-
runtime.SimulateSleep(TDuration::Seconds(5));
125-
initThread.join();
126-
127-
TPathId domainKey;
128-
ResolvePathId(runtime, "/Root/Shared", &domainKey);
129-
130-
auto init2 = [&] () {
131-
CreateServerlessDatabase(env, "Serverless", domainKey);
132-
CreateUniformTable(env, "Serverless", "Table1");
133-
CreateUniformTable(env, "Serverless", "Table2");
134-
};
135-
std::thread init2Thread(init2);
136-
137-
runtime.SimulateSleep(TDuration::Seconds(5));
138-
init2Thread.join();
139-
140-
runtime.SimulateSleep(TDuration::Seconds(60));
141-
142-
auto pathId1 = ResolvePathId(runtime, "/Root/Serverless/Table1");
143-
auto pathId2 = ResolvePathId(runtime, "/Root/Serverless/Table2");
144-
ValidateCountMin(runtime, pathId1);
145-
ValidateCountMin(runtime, pathId2);
146-
}
147-
148-
Y_UNIT_TEST(ScanTwoTablesTwoServerlessDbs) {
149-
TTestEnv env(1, 1);
150-
151-
auto init = [&] () {
152-
CreateDatabase(env, "Shared");
153-
};
154-
std::thread initThread(init);
155-
156-
auto& runtime = *env.GetServer().GetRuntime();
157-
runtime.SimulateSleep(TDuration::Seconds(5));
158-
initThread.join();
159-
160-
TPathId domainKey;
161-
ResolvePathId(runtime, "/Root/Shared", &domainKey);
162-
163-
auto init2 = [&] () {
164-
CreateServerlessDatabase(env, "Serverless1", domainKey);
165-
CreateServerlessDatabase(env, "Serverless2", domainKey);
166-
CreateUniformTable(env, "Serverless1", "Table1");
167-
CreateUniformTable(env, "Serverless2", "Table2");
168-
};
169-
std::thread init2Thread(init2);
170-
171-
runtime.SimulateSleep(TDuration::Seconds(5));
172-
init2Thread.join();
173-
174-
runtime.SimulateSleep(TDuration::Seconds(60));
175-
176-
auto pathId1 = ResolvePathId(runtime, "/Root/Serverless1/Table1");
177-
auto pathId2 = ResolvePathId(runtime, "/Root/Serverless2/Table2");
178-
ValidateCountMin(runtime, pathId1);
179-
ValidateCountMin(runtime, pathId2);
180-
}
18171

18272
Y_UNIT_TEST(DropTableNavigateError) {
18373
TTestEnv env(1, 1);
@@ -202,12 +92,7 @@ Y_UNIT_TEST_SUITE(AnalyzeDatashard) {
20292
runtime.SimulateSleep(TDuration::Seconds(5));
20393
init2Thread.join();
20494

205-
auto ev = std::make_unique<TEvStatistics::TEvAnalyze>();
206-
auto& record = ev->Record;
207-
PathIdFromPathId(pathId, record.AddTables()->MutablePathId());
208-
209-
auto sender = runtime.AllocateEdgeActor();
210-
runtime.SendToPipe(saTabletId, sender, ev.release());
95+
Analyze(runtime, {pathId}, saTabletId);
21196

21297
runtime.SimulateSleep(TDuration::Seconds(60));
21398

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#include <ydb/core/statistics/ut_common/ut_common.h>
2+
3+
#include <ydb/library/actors/testlib/test_runtime.h>
4+
5+
#include <ydb/core/testlib/tablet_helpers.h>
6+
#include <ydb/core/tx/scheme_cache/scheme_cache.h>
7+
#include <ydb/core/statistics/events.h>
8+
#include <ydb/core/statistics/service/service.h>
9+
10+
#include <thread>
11+
12+
namespace NKikimr {
13+
namespace NStat {
14+
15+
namespace {
16+
17+
18+
} // namespace
19+
20+
Y_UNIT_TEST_SUITE(TraverseDatashard) {
21+
22+
Y_UNIT_TEST(TraverseOneTable) {
23+
TTestEnv env(1, 1);
24+
auto init = [&] () {
25+
CreateDatabase(env, "Database");
26+
CreateUniformTable(env, "Database", "Table");
27+
};
28+
std::thread initThread(init);
29+
30+
auto& runtime = *env.GetServer().GetRuntime();
31+
runtime.SimulateSleep(TDuration::Seconds(5));
32+
initThread.join();
33+
34+
runtime.SimulateSleep(TDuration::Seconds(60));
35+
36+
auto pathId = ResolvePathId(runtime, "/Root/Database/Table");
37+
ValidateCountMin(runtime, pathId);
38+
}
39+
40+
Y_UNIT_TEST(TraverseTwoTables) {
41+
TTestEnv env(1, 1);
42+
auto init = [&] () {
43+
CreateDatabase(env, "Database");
44+
CreateUniformTable(env, "Database", "Table1");
45+
CreateUniformTable(env, "Database", "Table2");
46+
};
47+
std::thread initThread(init);
48+
49+
auto& runtime = *env.GetServer().GetRuntime();
50+
runtime.SimulateSleep(TDuration::Seconds(5));
51+
initThread.join();
52+
53+
runtime.SimulateSleep(TDuration::Seconds(60));
54+
55+
auto pathId1 = ResolvePathId(runtime, "/Root/Database/Table1");
56+
auto pathId2 = ResolvePathId(runtime, "/Root/Database/Table2");
57+
ValidateCountMin(runtime, pathId1);
58+
ValidateCountMin(runtime, pathId2);
59+
}
60+
61+
Y_UNIT_TEST(TraverseOneTableServerless) {
62+
TTestEnv env(1, 1);
63+
64+
auto init = [&] () {
65+
CreateDatabase(env, "Shared");
66+
};
67+
std::thread initThread(init);
68+
69+
auto& runtime = *env.GetServer().GetRuntime();
70+
runtime.SimulateSleep(TDuration::Seconds(5));
71+
initThread.join();
72+
73+
TPathId domainKey;
74+
ResolvePathId(runtime, "/Root/Shared", &domainKey);
75+
76+
auto init2 = [&] () {
77+
CreateServerlessDatabase(env, "Serverless", domainKey);
78+
CreateUniformTable(env, "Serverless", "Table");
79+
};
80+
std::thread init2Thread(init2);
81+
82+
runtime.SimulateSleep(TDuration::Seconds(5));
83+
init2Thread.join();
84+
85+
runtime.SimulateSleep(TDuration::Seconds(60));
86+
87+
auto pathId = ResolvePathId(runtime, "/Root/Serverless/Table");
88+
ValidateCountMin(runtime, pathId);
89+
}
90+
91+
Y_UNIT_TEST(TraverseTwoTablesServerless) {
92+
TTestEnv env(1, 1);
93+
94+
auto init = [&] () {
95+
CreateDatabase(env, "Shared");
96+
};
97+
std::thread initThread(init);
98+
99+
auto& runtime = *env.GetServer().GetRuntime();
100+
runtime.SimulateSleep(TDuration::Seconds(5));
101+
initThread.join();
102+
103+
TPathId domainKey;
104+
ResolvePathId(runtime, "/Root/Shared", &domainKey);
105+
106+
auto init2 = [&] () {
107+
CreateServerlessDatabase(env, "Serverless", domainKey);
108+
CreateUniformTable(env, "Serverless", "Table1");
109+
CreateUniformTable(env, "Serverless", "Table2");
110+
};
111+
std::thread init2Thread(init2);
112+
113+
runtime.SimulateSleep(TDuration::Seconds(5));
114+
init2Thread.join();
115+
116+
runtime.SimulateSleep(TDuration::Seconds(60));
117+
118+
auto pathId1 = ResolvePathId(runtime, "/Root/Serverless/Table1");
119+
auto pathId2 = ResolvePathId(runtime, "/Root/Serverless/Table2");
120+
ValidateCountMin(runtime, pathId1);
121+
ValidateCountMin(runtime, pathId2);
122+
}
123+
124+
Y_UNIT_TEST(TraverseTwoTablesTwoServerlessDbs) {
125+
TTestEnv env(1, 1);
126+
127+
auto init = [&] () {
128+
CreateDatabase(env, "Shared");
129+
};
130+
std::thread initThread(init);
131+
132+
auto& runtime = *env.GetServer().GetRuntime();
133+
runtime.SimulateSleep(TDuration::Seconds(5));
134+
initThread.join();
135+
136+
TPathId domainKey;
137+
ResolvePathId(runtime, "/Root/Shared", &domainKey);
138+
139+
auto init2 = [&] () {
140+
CreateServerlessDatabase(env, "Serverless1", domainKey);
141+
CreateServerlessDatabase(env, "Serverless2", domainKey);
142+
CreateUniformTable(env, "Serverless1", "Table1");
143+
CreateUniformTable(env, "Serverless2", "Table2");
144+
};
145+
std::thread init2Thread(init2);
146+
147+
runtime.SimulateSleep(TDuration::Seconds(5));
148+
init2Thread.join();
149+
150+
runtime.SimulateSleep(TDuration::Seconds(60));
151+
152+
auto pathId1 = ResolvePathId(runtime, "/Root/Serverless1/Table1");
153+
auto pathId2 = ResolvePathId(runtime, "/Root/Serverless2/Table2");
154+
ValidateCountMin(runtime, pathId1);
155+
ValidateCountMin(runtime, pathId2);
156+
}
157+
158+
}
159+
160+
} // NStat
161+
} // NKikimr

ydb/core/statistics/aggregator/ut/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ PEERDIR(
2323
SRCS(
2424
ut_analyze_datashard.cpp
2525
ut_analyze_columnshard.cpp
26+
ut_traverse_datashard.cpp
2627
ut_traverse_columnshard.cpp
2728
)
2829

ydb/core/statistics/ut_common/ut_common.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,25 @@ void ValidateCountMinAbsense(TTestActorRuntime& runtime, TPathId pathId) {
323323
UNIT_ASSERT(!rsp.Success);
324324
}
325325

326-
void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 tabletId) {
326+
void Analyze(TTestActorRuntime& runtime, const std::vector<TPathId>& pathIds, ui64 saTabletId) {
327+
auto ev = std::make_unique<TEvStatistics::TEvAnalyze>();
328+
auto& record = ev->Record;
329+
for (const TPathId& pathId : pathIds)
330+
PathIdFromPathId(pathId, record.AddTables()->MutablePathId());
331+
332+
auto sender = runtime.AllocateEdgeActor();
333+
runtime.SendToPipe(saTabletId, sender, ev.release());
334+
runtime.GrabEdgeEventRethrow<TEvStatistics::TEvAnalyzeResponse>(sender);
335+
}
336+
337+
void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 shardTabletId) {
327338
auto ev = std::make_unique<TEvStatistics::TEvAnalyzeTable>();
328339
auto& record = ev->Record;
329340
PathIdFromPathId(pathId, record.MutableTable()->MutablePathId());
330341
record.AddTypes(NKikimrStat::EColumnStatisticType::TYPE_COUNT_MIN_SKETCH);
331342

332343
auto sender = runtime.AllocateEdgeActor();
333-
runtime.SendToPipe(tabletId, sender, ev.release());
344+
runtime.SendToPipe(shardTabletId, sender, ev.release());
334345
runtime.GrabEdgeEventRethrow<TEvStatistics::TEvAnalyzeTableResponse>(sender);
335346
}
336347

ydb/core/statistics/ut_common/ut_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ std::shared_ptr<TCountMinSketch> ExtractCountMin(TTestActorRuntime& runtime, TPa
7474
void ValidateCountMin(TTestActorRuntime& runtime, TPathId pathId);
7575
void ValidateCountMinAbsense(TTestActorRuntime& runtime, TPathId pathId);
7676

77-
void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 tabletId);
77+
void Analyze(TTestActorRuntime& runtime, const std::vector<TPathId>& pathIds, ui64 saTabletId);
78+
void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 shardTabletId);
7879

7980
} // namespace NStat
8081
} // namespace NKikimr

0 commit comments

Comments
 (0)