@@ -1431,12 +1431,13 @@ async fn compaction_self_kick_advances_without_periodic_tick()
14311431 let id_allocator = Arc :: new ( AtomicU64 :: new ( 10 ) ) ;
14321432 let executor = LocalCompactionExecutor :: with_id_allocator ( Arc :: clone ( & sst_cfg) , id_allocator) ;
14331433 let driver = Arc :: new ( db. compaction_driver ( ) ) ;
1434- let worker_config = CompactionWorkerConfig :: new ( None , 1 , 1 , CascadeConfig :: default ( ) ) ;
1434+ let worker_config =
1435+ CompactionWorkerConfig :: new ( None , 1 , 1 , CascadeConfig :: new ( 0 , Duration :: from_millis ( 0 ) ) ) ;
14351436 let handle = driver. spawn_worker ( Arc :: clone ( & db. executor ) , planner, executor, worker_config) ;
14361437
14371438 handle. kick ( ) ;
14381439
1439- let deadline = Instant :: now ( ) + Duration :: from_secs ( 2 ) ;
1440+ let deadline = Instant :: now ( ) + Duration :: from_secs ( 10 ) ;
14401441 loop {
14411442 let snapshot = db. manifest . snapshot_latest ( db. manifest_table ) . await ?;
14421443 if let Some ( version) = snapshot. latest_version . as_ref ( ) {
@@ -1457,6 +1458,7 @@ async fn compaction_self_kick_advances_without_periodic_tick()
14571458 "expected L2 compaction to complete without new writes"
14581459 ) ;
14591460
1461+ handle. shutdown ( ) . await ;
14601462 fs:: remove_dir_all ( & db_root) ?;
14611463 Ok ( ( ) )
14621464}
@@ -2386,7 +2388,7 @@ async fn compaction_periodic_trigger_records_metrics() -> Result<(), Box<dyn std
23862388 wait_for_executions( & executed, 1 ) . await ,
23872389 "expected compaction execution"
23882390 ) ;
2389- drop ( handle) ;
2391+ handle. shutdown ( ) . await ;
23902392
23912393 let snapshot = metrics. snapshot ( ) ;
23922394 assert ! ( snapshot. trigger_periodic >= 1 ) ;
@@ -2473,7 +2475,7 @@ async fn compaction_kick_triggers_without_periodic_tick() -> Result<(), Box<dyn
24732475 wait_for_executions( & executed, 1 ) . await ,
24742476 "expected compaction work after kick"
24752477 ) ;
2476- drop ( handle) ;
2478+ handle. shutdown ( ) . await ;
24772479
24782480 let snapshot = metrics. snapshot ( ) ;
24792481 assert_eq ! ( snapshot. trigger_kick, 1 ) ;
@@ -2482,6 +2484,74 @@ async fn compaction_kick_triggers_without_periodic_tick() -> Result<(), Box<dyn
24822484 Ok ( ( ) )
24832485}
24842486
2487+ #[ tokio:: test( flavor = "current_thread" ) ]
2488+ async fn cascade_scheduling_queue_size_one ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2489+ let schema = Arc :: new ( Schema :: new ( vec ! [
2490+ Field :: new( "id" , DataType :: Utf8 , false ) ,
2491+ Field :: new( "v" , DataType :: Int32 , false ) ,
2492+ ] ) ) ;
2493+ let mode_cfg = SchemaBuilder :: from_schema ( Arc :: clone ( & schema) )
2494+ . primary_key ( "id" )
2495+ . build ( )
2496+ . expect ( "schema builder" ) ;
2497+ let executor = Arc :: new ( TokioExecutor :: default ( ) ) ;
2498+ let mut inner: DbInner < InMemoryFs , TokioExecutor > =
2499+ DB :: new ( mode_cfg, Arc :: clone ( & executor) ) . await ?. into_inner ( ) ;
2500+ let metrics = Arc :: new ( CompactionMetrics :: new ( ) ) ;
2501+ inner. compaction_metrics = Some ( Arc :: clone ( & metrics) ) ;
2502+
2503+ let entry = SstEntry :: new (
2504+ SsTableId :: new ( 1 ) ,
2505+ None ,
2506+ None ,
2507+ Path :: from ( "L0/001.parquet" ) ,
2508+ None ,
2509+ ) ;
2510+ inner
2511+ . manifest
2512+ . apply_version_edits (
2513+ inner. manifest_table ,
2514+ & [ VersionEdit :: AddSsts {
2515+ level : 0 ,
2516+ entries : vec ! [ entry] ,
2517+ } ] ,
2518+ )
2519+ . await ?;
2520+
2521+ let executed = Arc :: new ( StdMutex :: new ( Vec :: new ( ) ) ) ;
2522+ let planner = CascadePlanner ;
2523+ let executor = CountingExecutor :: new ( Arc :: clone ( & executed) ) ;
2524+ let driver = Arc :: new ( inner. compaction_driver ( ) ) ;
2525+ let worker_config =
2526+ CompactionWorkerConfig :: new ( None , 1 , 1 , CascadeConfig :: new ( 1 , Duration :: from_millis ( 0 ) ) ) ;
2527+ let handle = driver. spawn_worker (
2528+ Arc :: clone ( & inner. executor ) ,
2529+ planner,
2530+ executor,
2531+ worker_config,
2532+ ) ;
2533+
2534+ handle. kick ( ) ;
2535+ assert ! (
2536+ wait_for_executions( & executed, 2 ) . await ,
2537+ "expected L0->L1 and L1->L2 executions with queue size 1"
2538+ ) ;
2539+ handle. shutdown ( ) . await ;
2540+
2541+ let tasks = executed. lock ( ) . expect ( "executed lock" ) . clone ( ) ;
2542+ let l0_to_l1 = tasks
2543+ . iter ( )
2544+ . filter ( |( source, target) | * source == 0 && * target == 1 )
2545+ . count ( ) ;
2546+ let l1_to_l2 = tasks
2547+ . iter ( )
2548+ . filter ( |( source, target) | * source == 1 && * target == 2 )
2549+ . count ( ) ;
2550+ assert_eq ! ( l0_to_l1, 1 ) ;
2551+ assert_eq ! ( l1_to_l2, 1 ) ;
2552+ Ok ( ( ) )
2553+ }
2554+
24852555#[ tokio:: test( flavor = "current_thread" ) ]
24862556async fn cascade_scheduling_respects_budget ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
24872557 let schema = Arc :: new ( Schema :: new ( vec ! [
@@ -2534,7 +2604,7 @@ async fn cascade_scheduling_respects_budget() -> Result<(), Box<dyn std::error::
25342604 wait_for_executions( & executed, 1 ) . await ,
25352605 "expected initial compaction execution"
25362606 ) ;
2537- drop ( handle) ;
2607+ handle. shutdown ( ) . await ;
25382608
25392609 let tasks = executed. lock ( ) . expect ( "executed lock" ) . clone ( ) ;
25402610 let l0_to_l1 = tasks
@@ -2617,7 +2687,7 @@ async fn cascade_scheduling_respects_cooldown() -> Result<(), Box<dyn std::error
26172687 "expected two L0->L1 executions and one cascade"
26182688 ) ;
26192689
2620- drop ( handle) ;
2690+ handle. shutdown ( ) . await ;
26212691
26222692 let tasks = executed. lock ( ) . expect ( "executed lock" ) . clone ( ) ;
26232693 let l0_to_l1 = tasks
0 commit comments