cesiumdb 0.2.2

Blazing fast, persistent key-value store for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
//! Compaction manager - orchestrates all compaction operations
//!
//! This is the main entry point for the compaction system, coordinating
//! scheduling, execution, and background threads.

use std::{
    collections::HashSet,
    path::PathBuf,
    sync::{
        Arc,
        atomic::{
            AtomicBool,
            AtomicU64,
            AtomicUsize,
            Ordering,
        },
    },
    thread,
    time::Duration,
};

use parking_lot::{
    Mutex,
    RwLock,
};

use crate::{
    compaction::{
        AdaptiveExecutor,
        CompactionExecutor,
        CompactionJob,
        CompactionJobType,
        CompactionQueue,
        CompactionScheduler,
        ParallelCompactionManager,
        ResourceLimits,
        SchedulerConfig,
        SegmentRegistry,
        SubcompactionPlanner,
        WorkloadStats,
    },
    manifest_writer::ManifestWriter,
    version::VersionManager,
};

/// Main compaction manager
///
/// Coordinates all compaction activities including:
/// - Background compaction thread
/// - Adaptive scheduling and execution
/// - Manual compaction requests
pub struct CompactionManager {
    /// Scheduler for picking compaction jobs
    scheduler: Arc<CompactionScheduler>,

    /// Adaptive executor for running jobs
    executor: Option<AdaptiveExecutor>,

    /// Compaction queue
    queue: Arc<CompactionQueue>,

    /// Version manager
    version_manager: Arc<VersionManager>,

    /// Segment registry for reference tracking
    registry: Arc<SegmentRegistry>,

    /// Parallel compaction coordinator
    parallel_manager: Arc<ParallelCompactionManager>,

    /// Workload statistics
    workload_stats: Arc<WorkloadStats>,

    /// Background thread handle
    bg_thread: Option<thread::JoinHandle<()>>,

    /// Shutdown signal
    shutdown: Arc<AtomicBool>,

    /// Counter for failed compaction jobs
    failed_jobs: Arc<AtomicU64>,

    /// Tracks segments currently being compacted
    ///
    /// Prevents duplicate job scheduling by tracking which segments
    /// are already in-flight. Cleared when jobs complete.
    in_flight_segments: Arc<RwLock<HashSet<u64>>>,

    /// Number of L0 compactions currently in progress
    ///
    /// RocksDB-style: only one L0 compaction at a time to prevent
    /// overlapping reads and write amplification.
    l0_compactions_in_progress: Arc<AtomicUsize>,

    /// Cumulative bytes read by compaction jobs
    bytes_compacted_read: Arc<AtomicU64>,

    /// Cumulative bytes written by compaction jobs
    bytes_compacted_written: Arc<AtomicU64>,
}

impl CompactionManager {
    /// Creates a new compaction manager
    pub fn new(
        base_path: PathBuf,
        version_manager: Arc<VersionManager>,
        manifest: Option<Arc<Mutex<ManifestWriter>>>,
    ) -> Self {
        let registry = Arc::new(SegmentRegistry::new(base_path.clone()));
        Self::new_with_registry(base_path, version_manager, manifest, registry)
    }

    pub fn new_with_registry(
        base_path: PathBuf,
        version_manager: Arc<VersionManager>,
        manifest: Option<Arc<Mutex<ManifestWriter>>>,
        registry: Arc<SegmentRegistry>,
    ) -> Self {
        Self::new_with_scheduler_config(
            base_path,
            version_manager,
            manifest,
            registry,
            SchedulerConfig::default(),
        )
    }

    pub fn new_with_scheduler_config(
        base_path: PathBuf,
        version_manager: Arc<VersionManager>,
        manifest: Option<Arc<Mutex<ManifestWriter>>>,
        registry: Arc<SegmentRegistry>,
        scheduler_config: SchedulerConfig,
    ) -> Self {
        let queue = Arc::new(CompactionQueue::new());
        let scheduler = Arc::new(CompactionScheduler::with_config(
            scheduler_config,
            Arc::clone(&version_manager),
        ));
        let parallel_manager = Arc::new(ParallelCompactionManager::new(4));
        let workload_stats = Arc::new(WorkloadStats::new());

        let executor_impl = Arc::new(CompactionExecutor::with_planner(
            Arc::clone(&version_manager),
            base_path,
            manifest,
            Arc::clone(&registry),
            SubcompactionPlanner::new(),
        ));

        let limits = ResourceLimits::default();
        let executor = AdaptiveExecutor::new(
            executor_impl,
            Arc::clone(&queue),
            Arc::clone(&version_manager),
            limits,
        );

        Self {
            scheduler,
            executor: Some(executor),
            queue,
            version_manager,
            registry,
            parallel_manager,
            workload_stats,
            bg_thread: None,
            shutdown: Arc::new(AtomicBool::new(false)),
            failed_jobs: Arc::new(AtomicU64::new(0)),
            in_flight_segments: Arc::new(RwLock::new(HashSet::new())),
            l0_compactions_in_progress: Arc::new(AtomicUsize::new(0)),
            bytes_compacted_read: Arc::new(AtomicU64::new(0)),
            bytes_compacted_written: Arc::new(AtomicU64::new(0)),
        }
    }

