Skip to content

Commit 808f447

Browse files
authored
Fix shredding stalling (merge from main #17374) (#17408)
1 parent 651de40 commit 808f447

File tree

5 files changed

+58
-16
lines changed

5 files changed

+58
-16
lines changed

ydb/core/blobstorage/vdisk/hulldb/compstrat/hulldb_compstrat_selector.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ namespace NKikimr {
9292
return action;
9393
}
9494

95+
// compact explicitly defined SST's, if set
96+
action = TStrategyExplicit(HullCtx, Params, LevelSnap, Task).Select();
97+
if (action != ActNothing) {
98+
return action;
99+
}
100+
95101
// try to find what to compact based on levels balance
96102
action = TStrategyBalance(HullCtx, Params, LevelSnap, Task).Select();
97103
if (action != ActNothing) {
@@ -120,6 +126,12 @@ namespace NKikimr {
120126
return action;
121127
}
122128

129+
// compact explicitly defined SST's, if set
130+
action = TStrategyExplicit(HullCtx, Params, LevelSnap, Task).Select();
131+
if (action != ActNothing) {
132+
return action;
133+
}
134+
123135
// try to find what to compact based on levels balance
124136
action = TStrategyBalance(HullCtx, Params, LevelSnap, Task).Select();
125137
if (action != ActNothing) {

ydb/core/blobstorage/vdisk/hulldb/generic/hullds_sst.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ namespace NKikimr {
2222
TABLED() {SMALL() {str << StorageRatio.MonSummary();}}
2323
TABLED() {SMALL() {str << (Info.IsCreatedByRepl() ? "REPL" : "COMP");}}
2424
TABLED() {SMALL() {str << ToStringLocalTimeUpToSeconds(Info.CTime);}}
25+
TABLED() {SMALL() {
26+
str << AssignedSstId << '/' << VolatileOrderId << '@' << FormatList(AllChunks);
27+
}}
2528
++index;
2629
}
2730
}

ydb/core/blobstorage/vdisk/hulldb/generic/hullds_sstslice.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace NKikimr {
2020
TABLEH() {str << NHullComp::TSstRatio::MonHeader();}
2121
TABLEH() {str << "Origin";}
2222
TABLEH() {str << "CTime";}
23+
TABLEH() {str << "Location";}
2324
}
2425
}
2526
TABLEBODY() {
@@ -39,7 +40,7 @@ namespace NKikimr {
3940
// total
4041
TABLER() {
4142
TABLED() {SMALL() {str << "index";}}
42-
TABLED() {SMALL() {str << "total";}}
43+
TABLED() {SMALL() {str << "level";}}
4344
TABLED() {SMALL() {str << "lsns";}}
4445
TABLED() {SMALL() {str << sum.IdxTotalSize << " / " << sum.InplaceDataTotalSize << " / "
4546
<< sum.HugeDataTotalSize;}}
@@ -48,7 +49,9 @@ namespace NKikimr {
4849
<< sum.ItemsWithHugeData;}}
4950
TABLED() {SMALL() {str << "keys";}}
5051
TABLED() {SMALL() {str << "ratio";}}
52+
TABLED() {SMALL() {str << "origin";}}
5153
TABLED() {SMALL() {str << "time";}}
54+
TABLED() {SMALL() {str << "chunks";}}
5255
}
5356
}
5457
}

ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeleton.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,9 @@ namespace NKikimr {
24722472

24732473
void Handle(TEvents::TEvGone::TPtr &ev, const TActorContext &ctx) {
24742474
Y_UNUSED(ctx);
2475+
if (ev->Sender == ShredActorId) {
2476+
ShredActorId = {};
2477+
}
24752478
ActiveActors.Erase(ev->Sender);
24762479
}
24772480

ydb/core/blobstorage/vdisk/skeleton/skeleton_shred.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ namespace NKikimr {
2424

2525
THashMap<TChunkIdx, EChunkType> ChunkTypes;
2626
THashSet<TChunkIdx> ChunksShredded;
27-
THashSet<ui64> TablesToCompact;
27+
THashSet<ui64> TablesToCompactLogoBlobs;
28+
THashSet<ui64> TablesToCompactBlocks;
29+
THashSet<ui64> TablesToCompactBarriers;
2830
ui32 RepliesPending = 0;
2931
bool SnapshotProcessed = false;
3032
bool DefragCompleted = false;
31-
bool FoundAnyChunks = false;
3233

3334
public:
3435
TSkeletonShredActor(NPDisk::TEvShredVDisk::TPtr ev, TShredCtxPtr shredCtx)
@@ -71,7 +72,6 @@ namespace NKikimr {
7172
RepliesPending = 2;
7273
SnapshotProcessed = false;
7374
DefragCompleted = false;
74-
FoundAnyChunks = false;
7575
}
7676

7777
void Handle(TEvListChunksResult::TPtr ev) {
@@ -84,7 +84,6 @@ namespace NKikimr {
8484
for (const TChunkIdx chunkId : set) {
8585
if (const auto it = ChunkTypes.find(chunkId); it != ChunkTypes.end()) {
8686
it->second = type;
87-
FoundAnyChunks = true;
8887
Y_DEBUG_ABORT_UNLESS(ChunksToShred.contains(chunkId));
8988
} else {
9089
Y_DEBUG_ABORT_UNLESS(!ChunksToShred.contains(chunkId));
@@ -104,15 +103,20 @@ namespace NKikimr {
104103
(ActorId, SelfId()));
105104

106105
auto& snap = ev->Get()->Snap;
107-
TablesToCompact.clear();
108-
Scan<true>(snap.HullCtx, snap.LogoBlobsSnap, TablesToCompact);
109-
Scan<false>(snap.HullCtx, snap.BlocksSnap, TablesToCompact);
110-
Scan<false>(snap.HullCtx, snap.BarriersSnap, TablesToCompact);
106+
TablesToCompactLogoBlobs.clear();
107+
TablesToCompactBlocks.clear();
108+
TablesToCompactBarriers.clear();
109+
Scan<true>(snap.HullCtx, snap.LogoBlobsSnap, TablesToCompactLogoBlobs);
110+
Scan<false>(snap.HullCtx, snap.BlocksSnap, TablesToCompactBlocks);
111+
Scan<false>(snap.HullCtx, snap.BarriersSnap, TablesToCompactBarriers);
111112
SnapshotProcessed = true;
113+
DropUnknownChunks();
114+
CheckIfDone();
112115
CheckDefragStage();
113116

114117
STLOG(PRI_DEBUG, BS_SHRED, BSSV09, ShredCtx->VCtx->VDiskLogPrefix << "TEvTakeHullSnapshotResult processed",
115-
(ActorId, SelfId()), (TablesToCompact, TablesToCompact));
118+
(ActorId, SelfId()), (TablesToCompactLogoBlobs, TablesToCompactLogoBlobs),
119+
(TablesToCompactBlocks, TablesToCompactBlocks), (TablesToCompactBarriers, TablesToCompactBarriers));
116120
}
117121

118122
template<bool Blobs, typename TKey, typename TMemRec>
@@ -128,7 +132,6 @@ namespace NKikimr {
128132
}
129133
if (const auto it = ChunkTypes.find(p->ChunkIdx); it != ChunkTypes.end()) {
130134
it->second = EChunkType::HUGE_CHUNK;
131-
FoundAnyChunks = true;
132135
}
133136
}
134137
}
@@ -155,7 +158,6 @@ namespace NKikimr {
155158
tablesToCompact.insert(seg.AssignedSstId);
156159
STLOG(PRI_DEBUG, BS_SHRED, BSSV13, ShredCtx->VCtx->VDiskLogPrefix << "going to compact SST",
157160
(SstId, seg.AssignedSstId), (AllChunks, seg.AllChunks));
158-
FoundAnyChunks = true;
159161
Y_DEBUG_ABORT_UNLESS(ChunksToShred.contains(chunkId));
160162
} else {
161163
Y_DEBUG_ABORT_UNLESS(!ChunksToShred.contains(chunkId));
@@ -172,6 +174,19 @@ namespace NKikimr {
172174
}
173175
}
174176

177+
void DropUnknownChunks() {
178+
for (auto it = ChunkTypes.begin(); it != ChunkTypes.end(); ) {
179+
if (it->second == EChunkType::UNKNOWN) {
180+
const size_t num = ChunksToShred.erase(it->first);
181+
Y_VERIFY_DEBUG_S(num == 1, ShredCtx->VCtx->VDiskLogPrefix);
182+
ChunksShredded.insert(it->first);
183+
ChunkTypes.erase(it++);
184+
} else {
185+
++it;
186+
}
187+
}
188+
}
189+
175190
void HandleHullShredDefragResult() {
176191
STLOG(PRI_DEBUG, BS_SHRED, BSSV14, ShredCtx->VCtx->VDiskLogPrefix << "EvHullShredDefragResult received",
177192
(ActorId, SelfId()));
@@ -184,8 +199,15 @@ namespace NKikimr {
184199
return;
185200
}
186201

187-
if (!TablesToCompact.empty()) {
188-
Send(ShredCtx->SkeletonId, TEvCompactVDisk::Create(EHullDbType::LogoBlobs, std::move(TablesToCompact)));
202+
if (!TablesToCompactLogoBlobs.empty()) {
203+
Send(ShredCtx->SkeletonId, TEvCompactVDisk::Create(EHullDbType::LogoBlobs,
204+
std::exchange(TablesToCompactLogoBlobs, {})));
205+
} else if (!TablesToCompactBlocks.empty()) {
206+
Send(ShredCtx->SkeletonId, TEvCompactVDisk::Create(EHullDbType::Blocks,
207+
std::exchange(TablesToCompactBlocks, {})));
208+
} else if (!TablesToCompactBarriers.empty()) {
209+
Send(ShredCtx->SkeletonId, TEvCompactVDisk::Create(EHullDbType::Barriers,
210+
std::exchange(TablesToCompactBarriers, {})));
189211
} else {
190212
TActivationContext::Schedule(TDuration::Minutes(1), new IEventHandle(TEvents::TSystem::Wakeup, 0,
191213
SelfId(), TActorId(), nullptr, 0));
@@ -195,8 +217,7 @@ namespace NKikimr {
195217
void Handle(TEvCompactVDiskResult::TPtr /*ev*/) {
196218
STLOG(PRI_DEBUG, BS_SHRED, BSSV11, ShredCtx->VCtx->VDiskLogPrefix << "TEvCompactVDiskResult received",
197219
(ActorId, SelfId()));
198-
TActivationContext::Schedule(TDuration::Minutes(1), new IEventHandle(TEvents::TSystem::Wakeup, 0, SelfId(),
199-
TActorId(), nullptr, 0));
220+
CheckDefragStage();
200221
}
201222

202223
void Handle(TEvNotifyChunksDeleted::TPtr ev) {

0 commit comments

Comments
 (0)