LCOV - code coverage report
Current view: top level - pageserver/compaction/tests - tests.rs (source / functions) Coverage Total Hit
Test: 90b23405d17e36048d3bb64e314067f397803f1b.info Lines: 100.0 % 55 55
Test Date: 2024-09-20 13:14:58 Functions: 100.0 % 6 6

            Line data    Source code
       1              : use once_cell::sync::OnceCell;
       2              : use pageserver_compaction::interface::CompactionLayer;
       3              : use pageserver_compaction::simulator::MockTimeline;
       4              : use utils::logging;
       5              : 
       6              : static LOG_HANDLE: OnceCell<()> = OnceCell::new();
       7              : 
       8            2 : pub(crate) fn setup_logging() {
       9            2 :     LOG_HANDLE.get_or_init(|| {
      10            2 :         logging::init(
      11            2 :             logging::LogFormat::Test,
      12            2 :             logging::TracingErrorLayerEnablement::EnableWithRustLogFilter,
      13            2 :             logging::Output::Stdout,
      14            2 :         )
      15            2 :         .expect("Failed to init test logging")
      16            2 :     });
      17            2 : }
      18              : 
      19              : /// Test the extreme case that there are so many updates for a single key that
      20              : /// even if we produce an extremely narrow delta layer, spanning just that one
      21              : /// key, we still too many records to fit in the target file size. We need to
      22              : /// split in the LSN dimension too in that case.
      23              : #[tokio::test]
      24            1 : async fn test_many_updates_for_single_key() {
      25            1 :     setup_logging();
      26            1 :     let mut executor = MockTimeline::new();
      27            1 :     executor.target_file_size = 1_000_000; // 1 MB
      28            1 : 
      29            1 :     // Ingest 10 MB of updates to a single key.
      30         1000 :     for _ in 1..1000 {
      31          999 :         executor.ingest_uniform(100, 10, &(0..100_000)).unwrap();
      32          999 :         executor.ingest_uniform(1000, 10, &(0..1)).unwrap();
      33          999 :         executor.compact().await.unwrap();
      34            1 :     }
      35            1 : 
      36            1 :     // Check that all the layers are smaller than the target size (with some slop)
      37           12 :     for l in executor.live_layers.iter() {
      38           12 :         println!("layer {}: {}", l.short_id(), l.file_size());
      39           12 :     }
      40           12 :     for l in executor.live_layers.iter() {
      41           12 :         assert!(l.file_size() < executor.target_file_size * 2);
      42            1 :         // Sanity check that none of the delta layers are empty either.
      43           12 :         if l.is_delta() {
      44           12 :             assert!(l.file_size() > 0);
      45            1 :         }
      46            1 :     }
      47            1 : }
      48              : 
      49              : #[tokio::test]
      50            1 : async fn test_simple_updates() {
      51            1 :     setup_logging();
      52            1 :     let mut executor = MockTimeline::new();
      53            1 :     executor.target_file_size = 500_000; // 500 KB
      54            1 : 
      55            1 :     // Ingest some traffic.
      56          400 :     for _ in 1..400 {
      57          399 :         executor.ingest_uniform(100, 500, &(0..100_000)).unwrap();
      58          399 :     }
      59            1 : 
      60           39 :     for l in executor.live_layers.iter() {
      61           39 :         println!("layer {}: {}", l.short_id(), l.file_size());
      62           39 :     }
      63            1 : 
      64            1 :     println!("Running compaction...");
      65            1 :     executor.compact().await.unwrap();
      66            1 : 
      67           39 :     for l in executor.live_layers.iter() {
      68           39 :         println!("layer {}: {}", l.short_id(), l.file_size());
      69           39 :     }
      70            1 : }
        

Generated by: LCOV version 2.1-beta