Source:
public int compactPartitions() { if (partitions.isEmpty()) { logger.info("Skipping compaction as no partitions are assigned."); return 0; } List<PartitionId> partitionSnapshot = new ArrayList<>(partitions); long compactionStartTime = System.currentTimeMillis(); long timeToQuit = System.currentTimeMillis() + compactionTimeLimitMs; int compactionInProgress = 0; doneLatch.set(new CountDownLatch(1)); int totalBlobsPurged = 0; int compactedPartitionCount = 0; try { while (true) { while (compactionInProgress < numThreads) { if (partitionSnapshot.isEmpty()) { break; } PartitionId partitionId = partitionSnapshot.remove(0); executorCompletionService.submit(() -> compactPartition(partitionId)); compactionInProgress++; } totalBlobsPurged += executorCompletionService.take().get(); compactionInProgress--; compactedPartitionCount++; if (System.currentTimeMillis() >= timeToQuit) { logger.info("Compaction terminated due to time limit exceeded."); break; } if (isShuttingDown()) { logger.info("Compaction terminated due to shut down."); break; } if (partitionSnapshot.isEmpty()) { break; } } while (compactionInProgress > 0) { totalBlobsPurged += executorCompletionService.take().get(); compactionInProgress--; compactedPartitionCount++; } doneLatch.get().countDown(); } catch (Throwable th) { logger.error("Hit exception running compaction task", th); } finally { long compactionTime = (System.currentTimeMillis() - compactionStartTime) / 1000; logger.info("Purged blobs in partitions taking seconds", totalBlobsPurged, compactedPartitionCount, compactionTime); } return totalBlobsPurged; }

Target:
public int compactPartitions() { if (partitions.isEmpty()) { logger.info("Skipping compaction as no partitions are assigned."); return 0; } List<PartitionId> partitionSnapshot = new ArrayList<>(partitions); long compactionStartTime = System.currentTimeMillis(); long timeToQuit = System.currentTimeMillis() + compactionTimeLimitMs; int compactionInProgress = 0; doneLatch.set(new CountDownLatch(1)); int totalBlobsPurged = 0; int compactedPartitionCount = 0; try { while (!partitionSnapshot.isEmpty()) { while (compactionInProgress < numThreads) { if (partitionSnapshot.isEmpty()) { break; } PartitionId partitionId = partitionSnapshot.remove(0); executorCompletionService.submit(() -> compactPartition(partitionId)); compactionInProgress++; } try { totalBlobsPurged += executorCompletionService.take().get(); compactedPartitionCount++; } catch (ExecutionException ex) { vcrMetrics.compactionFailureCount.inc(); } compactionInProgress--; if (System.currentTimeMillis() >= timeToQuit) { logger.info("Compaction terminated due to time limit exceeded."); break; } if (isShutDown()) { logger.info("Compaction terminated due to shut down."); break; } } while (compactionInProgress > 0) { try { totalBlobsPurged += executorCompletionService.take().get(); compactedPartitionCount++; } catch (ExecutionException ex) { vcrMetrics.compactionFailureCount.inc(); } compactionInProgress--; } doneLatch.get().countDown(); } catch (Throwable th) { logger.error("Hit exception running compaction task", th); } finally { long compactionTime = (System.currentTimeMillis() - compactionStartTime) / 1000; logger.info("Purged blobs in partitions taking seconds", totalBlobsPurged, compactedPartitionCount, compactionTime); } return totalBlobsPurged; }