    /// Starts the background compaction thread
    pub fn start(&mut self) {
        if self.bg_thread.is_some() {
            return; // Already started
        }

        let queue = Arc::clone(&self.queue);
        let scheduler = Arc::clone(&self.scheduler);
        let shutdown = Arc::clone(&self.shutdown);
        let version_manager = Arc::clone(&self.version_manager);
        let in_flight = Arc::clone(&self.in_flight_segments);
        let max_concurrent = self.scheduler.config().max_concurrent_jobs;
        let l0_in_progress = Arc::clone(&self.l0_compactions_in_progress);
        let registry = Arc::clone(&self.registry);

        let handle = thread::spawn(move || {
            Self::background_compaction_loop(
                queue,
                scheduler,
                shutdown,
                version_manager,
                in_flight,
                max_concurrent,
                l0_in_progress,
                registry,
            );
        });

        self.bg_thread = Some(handle);
    }

    /// Background compaction loop
    fn background_compaction_loop(
        queue: Arc<CompactionQueue>,
        scheduler: Arc<CompactionScheduler>,
        shutdown: Arc<AtomicBool>,
        version_manager: Arc<VersionManager>,
        in_flight: Arc<RwLock<HashSet<u64>>>,
        max_concurrent: usize,
        l0_in_progress: Arc<AtomicUsize>,
        registry: Arc<SegmentRegistry>,
    ) {
        while !shutdown.load(Ordering::Relaxed) {
            // Drain completed jobs and clear their in-flight segments
            for job in queue.drain_completed() {
                {
                    let mut in_flight_guard = in_flight.write();
                    for seg in &job.input.segments {
                        in_flight_guard.remove(&seg.id());
                    }
                    if let Some(ref next_input) = job.next_level_input {
                        for seg in &next_input.segments {
                            in_flight_guard.remove(&seg.id());
                        }
                    }
                }
                // Decrement L0 compaction counter if applicable
                if job.job_type == CompactionJobType::L0Compaction {
                    l0_in_progress.fetch_sub(1, Ordering::Relaxed);
                }
            }

            // Clean up obsolete segments after dropping completed jobs
            let (deleted, bytes_freed) = registry.cleanup();
            if deleted > 0 {
                tracing::info!(
                    segments_deleted = deleted,
                    bytes_freed = bytes_freed,
                    "Cleaned up obsolete segments in background loop"
                );
            }

            // If the queue is completely idle, clear in-flight tracking so
            // future compactions can be scheduled for those segments.
            if queue.is_empty() {
                let mut in_flight_guard = in_flight.write();
                in_flight_guard.clear();
                l0_in_progress.store(0, Ordering::Relaxed);
            }

            // Fill the queue up to max_concurrent with non-conflicting jobs.
            let mut jobs_scheduled = 0usize;
            loop {
                let total_jobs = queue.queued_count() + queue.in_progress_count();
                if total_jobs >= max_concurrent {
                    break;
                }
                let slots = max_concurrent - total_jobs;

                let version = version_manager.current();
                let in_flight_snapshot = {
                    let guard = in_flight.read();
                    guard.clone()
                };

                let jobs = scheduler.pick_compactions(&version, &in_flight_snapshot, slots);
                if jobs.is_empty() {
                    break;
                }

                for job in jobs {
                    // RocksDB-style: serialize L0 compactions to one at a time
                    if job.job_type == CompactionJobType::L0Compaction &&
                        l0_in_progress.load(Ordering::Relaxed) > 0
                    {
                        tracing::debug!(job_id = job.id, "bg_loop: skipping L0 job, serialization");
                        continue;
                    }

                    // Double-check no segment is already in-flight
                    let is_dup = {
                        let guard = in_flight.read();
                        job.input
                            .segments
                            .iter()
                            .any(|seg| guard.contains(&seg.id())) ||
                            job.next_level_input.as_ref().is_some_and(|next| {
                                next.segments.iter().any(|seg| guard.contains(&seg.id()))
                            })
                    };
                    if is_dup {
                        continue;
                    }

                    // Mark segments as in-flight
                    {
                        let mut guard = in_flight.write();
                        for seg in &job.input.segments {
                            guard.insert(seg.id());
                        }
                        if let Some(ref next) = job.next_level_input {
                            for seg in &next.segments {
                                guard.insert(seg.id());
                            }
                        }
                    }

                    if job.job_type == CompactionJobType::L0Compaction {
                        l0_in_progress.fetch_add(1, Ordering::Relaxed);
                    }

                    queue.enqueue(job);
                    jobs_scheduled += 1;
                }
            }

            // Adaptive sleep: stay responsive when there's work, back off when idle
            if jobs_scheduled > 0 {
                thread::sleep(Duration::from_millis(10));
            } else {
                thread::sleep(Duration::from_millis(100));
            }
        }
    }

