From 1389d6b6a51f4c3341a0933de0e62e4c5a8e56ec Mon Sep 17 00:00:00 2001 From: Bojan Serafimov Date: Thu, 30 Jun 2022 19:00:45 -0400 Subject: [PATCH] Fix gc after import --- pageserver/src/layered_repository.rs | 3 +++ pageserver/src/page_service.rs | 3 ++- pageserver/src/pgdatadir_mapping.rs | 3 ++- test_runner/batch_others/test_import.py | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pageserver/src/layered_repository.rs b/pageserver/src/layered_repository.rs index f001ca0964..13f200ec92 100644 --- a/pageserver/src/layered_repository.rs +++ b/pageserver/src/layered_repository.rs @@ -2190,6 +2190,9 @@ impl LayeredTimeline { LsnForTimestamp::Past(lsn) => { debug!("past({})", lsn); } + LsnForTimestamp::NoData(lsn) => { + debug!("nodata({})", lsn); + } } debug!("pitr_cutoff_lsn = {:?}", pitr_cutoff_lsn) } diff --git a/pageserver/src/page_service.rs b/pageserver/src/page_service.rs index 0a9f8d1057..8eabcba820 100644 --- a/pageserver/src/page_service.rs +++ b/pageserver/src/page_service.rs @@ -530,7 +530,7 @@ impl PageServerHandler { // Create empty timeline info!("creating new timeline"); let repo = tenant_mgr::get_repository_for_tenant(tenant_id)?; - let timeline = repo.create_empty_timeline(timeline_id, Lsn(0))?; + let timeline = repo.create_empty_timeline(timeline_id, base_lsn)?; let repartition_distance = repo.get_checkpoint_distance(); let mut datadir_timeline = DatadirTimeline::::new(timeline, repartition_distance); @@ -1127,6 +1127,7 @@ impl postgres_backend::Handler for PageServerHandler { LsnForTimestamp::Present(lsn) => format!("{}", lsn), LsnForTimestamp::Future(_lsn) => "future".into(), LsnForTimestamp::Past(_lsn) => "past".into(), + LsnForTimestamp::NoData(_lsn) => "nodata".into(), }; pgb.write_message_noflush(&BeMessage::DataRow(&[Some(result.as_bytes())]))?; pgb.write_message(&BeMessage::CommandComplete(b"SELECT 1"))?; diff --git a/pageserver/src/pgdatadir_mapping.rs b/pageserver/src/pgdatadir_mapping.rs index 6ff5949c7e..c47d7cb1ad 100644 --- a/pageserver/src/pgdatadir_mapping.rs +++ b/pageserver/src/pgdatadir_mapping.rs @@ -51,6 +51,7 @@ pub enum LsnForTimestamp { Present(Lsn), Future(Lsn), Past(Lsn), + NoData(Lsn), } impl DatadirTimeline { @@ -250,7 +251,7 @@ impl DatadirTimeline { (false, false) => { // This can happen if no commit records have been processed yet, e.g. // just after importing a cluster. - bail!("no commit timestamps found"); + Ok(LsnForTimestamp::NoData(max_lsn)) } (true, false) => { // Didn't find any commit timestamps larger than the request diff --git a/test_runner/batch_others/test_import.py b/test_runner/batch_others/test_import.py index e478103313..63dc42ee3e 100644 --- a/test_runner/batch_others/test_import.py +++ b/test_runner/batch_others/test_import.py @@ -191,3 +191,8 @@ def test_import_from_pageserver(test_output_dir, pg_bin, vanilla_pg, neon_env_bu # Check it's the same as the first fullbackup # TODO pageserver should be checking checksum assert os.path.getsize(tar_output_file) == os.path.getsize(new_tar_output_file) + + # Check that gc works + psconn = env.pageserver.connect() + pscur = psconn.cursor() + pscur.execute(f"do_gc {tenant.hex} {timeline} 0")