31
31
import java .util .function .BiPredicate ;
32
32
import java .util .regex .Matcher ;
33
33
import java .util .regex .Pattern ;
34
- import java .util .stream .Collectors ;
35
34
36
35
import com .google .common .annotations .VisibleForTesting ;
37
36
import com .google .common .base .Preconditions ;
@@ -343,7 +342,7 @@ public synchronized Collection<AbstractCompactionTask> getNextBackgroundTasks(in
343
342
if (expirationTasks != null )
344
343
return expirationTasks ;
345
344
346
- return getNextBackgroundTasks (getNextCompactionAggregates (), gcBefore );
345
+ return getNextBackgroundTasks (getNextCompactionAggregates (), gcBefore , this );
347
346
}
348
347
349
348
/// Check for fully expired sstables and return a collection of expiration tasks if found.
@@ -401,21 +400,23 @@ public Set<CompactionSSTable> getFullyExpiredSSTables(int gcBefore)
401
400
controller .getIgnoreOverlapsInExpirationCheck ());
402
401
}
403
402
404
- /// Used by CNDB where compaction aggregates come from etcd rather than the strategy
403
+ /// Used by CNDB where compaction aggregates come from etcd rather than the strategy.
405
404
/// @return collection of `AbstractCompactionTask`, which could be either a `CompactionTask` or a `UnifiedCompactionTask`
406
- public synchronized Collection <AbstractCompactionTask > getNextBackgroundTasks (Collection <CompactionAggregate > aggregates , int gcBefore )
405
+ public synchronized Collection <AbstractCompactionTask > getNextBackgroundTasks (Collection <CompactionAggregate > aggregates , int gcBefore ,
406
+ CompactionObserver compositeCompactionObserver )
407
407
{
408
408
controller .onStrategyBackgroundTaskRequest ();
409
- return createCompactionTasks (aggregates , gcBefore );
409
+ return createCompactionTasks (aggregates , gcBefore , compositeCompactionObserver );
410
410
}
411
411
412
- private Collection <AbstractCompactionTask > createCompactionTasks (Collection <CompactionAggregate > aggregates , int gcBefore )
412
+ private Collection <AbstractCompactionTask > createCompactionTasks (Collection <CompactionAggregate > aggregates , int gcBefore ,
413
+ CompactionObserver compositeCompactionObserver )
413
414
{
414
415
Collection <AbstractCompactionTask > tasks = new ArrayList <>(aggregates .size ());
415
416
try
416
417
{
417
418
for (CompactionAggregate aggregate : aggregates )
418
- createAndAddTasks (gcBefore , (CompactionAggregate .UnifiedAggregate ) aggregate , tasks );
419
+ createAndAddTasks (gcBefore , (CompactionAggregate .UnifiedAggregate ) aggregate , tasks , compositeCompactionObserver );
419
420
420
421
return tasks ;
421
422
}
@@ -426,7 +427,8 @@ private Collection<AbstractCompactionTask> createCompactionTasks(Collection<Comp
426
427
}
427
428
428
429
/// Create compaction tasks for the given aggregate and add them to the given tasks list.
429
- public void createAndAddTasks (int gcBefore , CompactionAggregate .UnifiedAggregate aggregate , Collection <? super UnifiedCompactionTask > tasks )
430
+ public void createAndAddTasks (int gcBefore , CompactionAggregate .UnifiedAggregate aggregate ,
431
+ Collection <? super UnifiedCompactionTask > tasks , CompactionObserver compositeCompactionObserver )
430
432
{
431
433
CompactionPick selected = aggregate .getSelected ();
432
434
int parallelism = aggregate .getPermittedParallelism ();
@@ -440,7 +442,7 @@ public void createAndAddTasks(int gcBefore, CompactionAggregate.UnifiedAggregate
440
442
{
441
443
// This will ignore the range of the operation, which is fine.
442
444
backgroundCompactions .setSubmitted (this , transaction .opId (), aggregate );
443
- createAndAddTasks (gcBefore , transaction , aggregate .operationRange (), aggregate .keepOriginals (), getShardingStats (aggregate ), parallelism , tasks );
445
+ createAndAddTasks (gcBefore , transaction , aggregate .operationRange (), aggregate .keepOriginals (), getShardingStats (aggregate ), parallelism , tasks , compositeCompactionObserver );
444
446
}
445
447
else
446
448
{
@@ -612,7 +614,7 @@ void createAndAddTasks(int gcBefore,
612
614
int parallelism ,
613
615
Collection <? super CompactionTask > tasks )
614
616
{
615
- createAndAddTasks (gcBefore , transaction , null , false , shardingStats , parallelism , tasks );
617
+ createAndAddTasks (gcBefore , transaction , null , false , shardingStats , parallelism , tasks , this );
616
618
}
617
619
618
620
@ VisibleForTesting
@@ -622,10 +624,11 @@ void createAndAddTasks(int gcBefore,
622
624
boolean keepOriginals ,
623
625
ShardingStats shardingStats ,
624
626
int parallelism ,
625
- Collection <? super UnifiedCompactionTask > tasks )
627
+ Collection <? super UnifiedCompactionTask > tasks ,
628
+ CompactionObserver compositeCompactionObserver )
626
629
{
627
630
if (controller .parallelizeOutputShards () && parallelism > 1 )
628
- tasks .addAll (createParallelCompactionTasks (transaction , operationRange , keepOriginals , shardingStats , gcBefore , parallelism ));
631
+ tasks .addAll (createParallelCompactionTasks (transaction , operationRange , keepOriginals , shardingStats , gcBefore , parallelism , compositeCompactionObserver ));
629
632
else
630
633
tasks .add (createCompactionTask (transaction , operationRange , keepOriginals , shardingStats , gcBefore ));
631
634
}
@@ -697,7 +700,8 @@ private Collection<UnifiedCompactionTask> createParallelCompactionTasks(Lifecycl
697
700
boolean keepOriginals ,
698
701
ShardingStats shardingStats ,
699
702
int gcBefore ,
700
- int parallelism )
703
+ int parallelism ,
704
+ CompactionObserver compositeCompactionObserver )
701
705
{
702
706
final int coveredShardCount = shardingStats .coveredShardCount ;
703
707
assert parallelism > 1 ;
@@ -706,7 +710,7 @@ private Collection<UnifiedCompactionTask> createParallelCompactionTasks(Lifecycl
706
710
ShardManager shardManager = getShardManager ();
707
711
CompositeLifecycleTransaction compositeTransaction = new CompositeLifecycleTransaction (transaction );
708
712
SharedCompactionProgress sharedProgress = new SharedCompactionProgress (transaction .opId (), transaction .opType (), TableOperation .Unit .BYTES );
709
- SharedCompactionObserver sharedObserver = new SharedCompactionObserver (this );
713
+ SharedCompactionObserver sharedObserver = new SharedCompactionObserver (compositeCompactionObserver );
710
714
SharedTableOperation sharedOperation = new SharedTableOperation (sharedProgress );
711
715
List <UnifiedCompactionTask > tasks = shardManager .splitSSTablesInShardsLimited (
712
716
sstables ,
0 commit comments