Skip to content

Commit 1d89df8

Browse files
authored
Data cleanup fixes (ydb-platform#16627)
Fixes for data cleanup edge cases: - DataShard: clean readsets in DataCleanup (ydb-platform#15438) - DataShard and SchemeShard: handle borrowed parts in data erasure (ydb-platform#15451)
1 parent dfed0b4 commit 1d89df8

20 files changed

+582
-120
lines changed

ydb/core/protos/tx_datashard.proto

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,8 +2280,10 @@ message TEvForceDataCleanup {
22802280
// Intermediate requests and corresponding TEvForceDataCleanupResult's may be skipped.
22812281
message TEvForceDataCleanupResult {
22822282
enum EStatus {
2283-
OK = 0;
2284-
FAILED = 1;
2283+
UNKNOWN = 0;
2284+
OK = 1;
2285+
WRONG_SHARD_STATE = 2;
2286+
BORROWED = 3;
22852287
};
22862288
optional uint64 DataCleanupGeneration = 1; // from corresponding request (or greater)
22872289
optional uint64 TabletId = 2;

ydb/core/testlib/storage_helpers.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "storage_helpers.h"
2+
3+
#include <ydb/core/blobstorage/dsproxy/mock/model.h>
4+
5+
namespace NKikimr {
6+
int CountBlobsWithSubstring(ui64 tabletId, const TVector<TIntrusivePtr<NFake::TProxyDS>>& proxyDSs, const TString& substring) {
7+
int res = 0;
8+
for (const auto& proxyDS : proxyDSs) {
9+
for (const auto& [id, blob] : proxyDS->AllMyBlobs()) {
10+
if (id.TabletID() == tabletId && !blob.DoNotKeep && blob.Buffer.ConvertToString().Contains(substring)) {
11+
++res;
12+
}
13+
}
14+
}
15+
return res;
16+
}
17+
18+
bool BlobStorageContains(const TVector<TIntrusivePtr<NFake::TProxyDS>>& proxyDSs, const TString& value) {
19+
for (const auto& proxyDS : proxyDSs) {
20+
for (const auto& [id, blob] : proxyDS->AllMyBlobs()) {
21+
if (!blob.DoNotKeep && blob.Buffer.ConvertToString().Contains(value)) {
22+
return true;
23+
}
24+
}
25+
}
26+
return false;
27+
}
28+
} // namespace NKikimr

ydb/core/testlib/storage_helpers.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
#include <ydb/core/blobstorage/dsproxy/mock/dsproxy_mock.h>
4+
5+
namespace NKikimr {
6+
int CountBlobsWithSubstring(ui64 tabletId, const TVector<TIntrusivePtr<NFake::TProxyDS>>& proxyDSs, const TString& substring);
7+
bool BlobStorageContains(const TVector<TIntrusivePtr<NFake::TProxyDS>>& proxyDSs, const TString& value);
8+
} // namespace NKikimr

ydb/core/testlib/test_client.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ namespace Tests {
109109
using TControls = NKikimrConfig::TImmediateControlsConfig;
110110
using TLoggerInitializer = std::function<void (TTestActorRuntime&)>;
111111
using TStoragePoolKinds = TDomainsInfo::TDomain::TStoragePoolKinds;
112-
using TProxyDSPtr = TIntrusivePtr<NFake::TProxyDS>;
113112

114113
ui16 Port;
115114
ui16 GrpcPort = 0;
@@ -170,7 +169,7 @@ namespace Tests {
170169
TString ServerCertFilePath;
171170
bool Verbose = true;
172171
bool UseSectorMap = false;
173-
TVector<TProxyDSPtr> ProxyDSMocks;
172+
TVector<TIntrusivePtr<NFake::TProxyDS>> ProxyDSMocks;
174173

175174
std::function<IActor*(const TTicketParserSettings&)> CreateTicketParser = NKikimr::CreateTicketParser;
176175
std::shared_ptr<TGrpcServiceFactory> GrpcServiceFactory;
@@ -261,7 +260,7 @@ namespace Tests {
261260
return *this;
262261
}
263262

264-
TServerSettings& SetProxyDSMocks(const TVector<TProxyDSPtr>& proxyDSMocks) {
263+
TServerSettings& SetProxyDSMocks(const TVector<TIntrusivePtr<NFake::TProxyDS>>& proxyDSMocks) {
265264
ProxyDSMocks = proxyDSMocks;
266265
return *this;
267266
}

ydb/core/testlib/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SRCS(
1010
fake_scheme_shard.h
1111
minikql_compile.h
1212
mock_pq_metacache.h
13+
storage_helpers.cpp
1314
tablet_flat_dummy.cpp
1415
tablet_helpers.cpp
1516
tablet_helpers.h

ydb/core/tx/datashard/datashard__data_cleanup.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,19 @@ class TDataShard::TTxDataCleanup : public NTabletFlatExecutor::TTransactionBase<
2626
Response = std::make_unique<TEvDataShard::TEvForceDataCleanupResult>(
2727
record.GetDataCleanupGeneration(),
2828
Self->TabletID(),
29-
NKikimrTxDataShard::TEvForceDataCleanupResult::FAILED);
29+
NKikimrTxDataShard::TEvForceDataCleanupResult::WRONG_SHARD_STATE);
30+
return true;
31+
}
32+
33+
if (Self->Executor()->HasLoanedParts()) {
34+
LOG_WARN_S(ctx, NKikimrServices::TX_DATASHARD,
35+
"DataCleanup of tablet# " << Self->TabletID()
36+
<< ": has borrowed parts"
37+
<< ", requested from " << Ev->Sender);
38+
Response = std::make_unique<TEvDataShard::TEvForceDataCleanupResult>(
39+
record.GetDataCleanupGeneration(),
40+
Self->TabletID(),
41+
NKikimrTxDataShard::TEvForceDataCleanupResult::BORROWED);
3042
return true;
3143
}
3244

@@ -55,6 +67,8 @@ class TDataShard::TTxDataCleanup : public NTabletFlatExecutor::TTransactionBase<
5567
"DataCleanup of tablet# " << Self->TabletID()
5668
<< ": expired snapshots removed");
5769
}
70+
Self->OutReadSets.Cleanup(db, ctx);
71+
5872
Self->Executor()->CleanupData(Ev->Get()->Record.GetDataCleanupGeneration());
5973
Self->DataCleanupWaiters.insert({Ev->Get()->Record.GetDataCleanupGeneration(), Ev->Sender});
6074
return true;

0 commit comments

Comments
 (0)