    /// Triggers a manual compaction (user-requested)
    ///
    /// This will compact the entire database or a specific key range.
    pub fn compact(&self) {
        // Try to schedule compactions repeatedly until no more are needed
        // This will compact multiple levels if necessary
        for _ in 0..10 {
            // Get FRESH version each iteration (not stale snapshot)
            let version = self.version_manager.current();

            if let Some(job) = self.scheduler.pick_compaction(&version) {
                self.queue.enqueue(job);
            } else {
                break; // No more compactions needed
            }
        }
    }

    /// Notifies the compaction manager of a memtable flush
    ///
    /// This triggers L0 compaction checks. To prevent unbounded queue
    /// growth, we only enqueue if we're below capacity and the segments
    /// aren't already being compacted.
    pub fn notify_flush(&self) {
        let total_jobs = self.queue.queued_count() + self.queue.in_progress_count();
        if total_jobs >= self.scheduler.config().max_concurrent_jobs {
            tracing::debug!(
                total_jobs,
                max = self.scheduler.config().max_concurrent_jobs,
                "notify_flush: at capacity"
            );
            return;
        }

        let version = self.version_manager.current();
        let slots = self.scheduler.config().max_concurrent_jobs - total_jobs;
        let in_flight_snapshot = {
            let guard = self.in_flight_segments.read();
            guard.clone()
        };

        let jobs = self
            .scheduler
            .pick_compactions(&version, &in_flight_snapshot, slots);
        if jobs.is_empty() {
            tracing::debug!(
                l0_count = version.l0.len(),
                "notify_flush: no compaction needed"
            );
            return;
        }

        for job in jobs {
            // RocksDB-style: serialize L0 compactions
            if job.job_type == CompactionJobType::L0Compaction &&
                self.l0_compactions_in_progress.load(Ordering::Relaxed) > 0
            {
                tracing::debug!(
                    job_id = job.id,
                    "notify_flush: skipping L0 job, serialization"
                );
                continue;
            }
            if self.is_duplicate_job(&job) {
                tracing::debug!(job_id = job.id, "notify_flush: duplicate job");
                continue;
            }
            self.mark_in_flight(&job);
            if job.job_type == CompactionJobType::L0Compaction {
                self.l0_compactions_in_progress
                    .fetch_add(1, Ordering::Relaxed);
            }
            self.queue.enqueue(job);
        }
    }

    /// Returns true if writes should be stalled due to too many L0 files.
    ///
    /// When L0 has too many files, compaction can't keep up and writes should
    /// be slowed down to give compaction time to catch up.
    pub fn should_stall_writes(&self) -> bool {
        let version = self.version_manager.current();
        version.l0.len() >= self.scheduler.config().l0_stop_writes_trigger
    }

    /// Records a read operation for workload tracking
    pub fn record_read(&self, bytes_read: u64) {
        self.workload_stats.record_get(bytes_read);
    }

    /// Records a write operation for workload tracking
    pub fn record_write(&self, bytes_written: u64) {
        self.workload_stats.record_put(bytes_written);
    }

    /// Records a scan operation for workload tracking
    pub fn record_scan(&self, num_keys: u64, bytes_read: u64) {
        self.workload_stats.record_scan(num_keys, bytes_read);
    }

