Skip to content

Commit 7d17776

Browse files
authored
Draft of TEvAnalyzeTable in ColumnShard (#7198)
1 parent 33bdce5 commit 7d17776

File tree

8 files changed

+106
-27
lines changed

8 files changed

+106
-27
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <ydb/core/statistics/ut_common/ut_common.h>
2+
3+
#include <ydb/library/actors/testlib/test_runtime.h>
4+
5+
#include <thread>
6+
7+
namespace NKikimr {
8+
namespace NStat {
9+
10+
namespace {
11+
12+
13+
} // namespace
14+
15+
Y_UNIT_TEST_SUITE(AnalyzeColumnshard) {
16+
17+
Y_UNIT_TEST(AnalyzeOneColumnTable) {
18+
TTestEnv env(1, 1);
19+
auto init = [&] () {
20+
CreateDatabase(env, "Database");
21+
CreateColumnStoreTable(env, "Database", "Table", 1);
22+
};
23+
std::thread initThread(init);
24+
25+
auto& runtime = *env.GetServer().GetRuntime();
26+
runtime.SimulateSleep(TDuration::Seconds(30));
27+
initThread.join();
28+
29+
auto sender = runtime.AllocateEdgeActor();
30+
ui64 columnShardId = GetColumnTableShards(runtime, sender, "/Root/Database/Table").at(0);
31+
32+
auto pathId = ResolvePathId(runtime, "/Root/Database/Table", nullptr);
33+
34+
AnalyzeTable(runtime, pathId, columnShardId);
35+
}
36+
}
37+
38+
} // NStat
39+
} // NKikimr

ydb/core/statistics/aggregator/ut/ut_aggregator.cpp renamed to ydb/core/statistics/aggregator/ut/ut_analyze_datashard.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace {
1717

1818
} // namespace
1919

20-
Y_UNIT_TEST_SUITE(StatisticsAggregator) {
20+
Y_UNIT_TEST_SUITE(AnalyzeDatashard) {
2121

2222
Y_UNIT_TEST(ScanOneTable) {
2323
TTestEnv env(1, 1);
@@ -213,29 +213,6 @@ Y_UNIT_TEST_SUITE(StatisticsAggregator) {
213213

214214
ValidateCountMinAbsense(runtime, pathId);
215215
}
216-
217-
Y_UNIT_TEST(ScanOneColumnTable) {
218-
TTestEnv env(1, 1);
219-
auto init = [&] () {
220-
CreateDatabase(env, "Database");
221-
CreateColumnStoreTable(env, "Database", "Table", 10);
222-
};
223-
std::thread initThread(init);
224-
225-
auto& runtime = *env.GetServer().GetRuntime();
226-
runtime.SimulateSleep(TDuration::Seconds(30));
227-
initThread.join();
228-
229-
auto pathId = ResolvePathId(runtime, "/Root/Database/Table");
230-
231-
runtime.SimulateSleep(TDuration::Seconds(30));
232-
233-
auto countMin = ExtractCountMin(runtime, pathId);
234-
235-
ui32 value = 1;
236-
auto probe = countMin->Probe((const char *)&value, sizeof(value));
237-
UNIT_ASSERT_VALUES_EQUAL(probe, 10);
238-
}
239216
}
240217

241218
} // NStat
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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(TraverseColumnShard) {
21+
22+
Y_UNIT_TEST(OneColumnTableTraversal) {
23+
TTestEnv env(1, 1);
24+
auto init = [&] () {
25+
CreateDatabase(env, "Database");
26+
CreateColumnStoreTable(env, "Database", "Table", 10);
27+
};
28+
std::thread initThread(init);
29+
30+
auto& runtime = *env.GetServer().GetRuntime();
31+
runtime.SimulateSleep(TDuration::Seconds(30));
32+
initThread.join();
33+
34+
auto pathId = ResolvePathId(runtime, "/Root/Database/Table");
35+
36+
runtime.SimulateSleep(TDuration::Seconds(30));
37+
38+
auto countMin = ExtractCountMin(runtime, pathId);
39+
40+
ui32 value = 1;
41+
auto probe = countMin->Probe((const char *)&value, sizeof(value));
42+
UNIT_ASSERT_VALUES_EQUAL(probe, 10);
43+
}
44+
}
45+
46+
} // NStat
47+
} // NKikimr

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ PEERDIR(
2121
)
2222

2323
SRCS(
24-
ut_aggregator.cpp
24+
ut_analyze_datashard.cpp
25+
ut_analyze_columnshard.cpp
26+
ut_traverse_columnshard.cpp
2527
)
2628

2729
END()

ydb/core/statistics/ut_common/ut_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void ValidateCountMinAbsense(TTestActorRuntime& runtime, TPathId pathId) {
323323
UNIT_ASSERT(!rsp.Success);
324324
}
325325

326-
void AnalyzeTable(TTestActorRuntime& runtime, ui64 tabletId, const TPathId& pathId) {
326+
void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 tabletId) {
327327
auto ev = std::make_unique<TEvStatistics::TEvAnalyzeTable>();
328328
auto& record = ev->Record;
329329
PathIdFromPathId(pathId, record.MutableTable()->MutablePathId());

ydb/core/statistics/ut_common/ut_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ 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, ui64 tabletId, const TPathId& pathId);
77+
void AnalyzeTable(TTestActorRuntime& runtime, const TPathId& pathId, ui64 tabletId);
7878

7979
} // namespace NStat
8080
} // namespace NKikimr

ydb/core/tx/columnshard/columnshard__statistics.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55

66
namespace NKikimr::NColumnShard {
77

8+
void TColumnShard::Handle(NStat::TEvStatistics::TEvAnalyzeTable::TPtr& ev, const TActorContext&) {
9+
10+
// TODO Start a potentially long analysis process.
11+
// ...
12+
13+
14+
15+
// Return the response when the analysis is completed
16+
auto response = std::make_unique<NStat::TEvStatistics::TEvAnalyzeTableResponse>();
17+
Send(ev->Sender, response.release(), 0, ev->Cookie);
18+
}
19+
820
void TColumnShard::Handle(NStat::TEvStatistics::TEvStatisticsRequest::TPtr& ev, const TActorContext&) {
921
auto response = std::make_unique<NStat::TEvStatistics::TEvStatisticsResponse>();
1022
auto& record = response->Record;

ydb/core/tx/columnshard/columnshard_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ class TColumnShard
224224
void Handle(TEvPrivate::TEvTieringModified::TPtr& ev, const TActorContext&);
225225
void Handle(TEvPrivate::TEvNormalizerResult::TPtr& ev, const TActorContext&);
226226

227+
void Handle(NStat::TEvStatistics::TEvAnalyzeTable::TPtr& ev, const TActorContext& ctx);
227228
void Handle(NStat::TEvStatistics::TEvStatisticsRequest::TPtr& ev, const TActorContext& ctx);
228229

229230
void Handle(NActors::TEvents::TEvUndelivered::TPtr& ev, const TActorContext&);
@@ -380,6 +381,7 @@ class TColumnShard
380381
HFunc(TEvPrivate::TEvGarbageCollectionFinished, Handle);
381382
HFunc(TEvPrivate::TEvTieringModified, Handle);
382383

384+
HFunc(NStat::TEvStatistics::TEvAnalyzeTable, Handle);
383385
HFunc(NStat::TEvStatistics::TEvStatisticsRequest, Handle);
384386

385387
HFunc(NActors::TEvents::TEvUndelivered, Handle);

0 commit comments

Comments
 (0)