Skip to content

Commit 2227b46

Browse files
authored
Add datashard interface for data cleanup operation (#12896)
1 parent 4472125 commit 2227b46

File tree

7 files changed

+110
-0
lines changed

7 files changed

+110
-0
lines changed

ydb/core/protos/tx_datashard.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,3 +2265,18 @@ message TEvInMemoryStateResponse {
22652265
// Will be set for incomplete replies
22662266
optional bytes ContinuationToken = 3;
22672267
}
2268+
2269+
// Forces cleanup-related operations in datashard tablet:
2270+
// compaction, GC, GC log and other temporary data erasure.
2271+
// Once the operation is done, any deleted data not used initially
2272+
// will be included in garbage collection requests for the blobstorage.
2273+
// Note: deleted data may still be used for a while, e.g. for history for MVCC.
2274+
message TEvForceDataCleanup {
2275+
optional uint64 DataCleanupGeneration = 1; // increasing sequence
2276+
}
2277+
2278+
// Returns DataCleanupGeneration of the last successfully completed TEvForceDataCleanup request.
2279+
// Intermediate requests and corresponding TEvForceDataCleanupResult's may be skipped.
2280+
message TEvForceDataCleanupResult {
2281+
optional uint64 DataCleanupGeneration = 1; // from corresponding request
2282+
}

ydb/core/tx/datashard/datashard.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ namespace TEvDataShard {
346346
EvInMemoryStateRequest,
347347
EvInMemoryStateResponse,
348348

349+
EvForceDataCleanup,
350+
EvForceDataCleanupResult,
351+
349352
EvEnd
350353
};
351354

@@ -1562,6 +1565,24 @@ namespace TEvDataShard {
15621565
}
15631566
};
15641567

1568+
struct TEvForceDataCleanup : TEventPB<TEvForceDataCleanup, NKikimrTxDataShard::TEvForceDataCleanup,
1569+
TEvDataShard::EvForceDataCleanup> {
1570+
TEvForceDataCleanup() = default;
1571+
1572+
TEvForceDataCleanup(ui64 dataCleanupGeneration) {
1573+
Record.SetDataCleanupGeneration(dataCleanupGeneration);
1574+
}
1575+
};
1576+
1577+
struct TEvForceDataCleanupResult : TEventPB<TEvForceDataCleanupResult, NKikimrTxDataShard::TEvForceDataCleanupResult,
1578+
TEvDataShard::EvForceDataCleanupResult> {
1579+
TEvForceDataCleanupResult() = default;
1580+
1581+
TEvForceDataCleanupResult(ui64 dataCleanupGeneration) {
1582+
Record.SetDataCleanupGeneration(dataCleanupGeneration);
1583+
}
1584+
};
1585+
15651586
/**
15661587
* This message is used to ask datashard to compact any borrowed parts it has
15671588
* for the specified user table.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "datashard_impl.h"
2+
3+
namespace NKikimr::NDataShard {
4+
5+
void TDataShard::Handle(TEvDataShard::TEvForceDataCleanup::TPtr& ev, const TActorContext& ctx) {
6+
// TODO: implement
7+
const auto& record = ev->Get()->Record;
8+
auto result = MakeHolder<TEvDataShard::TEvForceDataCleanupResult>(record.GetDataCleanupGeneration());
9+
ctx.Send(ev->Sender, std::move(result));
10+
}
11+
12+
} // namespace NKikimr::NDataShard

ydb/core/tx/datashard/datashard_impl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,8 @@ class TDataShard
13891389

13901390
void Handle(TEvIncrementalRestoreScan::TEvFinished::TPtr& ev, const TActorContext& ctx);
13911391

1392+
void Handle(TEvDataShard::TEvForceDataCleanup::TPtr& ev, const TActorContext& ctx);
1393+
13921394
void HandleByReplicationSourceOffsetsServer(STATEFN_SIG);
13931395

13941396
void DoPeriodicTasks(const TActorContext &ctx);
@@ -3211,6 +3213,7 @@ class TDataShard
32113213
HFunc(TEvPrivate::TEvStatisticsScanFinished, Handle);
32123214
HFuncTraced(TEvPrivate::TEvRemoveSchemaSnapshots, Handle);
32133215
HFunc(TEvIncrementalRestoreScan::TEvFinished, Handle);
3216+
HFunc(TEvDataShard::TEvForceDataCleanup, Handle);
32143217
default:
32153218
if (!HandleDefaultEvents(ev, SelfId())) {
32163219
ALOG_WARN(NKikimrServices::TX_DATASHARD, "TDataShard::StateWork unhandled event type: " << ev->GetTypeRewrite() << " event: " << ev->ToString());
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <ydb/core/tx/datashard/ut_common/datashard_ut_common.h>
2+
3+
namespace NKikimr {
4+
5+
using namespace Tests;
6+
7+
Y_UNIT_TEST_SUITE(DataCleanup) {
8+
Y_UNIT_TEST(ForceDataCleanup) {
9+
TPortManager pm;
10+
TServerSettings serverSettings(pm.GetPort(2134));
11+
serverSettings.SetDomainName("Root")
12+
.SetUseRealThreads(false);
13+
14+
Tests::TServer::TPtr server = new TServer(serverSettings);
15+
auto &runtime = *server->GetRuntime();
16+
auto sender = runtime.AllocateEdgeActor();
17+
18+
InitRoot(server, sender);
19+
20+
auto [shards, tableId] = CreateShardedTable(server, sender, "/Root", "table-1", 1);
21+
22+
ui64 expectedDataCleanupGeneration = 42;
23+
auto request = MakeHolder<TEvDataShard::TEvForceDataCleanup>(expectedDataCleanupGeneration);
24+
25+
runtime.SendToPipe(shards.at(0), sender, request.Release(), 0, GetPipeConfigWithRetries());
26+
27+
auto ev = runtime.GrabEdgeEventRethrow<TEvDataShard::TEvForceDataCleanupResult>(sender);
28+
UNIT_ASSERT_VALUES_EQUAL(ev->Get()->Record.GetDataCleanupGeneration(), expectedDataCleanupGeneration);
29+
}
30+
}
31+
32+
} // namespace NKikimr
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
UNITTEST_FOR(ydb/core/tx/datashard)
2+
3+
FORK_SUBTESTS()
4+
5+
SPLIT_FACTOR(1)
6+
7+
IF (SANITIZER_TYPE == "thread" OR WITH_VALGRIND)
8+
SIZE(LARGE)
9+
TAG(ya:fat)
10+
ELSE()
11+
SIZE(MEDIUM)
12+
ENDIF()
13+
14+
PEERDIR(
15+
ydb/core/testlib/default
16+
ydb/core/tx/datashard/ut_common
17+
)
18+
19+
YQL_LAST_ABI_VERSION()
20+
21+
SRCS(
22+
datashard_ut_data_cleanup.cpp
23+
)
24+
25+
END()

ydb/core/tx/datashard/ya.make

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ SRCS(
5555
datashard__compact_borrowed.cpp
5656
datashard__compaction.cpp
5757
datashard__conditional_erase_rows.cpp
58+
datashard__data_cleanup.cpp
5859
datashard__engine_host.cpp
5960
datashard__engine_host.h
6061
datashard__get_state_tx.cpp
@@ -309,6 +310,7 @@ RECURSE_FOR_TESTS(
309310
ut_change_exchange
310311
ut_column_stats
311312
ut_compaction
313+
ut_data_cleanup
312314
ut_erase_rows
313315
ut_external_blobs
314316
ut_followers

0 commit comments

Comments
 (0)