@@ -208,7 +208,8 @@ public void start() {
208
208
TRACE ,
209
209
"Scheduling backfill process to start in {0} milliseconds" ,
210
210
backfillConfiguration .initialDelay ());
211
- scheduler = Executors .newSingleThreadScheduledExecutor ();
211
+ scheduler = Executors .newScheduledThreadPool (
212
+ 2 ); // Two threads: one for autonomous backfill, one for on-demand backfill
212
213
scheduler .scheduleAtFixedRate (
213
214
this ::detectGaps ,
214
215
backfillConfiguration .initialDelay (),
@@ -333,6 +334,11 @@ private void backfillGap(LongRange gap, BackfillType backfillType) throws Interr
333
334
// to avoid deadlocks, since blocks that fail verification are not persisted
334
335
getLatch (backfillType ).set (new CountDownLatch (batchOfBlocks .size ()));
335
336
337
+ if (batchOfBlocks .isEmpty ()) {
338
+ LOGGER .log (TRACE , "No blocks fetched for gap {0}, skipping" , chunk );
339
+ continue ; // Skip empty batches
340
+ }
341
+
336
342
// Process each fetched block
337
343
for (BlockUnparsed blockUnparsed : batchOfBlocks ) {
338
344
long blockNumber = extractBlockNumber (blockUnparsed );
@@ -349,21 +355,25 @@ private void backfillGap(LongRange gap, BackfillType backfillType) throws Interr
349
355
boolean backfillFinished = getLatch (backfillType ).get ().await (timeout , TimeUnit .MILLISECONDS );
350
356
351
357
// Check if the backfill finished successfully
352
- if (!backfillFinished ) {
358
+ if (backfillFinished ) {
359
+ // just log a victory message for each chunk
360
+ LOGGER .log (TRACE , "Successfully backfilled gap {0}" , chunk );
361
+ } else {
353
362
LOGGER .log (TRACE , "Backfill for gap {0} did not finish in time" , chunk );
354
363
backfillFetchErrors .increment ();
355
364
// If it didn't finish, we will retry it later but move on to next chunk
356
- } else {
357
- // just log a victory message for each chunk
358
- LOGGER .log (TRACE , "Successfully backfilled gap {0}" , chunk );
359
365
}
360
366
361
367
// Cooldown between batches
362
368
Thread .sleep (backfillConfiguration .delayBetweenBatches ());
363
369
}
364
370
365
371
LOGGER .log (
366
- TRACE , "Completed backfilling of type {0} gap from {1} to {2}" , backfillType , gap .start (), gap .end ());
372
+ TRACE ,
373
+ "Completed backfilling task (does not mean success or failure, just completion) of type {0} gap from {1} to {2} " ,
374
+ backfillType ,
375
+ gap .start (),
376
+ gap .end ());
367
377
if (backfillType .equals (BackfillType .ON_DEMAND )) {
368
378
onDemandBackfillStartBlock .set (-1 ); // Reset on-demand start block after backfill
369
379
}
0 commit comments