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 : ///
24 : /// TODO: The code to avoid this problem has not been implemented yet! So the
25 : /// assertion currently fails, but we need to make it not fail.
26 : #[ignore]
27 : #[tokio::test]
28 0 : async fn test_many_updates_for_single_key() {
29 0 : setup_logging();
30 0 : let mut executor = MockTimeline::new();
31 0 : executor.target_file_size = 1_000_000; // 1 MB
32 0 :
33 0 : // Ingest 10 MB of updates to a single key.
34 0 : for _ in 1..1000 {
35 0 : executor.ingest_uniform(100, 10, &(0..100_000)).unwrap();
36 0 : executor.ingest_uniform(1000, 10, &(0..1)).unwrap();
37 0 : executor.compact().await.unwrap();
38 0 : }
39 0 :
40 0 : // Check that all the layers are smaller than the target size (with some slop)
41 0 : for l in executor.live_layers.iter() {
42 0 : println!("layer {}: {}", l.short_id(), l.file_size());
43 0 : }
44 0 : for l in executor.live_layers.iter() {
45 0 : assert!(l.file_size() < executor.target_file_size * 2);
46 0 : // sanity check that none of the delta layers are stupidly small either
47 0 : if l.is_delta() {
48 0 : assert!(l.file_size() > executor.target_file_size / 2);
49 0 : }
50 0 : }
51 0 : }
52 :
53 : #[tokio::test]
54 2 : async fn test_simple_updates() {
55 2 : setup_logging();
56 2 : let mut executor = MockTimeline::new();
57 2 : executor.target_file_size = 500_000; // 500 KB
58 2 :
59 2 : // Ingest some traffic.
60 800 : for _ in 1..400 {
61 798 : executor.ingest_uniform(100, 500, &(0..100_000)).unwrap();
62 798 : }
63 2 :
64 78 : for l in executor.live_layers.iter() {
65 78 : println!("layer {}: {}", l.short_id(), l.file_size());
66 78 : }
67 2 :
68 2 : println!("Running compaction...");
69 2 : executor.compact().await.unwrap();
70 2 :
71 78 : for l in executor.live_layers.iter() {
72 78 : println!("layer {}: {}", l.short_id(), l.file_size());
73 78 : }
74 2 : }
|