    /// Returns the segment registry
    pub fn registry(&self) -> Arc<SegmentRegistry> {
        Arc::clone(&self.registry)
    }

    /// Records compaction I/O for throughput tracking
    pub fn record_compaction_io(&self, bytes_read: u64, bytes_written: u64) {
        self.bytes_compacted_read
            .fetch_add(bytes_read, Ordering::Relaxed);
        self.bytes_compacted_written
            .fetch_add(bytes_written, Ordering::Relaxed);
    }

    /// Returns current compaction statistics
    pub fn stats(&self) -> CompactionStats {
        let queue_stats = self.queue.stats();
        let parallel_stats = self.parallel_manager.stats();
        let workload_analysis = self.workload_stats.analyze();
        let registry_stats = self.registry.stats();

        // Read I/O counters from the executor (where they're actually updated)
        let (bytes_read, bytes_written) = self
            .executor
            .as_ref()
            .map(|e| e.compaction_io())
            .unwrap_or((0, 0));

        CompactionStats {
            queued_jobs: queue_stats.queued,
            in_progress_jobs: queue_stats.in_progress,
            completed_jobs: queue_stats.completed,
            failed_jobs: self.failed_jobs.load(Ordering::Relaxed),
            parallel_utilization: parallel_stats.utilization,
            workload_pattern: format!("{:?}", workload_analysis.pattern),
            pending_deletion_segments: registry_stats.pending_deletion,
            bytes_compacted_read: bytes_read,
            bytes_compacted_written: bytes_written,
        }
    }

    /// Shuts down the compaction manager
    pub fn shutdown(mut self) {
        // Signal shutdown
        self.shutdown.store(true, Ordering::Relaxed);

        // Shutdown queue
        self.queue.shutdown();

        // Wait for background thread
        if let Some(handle) = self.bg_thread.take() {
            let _result = handle.join();
        }

        // Shutdown executor
        if let Some(executor) = self.executor.take() {
            executor.shutdown();
        }
    }

    /// Checks if any input segments are already being compacted
    fn is_duplicate_job(&self, job: &CompactionJob) -> bool {
        let in_flight = self.in_flight_segments.read();

        // Check input segments
        for seg in &job.input.segments {
            if in_flight.contains(&seg.id()) {
                return true;
            }
        }

        // Check next level inputs
        if let Some(ref next_input) = job.next_level_input {
            for seg in &next_input.segments {
                if in_flight.contains(&seg.id()) {
                    return true;
                }
            }
        }

        false
    }

    /// Marks job segments as in-flight
    fn mark_in_flight(&self, job: &CompactionJob) {
        let mut in_flight = self.in_flight_segments.write();

        for seg in &job.input.segments {
            in_flight.insert(seg.id());
        }

        if let Some(ref next_input) = job.next_level_input {
            for seg in &next_input.segments {
                in_flight.insert(seg.id());
            }
        }
    }

    /// Clears in-flight status after job completes
    pub fn clear_in_flight(&self, job: &CompactionJob) {
        let mut in_flight = self.in_flight_segments.write();

        for seg in &job.input.segments {
            in_flight.remove(&seg.id());
        }

        if let Some(ref next_input) = job.next_level_input {
            for seg in &next_input.segments {
                in_flight.remove(&seg.id());
            }
        }
    }
}

impl Drop for CompactionManager {
    fn drop(&mut self) {
        self.shutdown.store(true, Ordering::Relaxed);
        self.queue.shutdown();

        // Join background thread to prevent orphaned threads
        if let Some(handle) = self.bg_thread.take() {
            let _ = handle.join();
        }

        // Shutdown executor if still present
        if let Some(executor) = self.executor.take() {
            executor.shutdown();
        }
    }
}

/// Statistics about compaction operations
#[derive(Debug, Clone)]
pub struct CompactionStats {
    /// Number of jobs waiting to be processed
    pub queued_jobs: usize,

    /// Number of jobs currently being processed
    pub in_progress_jobs: usize,

    /// Total number of jobs completed
    pub completed_jobs: u64,

    /// Total number of failed compaction jobs
    pub failed_jobs: u64,

    /// Parallel execution utilization (0.0-1.0)
    pub parallel_utilization: f64,

    /// Current workload pattern
    pub workload_pattern: String,

    /// Number of segments pending deletion
    pub pending_deletion_segments: usize,

