diff --git a/pageserver/src/layered_repository.rs b/pageserver/src/layered_repository.rs index 080ac2852d..59e73d961d 100644 --- a/pageserver/src/layered_repository.rs +++ b/pageserver/src/layered_repository.rs @@ -1432,7 +1432,8 @@ impl LayeredTimeline { let layers = timeline.layers.read().unwrap(); - // Check the open and frozen in-memory layers first + // Check the open and frozen in-memory layers first, in order from newest + // to oldest. if let Some(open_layer) = &layers.open_layer { let start_lsn = open_layer.get_lsn_range().start; if cont_lsn > start_lsn { @@ -1450,7 +1451,7 @@ impl LayeredTimeline { continue; } } - for frozen_layer in layers.frozen_layers.iter() { + for frozen_layer in layers.frozen_layers.iter().rev() { let start_lsn = frozen_layer.get_lsn_range().start; if cont_lsn > start_lsn { //info!("CHECKING for {} at {} on frozen layer {}", key, cont_lsn, frozen_layer.filename().display()); @@ -1695,7 +1696,9 @@ impl LayeredTimeline { self.conf.timeline_path(&self.timelineid, &self.tenantid), ])?; - // Finally, replace the frozen in-memory layer with the new on-disk layers + fail_point!("flush-frozen"); + + // Finally, replace the frozen in-memory layer with the new on-disk layer { let mut layers = self.layers.write().unwrap(); let l = layers.frozen_layers.pop_front(); diff --git a/pageserver/src/layered_repository/layer_map.rs b/pageserver/src/layered_repository/layer_map.rs index 03ee8b8ef1..91a900dde0 100644 --- a/pageserver/src/layered_repository/layer_map.rs +++ b/pageserver/src/layered_repository/layer_map.rs @@ -43,10 +43,13 @@ pub struct LayerMap { pub next_open_layer_at: Option, /// - /// The frozen layer, if any, contains WAL older than the current 'open_layer' - /// or 'next_open_layer_at', but newer than any historic layer. The frozen - /// layer is during checkpointing, when an InMemoryLayer is being written out - /// to disk. + /// Frozen layers, if any. Frozen layers are in-memory layers that + /// are no longer added to, but haven't been written out to disk + /// yet. They contain WAL older than the current 'open_layer' or + /// 'next_open_layer_at', but newer than any historic layer. + /// The frozen layers are in order from oldest to newest, so that + /// the newest one is in the 'back' of the VecDeque, and the oldest + /// in the 'front'. /// pub frozen_layers: VecDeque>, diff --git a/test_runner/batch_others/test_ancestor_branch.py b/test_runner/batch_others/test_ancestor_branch.py index aeb45348ad..75fe3cde0f 100644 --- a/test_runner/batch_others/test_ancestor_branch.py +++ b/test_runner/batch_others/test_ancestor_branch.py @@ -33,6 +33,10 @@ def test_ancestor_branch(zenith_env_builder: ZenithEnvBuilder): 'compaction_target_size': '4194304', }) + with closing(env.pageserver.connect()) as psconn: + with psconn.cursor(cursor_factory=psycopg2.extras.DictCursor) as pscur: + pscur.execute("failpoints flush-frozen=sleep(10000)") + env.zenith_cli.create_timeline(f'main', tenant_id=tenant) pg_branch0 = env.postgres.create_start('main', tenant_id=tenant) branch0_cur = pg_branch0.connect().cursor()