Skip to content

Commit 9faa23a

Browse files
committed
Add tests for tablet to clear all data from old groups on cleanup
1 parent d3eb5ac commit 9faa23a

File tree

3 files changed

+324
-83
lines changed

3 files changed

+324
-83
lines changed

ydb/core/tx/datashard/datashard_ut_background_compaction.cpp

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Y_UNIT_TEST_SUITE(DataShardBackgroundCompaction) {
2929
Y_UNIT_TEST(ShouldCompact) {
3030
TPortManager pm;
3131
TServerSettings serverSettings(pm.GetPort(2134));
32-
serverSettings.SetDomainName("Root", 10)
32+
serverSettings.SetDomainName("Root")
3333
.SetUseRealThreads(false);
3434

3535
Tests::TServer::TPtr server = new TServer(serverSettings);
@@ -39,90 +39,16 @@ Y_UNIT_TEST_SUITE(DataShardBackgroundCompaction) {
3939
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
4040
runtime.SetLogPriority(NKikimrServices::TX_PROXY, NLog::PRI_DEBUG);
4141

42-
ui32 oldGroupId = 2181038085;
43-
ui32 newGroupId = 2181038081;
44-
45-
TActorId oldGroupActorId;
46-
TActorId newGroupActorId;
47-
48-
auto captureEvents = [&](TAutoPtr<IEventHandle> &ev) -> auto {
49-
switch (ev->GetTypeRewrite()) {
50-
case TEvBlobStorage::TEvPutResult::EventType: {
51-
auto* msg = ev->Get<TEvBlobStorage::TEvPutResult>();
52-
if (!oldGroupActorId && msg->GroupId == oldGroupId) {
53-
oldGroupActorId = ev->Sender;
54-
} else if (!newGroupActorId && msg->GroupId == newGroupId) {
55-
newGroupActorId = ev->Sender;
56-
}
57-
}
58-
}
59-
return TTestActorRuntime::EEventAction::PROCESS;
60-
};
61-
runtime.SetObserverFunc(captureEvents);
62-
6342
InitRoot(server, sender);
6443

6544
CreateShardedTable(server, sender, "/Root", "table-1", 1);
45+
ExecSQL(server, sender, "UPSERT INTO `/Root/table-1` (key, value) VALUES (1, 100), (3, 300), (5, 500);");
6646

6747
auto shards = GetTableShards(server, sender, "/Root/table-1");
6848

69-
ui64 shardId = shards.at(0);
70-
71-
ExecSQL(server, sender, "UPSERT INTO `/Root/table-1` (key, value) VALUES (1, 100);");
72-
73-
IActor* oldGroupActor = runtime.FindActor(oldGroupActorId, 0U);
74-
TIntrusivePtr<NFake::TProxyDS> oldModel = Model(oldGroupActor);
75-
UNIT_ASSERT(oldModel);
76-
77-
{
78-
auto request1 = MakeHolder<TEvDataShard::TEvForceDataCleanup>(2);
79-
runtime.SendToPipe(shardId, sender, request1.Release(), 0, GetPipeConfigWithRetries());
80-
auto ev = runtime.GrabEdgeEventRethrow<TEvDataShard::TEvForceDataCleanupResult>(sender);
81-
auto &msg = *ev->Get();
82-
UNIT_ASSERT_EQUAL(msg.Record.GetStatus(), NKikimrTxDataShard::TEvForceDataCleanupResult::OK);
83-
UNIT_ASSERT_VALUES_EQUAL(msg.Record.GetTabletId(), shardId);
84-
UNIT_ASSERT_VALUES_EQUAL(msg.Record.GetDataCleanupGeneration(), 2);
85-
}
86-
87-
// {
88-
// auto shards = GetTableShards(server, sender, "/Root/table-1");
89-
90-
// auto [tables, ownerId] = GetTables(server, shards.at(0));
91-
// auto compactionResult = CompactTable(server, tables["table-1"], shards.at(0), ownerId);
92-
// UNIT_ASSERT_VALUES_EQUAL(compactionResult.GetStatus(), NKikimrTxDataShard::TEvCompactTableResult::OK);
93-
// }
94-
95-
// ExecSQL(server, sender, "UPSERT INTO `/Root/table-1` (key, value) VALUES (1, 200);");
96-
97-
{
98-
{
99-
TActorId s = runtime.AllocateEdgeActor(0);
100-
ui64 hiveId = 72057594037968897;
101-
runtime.SendToPipe(hiveId, s, new TEvHive::TEvReassignTabletSpace(shardId, {}), 0, GetPipeConfigWithRetries());
102-
}
103-
104-
runtime.SimulateSleep(TDuration::Minutes(1));
105-
106-
InvalidateTabletResolverCache(runtime, shardId, 0);
107-
108-
RebootTablet(runtime, shardId, sender);
109-
110-
{
111-
auto request1 = MakeHolder<TEvDataShard::TEvForceDataCleanup>(4);
112-
runtime.SendToPipe(shardId, sender, request1.Release(), 0, GetPipeConfigWithRetries());
113-
auto ev = runtime.GrabEdgeEventRethrow<TEvDataShard::TEvForceDataCleanupResult>(sender);
114-
auto &msg = *ev->Get();
115-
UNIT_ASSERT_EQUAL(msg.Record.GetStatus(), NKikimrTxDataShard::TEvForceDataCleanupResult::OK);
116-
UNIT_ASSERT_VALUES_EQUAL(msg.Record.GetTabletId(), shardId);
117-
UNIT_ASSERT_VALUES_EQUAL(msg.Record.GetDataCleanupGeneration(), 4);
118-
}
119-
120-
RebootTablet(runtime, shardId, sender);
121-
}
122-
123-
IActor* newGroupActor = runtime.FindActor(newGroupActorId, 0U);
124-
TIntrusivePtr<NFake::TProxyDS> newModel = Model(newGroupActor);
125-
UNIT_ASSERT(newModel);
49+
auto [tables, ownerId] = GetTables(server, shards.at(0));
50+
auto compactionResult = CompactTable(server, tables["table-1"], shards.at(0), ownerId);
51+
UNIT_ASSERT_VALUES_EQUAL(compactionResult.GetStatus(), NKikimrTxDataShard::TEvCompactTableResult::OK);
12652
}
12753

12854
Y_UNIT_TEST(ShouldNotCompactWhenBorrowed) {

0 commit comments

Comments
 (0)