    /// Cumulative bytes read by compaction jobs
    pub bytes_compacted_read: u64,

    /// Cumulative bytes written by compaction jobs
    pub bytes_compacted_written: u64,
}

impl std::fmt::Display for CompactionStats {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "Compaction: queued={}, in_progress={}, completed={}, failed={}, parallel_util={:.0}%, pattern={}, pending_deletion={}, compacted_read={:.2}MB, compacted_written={:.2}MB",
            self.queued_jobs,
            self.in_progress_jobs,
            self.completed_jobs,
            self.failed_jobs,
            self.parallel_utilization * 100.0,
            self.workload_pattern,
            self.pending_deletion_segments,
            self.bytes_compacted_read as f64 / (1024.0 * 1024.0),
            self.bytes_compacted_written as f64 / (1024.0 * 1024.0)
        )
    }
}

#[cfg(test)]
mod tests {
    use tempfile::TempDir;

    use super::*;

    #[test]
    fn test_manager_creation() {
        let temp_dir = TempDir::new().unwrap();
        let version_manager = Arc::new(VersionManager::new(7));

        let manager = CompactionManager::new(temp_dir.path().to_path_buf(), version_manager, None);

        assert!(manager.bg_thread.is_none());
        assert_eq!(manager.registry().live_count(), 0);
    }

    #[test]
    fn test_manager_start() {
        let temp_dir = TempDir::new().unwrap();
        let version_manager = Arc::new(VersionManager::new(7));

        let mut manager =
            CompactionManager::new(temp_dir.path().to_path_buf(), version_manager, None);

        manager.start();
        assert!(manager.bg_thread.is_some());

        manager.shutdown();
    }

    #[test]
    fn test_workload_tracking() {
        let temp_dir = TempDir::new().unwrap();
        let version_manager = Arc::new(VersionManager::new(7));

        let manager = CompactionManager::new(temp_dir.path().to_path_buf(), version_manager, None);

        manager.record_read(1000);
        manager.record_write(2000);
        manager.record_scan(10, 5000);

        let stats = manager.stats();
        assert_eq!(stats.queued_jobs, 0);
    }

    #[test]
    fn test_stats() {
        let temp_dir = TempDir::new().unwrap();
        let version_manager = Arc::new(VersionManager::new(7));

        let manager = CompactionManager::new(temp_dir.path().to_path_buf(), version_manager, None);

        let stats = manager.stats();
        assert_eq!(stats.queued_jobs, 0);
        assert_eq!(stats.in_progress_jobs, 0);
        assert_eq!(stats.completed_jobs, 0);
        assert_eq!(stats.pending_deletion_segments, 0);
    }

    #[test]
    fn test_l0_compaction_serialization() {
        let temp_dir = TempDir::new().unwrap();
        let version_manager = Arc::new(VersionManager::new(7));

        let manager =
            CompactionManager::new(temp_dir.path().to_path_buf(), version_manager.clone(), None);

        // Manually simulate an L0 compaction being in progress
        manager
            .l0_compactions_in_progress
            .fetch_add(1, Ordering::Relaxed);

        // Create a fake L0 job and try to enqueue via notify_flush
        // Since l0_compactions_in_progress > 0, it should be rejected
        let before = manager.queue.queued_count();
        manager.notify_flush();
        let after = manager.queue.queued_count();

        // No new job should be queued (no L0 segments exist, but the guard should still
        // work)
        assert_eq!(after, before);

        // Decrement and verify it allows future L0 compactions
        manager
            .l0_compactions_in_progress
            .fetch_sub(1, Ordering::Relaxed);
        assert_eq!(
            manager.l0_compactions_in_progress.load(Ordering::Relaxed),
            0
        );
    }

    #[test]
    fn test_level_compaction_parallel_with_l0() {
        let temp_dir = TempDir::new().unwrap();
        let version_manager = Arc::new(VersionManager::new(7));

        let manager =
            CompactionManager::new(temp_dir.path().to_path_buf(), version_manager.clone(), None);

        // L0 in progress should NOT block manual compaction of other levels
        manager
            .l0_compactions_in_progress
            .fetch_add(1, Ordering::Relaxed);

        // compact() bypasses the L0 guard (it directly enqueues via scheduler)
        // but with no data, no jobs are picked anyway
        manager.compact();

        // Just verify the state is consistent
        assert_eq!(
            manager.l0_compactions_in_progress.load(Ordering::Relaxed),
            1
        );
    }
}