Skip to content

Commit 7e5d8f2

Browse files
authored
Merge 93d47a0 into 2bc34d4
2 parents 2bc34d4 + 93d47a0 commit 7e5d8f2

File tree

7 files changed

+81
-18
lines changed

7 files changed

+81
-18
lines changed

ydb/core/protos/config.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,7 @@ message TColumnShardConfig {
16851685
message TRepairInfo {
16861686
optional string ClassName = 1;
16871687
optional string Description = 2;
1688+
optional bool DryRun = 3;
16881689
}
16891690
repeated TRepairInfo Repairs = 15;
16901691

ydb/core/tx/columnshard/columnshard__init.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class TTxApplyNormalizer: public TTransactionBase<TColumnShard> {
177177
public:
178178
TTxApplyNormalizer(TColumnShard* self, NOlap::INormalizerChanges::TPtr changes)
179179
: TBase(self)
180+
, IsDryRun(self->NormalizerController.GetNormalizer()->GetIsDryRun())
180181
, Changes(changes) {
181182
}
182183

@@ -187,16 +188,20 @@ class TTxApplyNormalizer: public TTransactionBase<TColumnShard> {
187188
}
188189

189190
private:
191+
const bool IsDryRun;
190192
bool NormalizerFinished = false;
191193
NOlap::INormalizerChanges::TPtr Changes;
192194
};
193195

194196
bool TTxApplyNormalizer::Execute(TTransactionContext& txc, const TActorContext&) {
195197
NActors::TLogContextGuard gLogging =
196198
NActors::TLogContextBuilder::Build(NKikimrServices::TX_COLUMNSHARD)("tablet_id", Self->TabletID())("event", "TTxApplyNormalizer::Execute");
197-
AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("step", "TTxApplyNormalizer.Execute")("details", Self->NormalizerController.DebugString());
198-
if (!Changes->ApplyOnExecute(txc, Self->NormalizerController)) {
199-
return false;
199+
AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("step", "TTxApplyNormalizer.Execute")("details", Self->NormalizerController.DebugString())(
200+
"dry_run", IsDryRun);
201+
if (!IsDryRun) {
202+
if (!Changes->ApplyOnExecute(txc, Self->NormalizerController)) {
203+
return false;
204+
}
200205
}
201206

202207
if (Self->NormalizerController.GetNormalizer()->DecActiveCounters() == 0) {
@@ -211,9 +216,14 @@ void TTxApplyNormalizer::Complete(const TActorContext& ctx) {
211216
NActors::TLogContextGuard gLogging = NActors::TLogContextBuilder::Build(NKikimrServices::TX_COLUMNSHARD)("tablet_id", Self->TabletID())(
212217
"event", "TTxApplyNormalizer::Complete");
213218
AFL_VERIFY(!Self->NormalizerController.IsNormalizationFinished())("details", Self->NormalizerController.DebugString());
214-
AFL_WARN(NKikimrServices::TX_COLUMNSHARD)("event", "apply_normalizer_changes")(
215-
"details", Self->NormalizerController.DebugString())("size", Changes->GetSize());
216-
Changes->ApplyOnComplete(Self->NormalizerController);
219+
AFL_WARN(NKikimrServices::TX_COLUMNSHARD)("event", "apply_normalizer_changes")("details", Self->NormalizerController.DebugString())(
220+
"size", Changes->GetSize())("dry_run", IsDryRun);
221+
if (IsDryRun) {
222+
AFL_WARN(NKikimrServices::TX_COLUMNSHARD)("event", "normalizer_changes_dry_run")(
223+
"normalizer", Self->NormalizerController.GetNormalizer()->GetClassName())("changes", Changes->DebugString());
224+
} else {
225+
Changes->ApplyOnComplete(Self->NormalizerController);
226+
}
217227
if (!NormalizerFinished) {
218228
return;
219229
}

ydb/core/tx/columnshard/normalizer/abstract/abstract.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void TNormalizationController::InitNormalizers(const TInitContext& ctx) {
7777
auto component = INormalizerComponent::TFactory::MakeHolder(i.GetClassName(), ctx);
7878
AFL_VERIFY(component)("class_name", i.GetClassName());
7979
auto normalizer = RegisterNormalizer(std::shared_ptr<INormalizerComponent>(component.Release()));
80-
normalizer->SetIsRepair(true).SetUniqueDescription(i.GetDescription());
80+
normalizer->SetIsRepair(true).SetIsDryRun(i.GetDryRun()).SetUniqueDescription(i.GetDescription());
8181
}
8282
}
8383
}

ydb/core/tx/columnshard/normalizer/abstract/abstract.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class INormalizerChanges {
106106
}
107107

108108
virtual ui64 GetSize() const = 0;
109+
virtual TString DebugString() const {
110+
return TStringBuilder() << "size=" << GetSize();
111+
}
109112
};
110113

111114
class TTrivialNormalizerTask: public INormalizerTask {
@@ -170,6 +173,7 @@ class TNormalizationController {
170173
class INormalizerComponent {
171174
private:
172175
YDB_ACCESSOR(bool, IsRepair, false);
176+
YDB_ACCESSOR(bool, IsDryRun, false);
173177
YDB_ACCESSOR_DEF(TString, UniqueDescription);
174178
YDB_ACCESSOR(TString, UniqueId, TGUID::CreateTimebased().AsUuidString());
175179

ydb/core/tx/columnshard/normalizer/portion/broken_blobs.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <ydb/core/tx/columnshard/engines/scheme/filtered_scheme.h>
88
#include <ydb/core/tx/columnshard/tables_manager.h>
99

10+
#include <util/string/vector.h>
11+
1012
namespace NKikimr::NOlap::NNormalizer::NBrokenBlobs {
1113

1214
class TNormalizerResult: public INormalizerChanges {
@@ -33,17 +35,8 @@ class TNormalizerResult: public INormalizerChanges {
3335
copy.SaveMetaToDatabase(db);
3436
}
3537
if (BrokenPortions.size()) {
36-
TStringBuilder sb;
37-
ui64 recordsCount = 0;
38-
sb << "path_ids:[";
39-
for (auto&& [_, p] : BrokenPortions) {
40-
sb << p.GetPortionInfo().GetPathId() << ",";
41-
recordsCount += p.GetPortionInfo().GetRecordsCount();
42-
}
43-
sb << "];";
44-
sb << "records_count:" << recordsCount;
4538
NIceDb::TNiceDb db(txc.DB);
46-
normController.AddNormalizerEvent(db, "REMOVE_PORTIONS", sb);
39+
normController.AddNormalizerEvent(db, "REMOVE_PORTIONS", DebugString());
4740
}
4841
return true;
4942
}
@@ -54,6 +47,19 @@ class TNormalizerResult: public INormalizerChanges {
5447
ui64 GetSize() const override {
5548
return BrokenPortions.size();
5649
}
50+
51+
TString DebugString() const override {
52+
TStringBuilder sb;
53+
ui64 recordsCount = 0;
54+
sb << "path_ids=[";
55+
for (auto&& [_, p] : BrokenPortions) {
56+
sb << p.GetPortionInfo().GetPathId() << ",";
57+
recordsCount += p.GetPortionInfo().GetRecordsCount();
58+
}
59+
sb << "]";
60+
sb << ";records_count=" << recordsCount;
61+
return sb;
62+
}
5763
};
5864

5965
class TReadTask: public NOlap::NBlobOperations::NRead::ITask {

ydb/core/tx/columnshard/normalizer/portion/leaked_blobs.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@
99

1010
#include <ydb/library/actors/core/actor.h>
1111

12+
#include <util/string/vector.h>
13+
1214
namespace NKikimr::NOlap {
1315

1416
class TLeakedBlobsNormalizerChanges: public INormalizerChanges {
1517
private:
1618
THashSet<TLogoBlobID> Leaks;
1719
const ui64 TabletId;
1820
NColumnShard::TBlobGroupSelector DsGroupSelector;
21+
ui64 LeakeadBlobsSize;
1922

2023
public:
2124
TLeakedBlobsNormalizerChanges(THashSet<TLogoBlobID>&& leaks, const ui64 tabletId, NColumnShard::TBlobGroupSelector dsGroupSelector)
2225
: Leaks(std::move(leaks))
2326
, TabletId(tabletId)
2427
, DsGroupSelector(dsGroupSelector) {
28+
LeakeadBlobsSize = 0;
29+
for (const auto& blob : Leaks) {
30+
LeakeadBlobsSize += blob.BlobSize();
31+
}
2532
}
2633

2734
bool ApplyOnExecute(NTabletFlatExecutor::TTransactionContext& txc, const TNormalizationController& /*normController*/) const override {
@@ -42,6 +49,18 @@ class TLeakedBlobsNormalizerChanges: public INormalizerChanges {
4249
ui64 GetSize() const override {
4350
return Leaks.size();
4451
}
52+
53+
TString DebugString() const override {
54+
TStringBuilder sb;
55+
sb << "tablet=" << TabletId;
56+
sb << ";leaked_blob_count=" << Leaks.size();
57+
sb << ";leaked_blobs_size=" << LeakeadBlobsSize;
58+
auto blobSampleEnd = Leaks.begin();
59+
for (ui64 i = 0; i < 10 && blobSampleEnd != Leaks.end(); ++i, ++blobSampleEnd) {
60+
}
61+
sb << ";leaked_blobs=[" << JoinStrings(Leaks.begin(), blobSampleEnd, ",") << "]";
62+
return sb;
63+
}
4564
};
4665

4766
class TRemoveLeakedBlobsActor: public TActorBootstrapped<TRemoveLeakedBlobsActor> {
@@ -156,7 +175,8 @@ TConclusion<std::vector<INormalizerTask::TPtr>> TLeakedBlobsNormalizer::DoInit(
156175
NIceDb::TNiceDb db(txc.DB);
157176
const bool ready = (int)Schema::Precharge<Schema::IndexPortions>(db, txc.DB.GetScheme()) &
158177
(int)Schema::Precharge<Schema::IndexColumns>(db, txc.DB.GetScheme()) &
159-
(int)Schema::Precharge<Schema::IndexIndexes>(db, txc.DB.GetScheme());
178+
(int)Schema::Precharge<Schema::IndexIndexes>(db, txc.DB.GetScheme()) &
179+
(int)Schema::Precharge<Schema::BlobsToDeleteWT>(db, txc.DB.GetScheme());
160180
if (!ready) {
161181
return TConclusionStatus::Fail("Not ready");
162182
}
@@ -219,6 +239,24 @@ TConclusionStatus TLeakedBlobsNormalizer::LoadPortionBlobIds(
219239
}
220240
Indexes = std::move(indexesLocal);
221241
}
242+
if (BlobsToDelete.empty()) {
243+
THashSet<TUnifiedBlobId> blobsToDelete;
244+
auto rowset = db.Table<NColumnShard::Schema::BlobsToDeleteWT>().Select();
245+
if (!rowset.IsReady()) {
246+
return TConclusionStatus::Fail("Not ready: BlobsToDeleteWT");
247+
}
248+
while (!rowset.EndOfSet()) {
249+
const TString& blobIdStr = rowset.GetValue<NColumnShard::Schema::BlobsToDeleteWT::BlobId>();
250+
TString error;
251+
TUnifiedBlobId blobId = TUnifiedBlobId::ParseFromString(blobIdStr, &DsGroupSelector, error);
252+
AFL_VERIFY(blobId.IsValid())("event", "cannot_parse_blob")("error", error)("original_string", blobIdStr);
253+
blobsToDelete.emplace(blobId);
254+
if (!rowset.Next()) {
255+
return TConclusionStatus::Fail("Local table is not loaded: BlobsToDeleteWT");
256+
}
257+
}
258+
BlobsToDelete = std::move(blobsToDelete);
259+
}
222260
AFL_VERIFY(Portions.size() == Records.size())("portions", Portions.size())("records", Records.size());
223261
THashSet<TLogoBlobID> resultLocal;
224262
for (auto&& i : Portions) {
@@ -240,6 +278,9 @@ TConclusionStatus TLeakedBlobsNormalizer::LoadPortionBlobIds(
240278
for (auto&& c : it->second) {
241279
resultLocal.emplace(c.GetLogoBlobId());
242280
}
281+
for (const auto& c : BlobsToDelete) {
282+
resultLocal.emplace(c.GetLogoBlobId());
283+
}
243284
}
244285
std::swap(resultLocal, result);
245286
return TConclusionStatus::Success();

ydb/core/tx/columnshard/normalizer/portion/leaked_blobs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ class TLeakedBlobsNormalizer: public TNormalizationController::INormalizerCompon
4545
THashMap<ui64, TPortionInfoConstructor> Portions;
4646
THashMap<ui64, std::vector<TColumnChunkLoadContextV1>> Records;
4747
THashMap<ui64, std::vector<TIndexChunkLoadContext>> Indexes;
48+
THashSet<TUnifiedBlobId> BlobsToDelete;
4849
};
4950
} // namespace NKikimr::NOlap

0 commit comments

Comments
 (0)