LCOV - code coverage report
Current view: top level - pageserver/compaction/tests - tests.rs (source / functions) Coverage Total Hit
Test: fabb29a6339542ee130cd1d32b534fafdc0be240.info Lines: 100.0 % 55 55
Test Date: 2024-06-25 13:20:00 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            4 : pub(crate) fn setup_logging() {
       9            4 :     LOG_HANDLE.get_or_init(|| {
      10            4 :         logging::init(
      11            4 :             logging::LogFormat::Test,
      12            4 :             logging::TracingErrorLayerEnablement::EnableWithRustLogFilter,
      13            4 :             logging::Output::Stdout,
      14            4 :         )
      15            4 :         .expect("Failed to init test logging")
      16            4 :     });
      17            4 : }
      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            2 : async fn test_many_updates_for_single_key() {
      25            2 :     setup_logging();
      26            2 :     let mut executor = MockTimeline::new();
      27            2 :     executor.target_file_size = 1_000_000; // 1 MB
      28            2 : 
      29            2 :     // Ingest 10 MB of updates to a single key.
      30         2000 :     for _ in 1..1000 {
      31         1998 :         executor.ingest_uniform(100, 10, &(0..100_000)).unwrap();
      32         1998 :         executor.ingest_uniform(1000, 10, &(0..1)).unwrap();
      33         1998 :         executor.compact().await.unwrap();
      34            2 :     }
      35            2 : 
      36            2 :     // Check that all the layers are smaller than the target size (with some slop)
      37           24 :     for l in executor.live_layers.iter() {
      38           24 :         println!("layer {}: {}", l.short_id(), l.file_size());
      39           24 :     }
      40           24 :     for l in executor.live_layers.iter() {
      41           24 :         assert!(l.file_size() < executor.target_file_size * 2);
      42            2 :         // Sanity check that none of the delta layers are empty either.
      43           24 :         if l.is_delta() {
      44           24 :             assert!(l.file_size() > 0);
      45            2 :         }
      46            2 :     }
      47            2 : }
      48              : 
      49              : #[tokio::test]
      50            2 : async fn test_simple_updates() {
      51            2 :     setup_logging();
      52            2 :     let mut executor = MockTimeline::new();
      53            2 :     executor.target_file_size = 500_000; // 500 KB
      54            2 : 
      55            2 :     // Ingest some traffic.
      56          800 :     for _ in 1..400 {
      57          798 :         executor.ingest_uniform(100, 500, &(0..100_000)).unwrap();
      58          798 :     }
      59            2 : 
      60           78 :     for l in executor.live_layers.iter() {
      61           78 :         println!("layer {}: {}", l.short_id(), l.file_size());
      62           78 :     }
      63            2 : 
      64            2 :     println!("Running compaction...");
      65            2 :     executor.compact().await.unwrap();
      66            2 : 
      67           78 :     for l in executor.live_layers.iter() {
      68           78 :         println!("layer {}: {}", l.short_id(), l.file_size());
      69           78 :     }
      70            2 : }
        

Generated by: LCOV version 2.1-beta