@@ -161,7 +161,7 @@ void TPartition::DumpKeysForBlobsCompaction() const
161161 LOG_D (" ===================================" );
162162}
163163
164- void TPartition::TryRunCompaction ()
164+ void TPartition::TryRunCompaction (bool force )
165165{
166166 if (CompactionInProgress) {
167167 LOG_D (" Blobs compaction in progress" );
@@ -174,12 +174,11 @@ void TPartition::TryRunCompaction()
174174 }
175175
176176 // DumpKeysForBlobsCompaction();
177- DumpZones (__FILE__, __LINE__);
178177
179178 const ui64 blobsKeyCountLimit = GetBodyKeysCountLimit ();
180179 const ui64 compactedBlobSizeLowerBound = GetCompactedBlobSizeLowerBound ();
181180
182- if ((BlobEncoder.DataKeysBody .size () < blobsKeyCountLimit) && (BlobEncoder.GetSize () < GetCumulativeSizeLimit ())) {
181+ if ((BlobEncoder.DataKeysBody .size () < blobsKeyCountLimit) && (BlobEncoder.GetSize () < GetCumulativeSizeLimit ()) && !force ) {
183182 LOG_D (" No data for blobs compaction" );
184183 return ;
185184 }
@@ -200,13 +199,19 @@ void TPartition::TryRunCompaction()
200199 LOG_D (" Blob key for rename " << k.Key .ToString ());
201200 }
202201 }
202+
203203 LOG_D (blobsCount << " keys were taken away. Let's read " << blobsSize << " bytes" );
204204
205205 CompactionInProgress = true ;
206206
207207 Send (SelfId (), new TEvPQ::TEvRunCompaction (blobsCount));
208208}
209209
210+ void TPartition::Handle (TEvPQ::TEvForceCompaction::TPtr&)
211+ {
212+ TryRunCompaction (true );
213+ }
214+
210215void TPartition::Handle (TEvPQ::TEvRunCompaction::TPtr& ev)
211216{
212217 const ui64 blobsCount = ev->Get ()->BlobsCount ;
@@ -261,11 +266,14 @@ bool TPartition::CompactRequestedBlob(const TRequestedBlob& requestedBlob,
261266 TMaybe<ui64> firstBlobOffset = requestedBlob.Offset ;
262267
263268 for (TBlobIterator it (requestedBlob.Key , requestedBlob.Value ); it.IsValid (); it.Next ()) {
269+ LOG_D (" Compaction: case 18" );
264270 TBatch batch = it.GetBatch ();
265271 batch.Unpack ();
266272
267273 for (const auto & blob : batch.Blobs ) {
274+ LOG_D (" Compaction: case 19" );
268275 if (wasThePreviousBlobBig && blob.PartData && (blob.PartData ->PartNo != 0 )) {
276+ LOG_D (" Compaction: case 20" );
269277 // надо продолжить писать большое сообщение
270278 CompactionBlobEncoder.NewHead .PartNo = blob.PartData ->PartNo ;
271279 CompactionBlobEncoder.NewPartitionedBlob (Partition,
@@ -278,6 +286,8 @@ bool TPartition::CompactRequestedBlob(const TRequestedBlob& requestedBlob,
278286 needToCompactHead,
279287 MaxBlobSize,
280288 blob.PartData ->PartNo );
289+ } else {
290+ LOG_D (" Compaction: case 21" );
281291 }
282292 wasThePreviousBlobBig = false ;
283293
@@ -310,12 +320,17 @@ bool TPartition::CompactRequestedBlob(const TRequestedBlob& requestedBlob,
310320
311321 blobCreationUnixTime = std::max (blobCreationUnixTime, blob.WriteTimestamp );
312322 if (!ExecRequestForCompaction (msg, parameters, compactionRequest, blobCreationUnixTime)) {
323+ LOG_D (" Compaction: case 22" );
313324 return false ;
325+ } else {
326+ LOG_D (" Compaction: case 23" );
314327 }
315328
316329 firstBlobOffset = Nothing ();
317330 }
331+ LOG_D (" Compaction: case 25" );
318332 }
333+ LOG_D (" Compaction: case 26" );
319334
320335 return true ;
321336}
@@ -329,6 +344,7 @@ void TPartition::RenameCompactedBlob(TDataKey& k,
329344 const auto & ctx = ActorContext ();
330345
331346 if (!CompactionBlobEncoder.PartitionedBlob .IsInited ()) {
347+ LOG_D (" Compaction: case 12" );
332348 CompactionBlobEncoder.NewPartitionedBlob (Partition,
333349 CompactionBlobEncoder.NewHead .Offset ,
334350 " " , // SourceId
@@ -338,22 +354,30 @@ void TPartition::RenameCompactedBlob(TDataKey& k,
338354 parameters.HeadCleared , // headCleared
339355 needToCompactHead, // needCompactHead
340356 MaxBlobSize);
357+ } else {
358+ LOG_D (" Compaction: case 13" );
341359 }
342360 auto write = CompactionBlobEncoder.PartitionedBlob .Add (k.Key , size, k.Timestamp , false );
343361 if (write && !write->Value .empty ()) {
362+ LOG_D (" Compaction: case 14" );
344363 // надо записать содержимое головы перед первым большим блобом
345364 AddCmdWrite (write, compactionRequest, k.Timestamp , ctx);
346365 CompactionBlobEncoder.CompactedKeys .emplace_back (write->Key , write->Value .size ());
366+ } else {
367+ LOG_D (" Compaction: case 15" );
347368 }
348369
349370 if (const auto & formedBlobs = CompactionBlobEncoder.PartitionedBlob .GetFormedBlobs (); !formedBlobs.empty ()) {
371+ LOG_D (" Compaction: case 16" );
350372 ui32 curWrites = RenameTmpCmdWrites (compactionRequest);
351373 RenameFormedBlobs (formedBlobs,
352374 parameters,
353375 curWrites,
354376 compactionRequest,
355377 CompactionBlobEncoder,
356378 ctx);
379+ } else {
380+ LOG_D (" Compaction: case 17" );
357381 }
358382
359383 k.BlobKeyToken ->NeedDelete = false ;
@@ -376,8 +400,11 @@ void TPartition::BlobsForCompactionWereRead(const TVector<NPQ::TRequestedBlob>&
376400 if (!CompactionBlobEncoder.Head .GetCount () &&
377401 !CompactionBlobEncoder.NewHead .GetCount () &&
378402 CompactionBlobEncoder.IsEmpty ()) {
403+ LOG_D (" Compaction: case 09" );
379404 // если это первое сообщение, то надо поправить StartOffset
380405 CompactionBlobEncoder.StartOffset = BlobEncoder.StartOffset ;
406+ } else {
407+ LOG_D (" Compaction: case 10" );
381408 }
382409
383410 CompactionBlobEncoder.NewHead .Clear ();
@@ -399,15 +426,20 @@ void TPartition::BlobsForCompactionWereRead(const TVector<NPQ::TRequestedBlob>&
399426 DumpZones (__FILE__, __LINE__);
400427
401428 for (size_t i = 0 ; i < KeysForCompaction.size (); ++i) {
429+ LOG_D (" Compaction: case 11" );
402430 auto & [k, pos] = KeysForCompaction[i];
403431 bool needToCompactHead = (parameters.CurOffset < k.Key .GetOffset ());
404432
405433 if (pos == Max<size_t >()) {
434+ LOG_D (" Compaction: case 01" );
406435 // большой блоб надо переименовать
407436 LOG_D (" Rename key " << k.Key .ToString ());
408437
409438 if (!WasTheLastBlobBig) {
439+ LOG_D (" Compaction: case 02" );
410440 needToCompactHead = true ;
441+ } else {
442+ LOG_D (" Compaction: case 03" );
411443 }
412444 LOG_D (" Need to compact head " << needToCompactHead);
413445
@@ -427,32 +459,41 @@ void TPartition::BlobsForCompactionWereRead(const TVector<NPQ::TRequestedBlob>&
427459
428460 WasTheLastBlobBig = true ;
429461 } else {
462+ LOG_D (" Compaction: case 04" );
430463 // маленький блоб надо дописать
431464 LOG_D (" Append blob for key " << k.Key .ToString ());
432465 LOG_D (" Need to compact head " << needToCompactHead);
433466
434467 const TRequestedBlob& requestedBlob = blobs[pos];
435468 if (!CompactRequestedBlob (requestedBlob, parameters, needToCompactHead, compactionRequest.Get (), blobCreationUnixTime, WasTheLastBlobBig)) {
469+ LOG_D (" Compaction: case 05" );
436470 LOG_D (" Can't append blob for key " << k.Key .ToString ());
437471 Y_FAIL (" Something went wrong" );
438472 return ;
473+ } else {
474+ LOG_D (" Compaction: case 06" );
439475 }
440476
441477 WasTheLastBlobBig = false ;
442478 }
443479
444480 DumpZones (__FILE__, __LINE__);
445481 }
482+ LOG_D (" Compaction: case 24" );
446483
447484 if (!CompactionBlobEncoder.IsLastBatchPacked ()) {
485+ LOG_D (" Compaction: case 07" );
448486 CompactionBlobEncoder.PackLastBatch ();
487+ } else {
488+ LOG_D (" Compaction: case 08" );
449489 }
450490
451491 CompactionBlobEncoder.HeadCleared = parameters.HeadCleared ;
452492
453493 EndProcessWritesForCompaction (compactionRequest.Get (), blobCreationUnixTime, ctx);
454494
455495 DumpZones (__FILE__, __LINE__);
496+
456497 // for debugging purposes
457498 DumpKeyValueRequest (compactionRequest->Record );
458499
0 commit comments