@@ -129,6 +129,8 @@ TBlobManager::TBlobManager(TIntrusivePtr<TTabletStorageInfo> tabletInfo, ui32 ge
129
129
, CurrentGen(gen)
130
130
, CurrentStep(0 )
131
131
{
132
+ BlobsManagerCounters.CurrentGen ->Set (CurrentGen);
133
+ BlobsManagerCounters.CurrentStep ->Set (CurrentStep);
132
134
}
133
135
134
136
void TBlobManager::RegisterControls (NKikimr::TControlBoard& /* icb*/ ) {
@@ -151,43 +153,19 @@ bool TBlobManager::LoadState(IBlobManagerDb& db, const TTabletId selfTabletId) {
151
153
return false ;
152
154
}
153
155
154
- for (auto it = BlobsToDelete.GetIterator (); it.IsValid (); ++it) {
155
- BlobsManagerCounters.OnDeleteBlobMarker (it.GetBlobId ().BlobSize ());
156
- }
157
- BlobsManagerCounters.OnBlobsDelete (BlobsToDelete);
156
+ BlobsManagerCounters.OnBlobsToDelete (BlobsToDelete);
158
157
159
158
// Build the list of steps that cannot be garbage collected before Keep flag is set on the blobs
160
- THashSet<TGenStep> genStepsWithBlobsToKeep;
161
- std::map<TGenStep, std::set<TLogoBlobID>> blobsToKeepLocal;
159
+ TBlobsByGenStep blobsToKeepLocal;
162
160
for (const auto & unifiedBlobId : blobsToKeep) {
163
161
AFL_DEBUG (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" add_blob_to_keep" , unifiedBlobId.ToStringNew ());
164
162
TLogoBlobID blobId = unifiedBlobId.GetLogoBlobId ();
165
- TGenStep genStep (blobId);
166
- Y_ABORT_UNLESS (LastCollectedGenStep < genStep);
167
-
168
- AFL_VERIFY (blobsToKeepLocal[genStep].emplace (blobId).second )(" blob_to_keep_double" , unifiedBlobId.ToStringNew ());
169
- BlobsManagerCounters.OnKeepMarker (blobId.BlobSize ());
170
- const ui64 groupId = dsGroupSelector.GetGroup (blobId);
171
- // Keep + DontKeep (probably in different gen:steps)
172
- // GC could go through it to a greater LastCollectedGenStep
173
- if (BlobsToDelete.Contains (SelfTabletId, TUnifiedBlobId (groupId, blobId))) {
174
- continue ;
175
- }
163
+ Y_ABORT_UNLESS (LastCollectedGenStep < TGenStep (blobId));
176
164
177
- genStepsWithBlobsToKeep. insert (genStep );
165
+ AFL_VERIFY (blobsToKeepLocal. Add (blobId))( " blob_to_keep_double " , unifiedBlobId. ToStringNew () );
178
166
}
179
167
std::swap (blobsToKeepLocal, BlobsToKeep);
180
- BlobsManagerCounters.OnBlobsKeep (BlobsToKeep);
181
-
182
- AllocatedGenSteps.clear ();
183
- for (const auto & gs : genStepsWithBlobsToKeep) {
184
- AllocatedGenSteps.push_back (new TAllocatedGenStep (gs));
185
- }
186
- AllocatedGenSteps.push_back (new TAllocatedGenStep ({ CurrentGen, 0 }));
187
-
188
- Sort (AllocatedGenSteps.begin (), AllocatedGenSteps.end (), [](const TAllocatedGenStepConstPtr& a, const TAllocatedGenStepConstPtr& b) {
189
- return a->GenStep < b->GenStep ;
190
- });
168
+ BlobsManagerCounters.OnBlobsToKeep (BlobsToKeep);
191
169
192
170
return true ;
193
171
}
@@ -280,50 +258,47 @@ void TBlobManager::DrainDeleteTo(const TGenStep& dest, TGCContext& gcContext) {
280
258
}
281
259
}
282
260
283
- bool TBlobManager::DrainKeepTo (const TGenStep& dest, TGCContext& gcContext, const bool controlCapacity) {
284
- AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" event" , " PreparePerGroupGCRequests" )(" gen_step" , dest)(" gs_blobs_to_keep_count" , BlobsToKeep.size ());
285
- for (; BlobsToKeep.size () && (!controlCapacity || !gcContext.IsFull ()); BlobsToKeep.erase (BlobsToKeep.begin ())) {
286
- auto gsBlobs = BlobsToKeep.begin ();
287
- TGenStep genStep = gsBlobs->first ;
261
+ bool TBlobManager::DrainKeepTo (const TGenStep& dest, TGCContext& gcContext) {
262
+ AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" event" , " PreparePerGroupGCRequests" )(" gen_step" , dest)(" gs_blobs_to_keep_count" , BlobsToKeep.GetSize ());
263
+
264
+ const auto pred = [&](const TGenStep& genStep, const TLogoBlobID& logoBlobId) {
288
265
AFL_VERIFY (LastCollectedGenStep < genStep)(" last" , LastCollectedGenStep.ToString ())(" gen" , genStep.ToString ());
289
- if (dest < genStep) {
290
- return true ;
291
- }
292
- for (auto && keepBlobIt : gsBlobs->second ) {
293
- const ui32 blobGroup = TabletInfo->GroupFor (keepBlobIt.Channel (), keepBlobIt.Generation ());
294
- TBlobAddress bAddress (blobGroup, keepBlobIt.Channel ());
295
- const TUnifiedBlobId keepUnified (blobGroup, keepBlobIt);
296
- gcContext.MutableKeepsToErase ().emplace_back (keepUnified);
297
- if (BlobsToDelete.ExtractBlobTo (keepUnified, gcContext.MutableExtractedToRemoveFromDB ())) {
298
- if (keepBlobIt.Generation () == CurrentGen) {
299
- AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" to_not_keep" , keepUnified.ToStringNew ());
300
- continue ;
301
- }
302
- if (gcContext.GetSharedBlobsManager ()->BuildStoreCategories ({ keepUnified }).GetDirect ().IsEmpty ()) {
303
- AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" to_not_keep_not_direct" , keepUnified.ToStringNew ());
304
- continue ;
305
- }
306
- AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" to_not_keep_old" , keepUnified.ToStringNew ());
307
- gcContext.MutablePerGroupGCListsInFlight ()[bAddress].DontKeepList .insert (keepBlobIt);
308
- } else {
309
- AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" to_keep" , keepUnified.ToStringNew ());
310
- gcContext.MutablePerGroupGCListsInFlight ()[bAddress].KeepList .insert (keepBlobIt);
266
+ const ui32 blobGroup = TabletInfo->GroupFor (logoBlobId.Channel (), logoBlobId.Generation ());
267
+ TBlobAddress bAddress (blobGroup, logoBlobId.Channel ());
268
+ const TUnifiedBlobId keepUnified (blobGroup, logoBlobId);
269
+ gcContext.MutableKeepsToErase ().emplace_back (keepUnified);
270
+ if (BlobsToDelete.ExtractBlobTo (keepUnified, gcContext.MutableExtractedToRemoveFromDB ())) {
271
+ if (logoBlobId.Generation () == CurrentGen) {
272
+ AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" to_not_keep" , keepUnified.ToStringNew ());
273
+ continue ;
274
+ }
275
+ if (gcContext.GetSharedBlobsManager ()->BuildStoreCategories ({ keepUnified }).GetDirect ().IsEmpty ()) {
276
+ AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" to_not_keep_not_direct" , keepUnified.ToStringNew ());
277
+ continue ;
311
278
}
279
+ AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" to_not_keep_old" , keepUnified.ToStringNew ());
280
+ gcContext.MutablePerGroupGCListsInFlight ()[bAddress].DontKeepList .insert (logoBlobId);
281
+ } else {
282
+ AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" to_keep" , keepUnified.ToStringNew ());
283
+ gcContext.MutablePerGroupGCListsInFlight ()[bAddress].KeepList .insert (logoBlobId);
312
284
}
313
- }
314
- return BlobsToKeep.empty ();
285
+ };
286
+
287
+ return BlobsToKeep.ExtractFront (dest, gcContext.GetFreeSpace (), pred);
315
288
}
316
289
317
290
std::shared_ptr<NBlobOperations::NBlobStorage::TGCTask> TBlobManager::BuildGCTask (const TString& storageId,
318
291
const std::shared_ptr<TBlobManager>& manager, const std::shared_ptr<NDataSharing::TStorageSharedBlobsManager>& sharedBlobsInfo,
319
292
const std::shared_ptr<NBlobOperations::TRemoveGCCounters>& counters) noexcept {
320
293
AFL_VERIFY (!CollectGenStepInFlight);
321
- if (BlobsToKeep.empty () && BlobsToDelete.IsEmpty () && LastCollectedGenStep == TGenStep{ CurrentGen, CurrentStep }) {
294
+ if (BlobsToKeep.IsEmpty () && BlobsToDelete.IsEmpty () && LastCollectedGenStep == TGenStep{ CurrentGen, CurrentStep }) {
295
+ BlobsManagerCounters.GCCounters .SkipCollectionEmpty ->Add (1 );
322
296
ACFL_DEBUG (" event" , " TBlobManager::BuildGCTask skip" )(" current_gen" , CurrentGen)(" current_step" , CurrentStep);
323
297
return nullptr ;
324
298
}
325
299
326
300
if (AppData ()->TimeProvider ->Now () - PreviousGCTime < NYDBTest::TControllers::GetColumnShardController ()->GetOverridenGCPeriod (TDuration::Seconds (GC_INTERVAL_SECONDS))) {
301
+ BlobsManagerCounters.GCCounters .SkipCollectionThrottling ->Add (1 );
327
302
return nullptr ;
328
303
}
329
304
@@ -334,21 +309,12 @@ std::shared_ptr<NBlobOperations::NBlobStorage::TGCTask> TBlobManager::BuildGCTas
334
309
AFL_VERIFY (newCollectGenSteps.size ());
335
310
AFL_VERIFY (newCollectGenSteps.front () == LastCollectedGenStep);
336
311
if (GCBarrierPreparation != LastCollectedGenStep) {
337
- if (!GCBarrierPreparation.Generation ()) {
338
- for (auto && newCollectGenStep : newCollectGenSteps) {
339
- if (!DrainKeepTo (newCollectGenStep, gcContext)) {
340
- break ;
341
- }
342
- if (newCollectGenStep.Generation () == CurrentGen) {
343
- CollectGenStepInFlight = std::max (CollectGenStepInFlight.value_or (newCollectGenStep), newCollectGenStep);
344
- }
345
- }
346
- AFL_VERIFY (LastCollectedGenStep <= CollectGenStepInFlight)(" last" , LastCollectedGenStep)(" collect" , CollectGenStepInFlight);
347
- } else {
348
- AFL_VERIFY (GCBarrierPreparation.Generation () != CurrentGen);
312
+ if (GCBarrierPreparation.Generation ()) {
313
+ AFL_VERIFY (GCBarrierPreparation.Generation () < CurrentGen);
349
314
AFL_VERIFY (LastCollectedGenStep <= GCBarrierPreparation);
350
- CollectGenStepInFlight = GCBarrierPreparation;
351
- AFL_VERIFY (DrainKeepTo (*CollectGenStepInFlight, gcContext, false ));
315
+ if (DrainKeepTo (GCBarrierPreparation, gcContext)) {
316
+ CollectGenStepInFlight = GCBarrierPreparation;
317
+ }
352
318
}
353
319
} else {
354
320
DrainDeleteTo (LastCollectedGenStep, gcContext);
@@ -368,30 +334,33 @@ std::shared_ptr<NBlobOperations::NBlobStorage::TGCTask> TBlobManager::BuildGCTas
368
334
gcContext.InitializeFirst (TabletInfo);
369
335
FirstGC = false ;
370
336
}
337
+ if (!BlobsToKeep.IsEmpty ()) {
338
+ AFL_VERIFY (*CollectGenStepInFlight < BlobsToKeep.GetMinGenStepVerified ());
339
+ }
340
+ AFL_VERIFY (LastCollectedGenStep < *CollectGenStepInFlight);
371
341
}
372
- AFL_VERIFY (LastCollectedGenStep <= *CollectGenStepInFlight);
373
342
AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" notice" , " collect_gen_step" )(" value" , CollectGenStepInFlight)(" current_gen" , CurrentGen);
374
343
375
- const bool isFull = gcContext.IsFull ();
344
+ if (gcContext.IsFull ()) {
345
+ PreviousGCTime = TInstant::Zero ();
346
+ }
376
347
348
+ BlobsManagerCounters.OnGCTask (gcContext.GetKeepsToErase ().size (), gcContext.GetExtractedToRemoveFromDB ().GetSize (), gcContext.IsFull (), !!CollectGenStepInFlight);
377
349
auto removeCategories = sharedBlobsInfo->BuildRemoveCategories (std::move (gcContext.MutableExtractedToRemoveFromDB ()));
378
-
379
350
auto result = std::make_shared<NBlobOperations::NBlobStorage::TGCTask>(storageId, std::move (gcContext.MutablePerGroupGCListsInFlight ()),
380
351
CollectGenStepInFlight, std::move (gcContext.MutableKeepsToErase ()), manager, std::move (removeCategories), counters, TabletInfo->TabletID , CurrentGen);
381
352
if (result->IsEmpty ()) {
353
+ BlobsManagerCounters.OnEmptyGCTask ();
382
354
CollectGenStepInFlight = {};
383
355
return nullptr ;
384
356
}
385
357
386
- if (isFull) {
387
- PreviousGCTime = TInstant::Zero ();
388
- }
389
-
390
358
return result;
391
359
}
392
360
393
361
TBlobBatch TBlobManager::StartBlobBatch () {
394
362
++CurrentStep;
363
+ BlobsManagerCounters.CurrentStep ->Set (CurrentStep);
395
364
AFL_VERIFY (TabletInfo->Channels .size () > 2 );
396
365
const auto & channel = TabletInfo->Channels [(CurrentStep % (TabletInfo->Channels .size () - 2 )) + 2 ];
397
366
++CountersUpdate.BatchesStarted ;
@@ -419,11 +388,9 @@ void TBlobManager::DoSaveBlobBatchOnComplete(TBlobBatch&& blobBatch) {
419
388
AFL_VERIFY (genStep > edgeGenStep)(" gen_step" , genStep)(" edge_gen_step" , edgeGenStep)(" blob_id" , blobId.ToStringNew ());
420
389
AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" to_keep" , logoBlobId.ToString ());
421
390
422
- BlobsManagerCounters. OnKeepMarker (logoBlobId. BlobSize ( ));
423
- AFL_VERIFY (BlobsToKeep[genStep]. emplace (logoBlobId). second );
391
+ AFL_VERIFY (BlobsToKeep. Add (logoBlobId ));
392
+ BlobsManagerCounters. OnBlobsToKeep (BlobsToKeep );
424
393
}
425
- BlobsManagerCounters.OnBlobsKeep (BlobsToKeep);
426
-
427
394
blobBatch.BatchInfo ->GenStepRef .Reset ();
428
395
}
429
396
@@ -459,12 +426,11 @@ void TBlobManager::DeleteBlobOnComplete(const TTabletId tabletId, const TUnified
459
426
if (!IsBlobInUsage (blobId)) {
460
427
LOG_S_DEBUG (" BlobManager at tablet " << TabletInfo->TabletID << " Delete Blob " << blobId);
461
428
AFL_VERIFY (BlobsToDelete.Add (tabletId, blobId));
462
- BlobsManagerCounters.OnDeleteBlobMarker (blobId.BlobSize ());
463
- BlobsManagerCounters.OnBlobsDelete (BlobsToDelete);
429
+ BlobsManagerCounters.OnBlobsToDelete (BlobsToDelete);
464
430
} else {
465
- BlobsManagerCounters.OnDeleteBlobDelayedMarker (blobId.BlobSize ());
466
431
LOG_S_DEBUG (" BlobManager at tablet " << TabletInfo->TabletID << " Delay Delete Blob " << blobId);
467
- BlobsToDeleteDelayed.Add (tabletId, blobId);
432
+ AFL_VERIFY (BlobsToDeleteDelayed.Add (tabletId, blobId));
433
+ BlobsManagerCounters.OnBlobsToDeleteDelayed (BlobsToDeleteDelayed);
468
434
}
469
435
}
470
436
@@ -486,7 +452,7 @@ void TBlobManager::OnGCFinishedOnComplete(const std::optional<TGenStep>& genStep
486
452
487
453
void TBlobManager::OnGCStartOnExecute (const std::optional<TGenStep>& genStep, IBlobManagerDb& db) {
488
454
if (genStep) {
489
- AFL_VERIFY (LastCollectedGenStep <= *genStep)(" last" , LastCollectedGenStep)(" prepared" , genStep);
455
+ AFL_VERIFY (LastCollectedGenStep < *genStep)(" last" , LastCollectedGenStep)(" prepared" , genStep);
490
456
db.SaveGCBarrierPreparation (*genStep);
491
457
}
492
458
}
@@ -503,8 +469,8 @@ void TBlobManager::OnBlobFree(const TUnifiedBlobId& blobId) {
503
469
// Check if the blob is marked for delayed deletion
504
470
if (BlobsToDeleteDelayed.ExtractBlobTo (blobId, BlobsToDelete)) {
505
471
AFL_INFO (NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)(" blob_id" , blobId)(" event" , " blob_delayed_deleted" );
506
- BlobsManagerCounters.OnBlobsDelete (BlobsToDelete);
507
- BlobsManagerCounters.OnDeleteBlobMarker (blobId. GetLogoBlobId (). BlobSize () );
472
+ BlobsManagerCounters.OnBlobsToDelete (BlobsToDelete);
473
+ BlobsManagerCounters.OnBlobsToDeleteDelayed (BlobsToDeleteDelayed );
508
474
}
509
475
}
510
476
0 commit comments