From 397b60feabd132cfe4401e8b4f2c1cf11c25a71c Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 6 Dec 2022 10:27:26 -0500 Subject: [PATCH] common abstraction for waiting for SK commit_lsn to reach PS --- test_runner/fixtures/neon_fixtures.py | 31 +++++++++++++++++++ .../test_tenants_with_remote_storage.py | 14 +++------ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/test_runner/fixtures/neon_fixtures.py b/test_runner/fixtures/neon_fixtures.py index 818853a4ac..3a3ee94425 100644 --- a/test_runner/fixtures/neon_fixtures.py +++ b/test_runner/fixtures/neon_fixtures.py @@ -3084,3 +3084,34 @@ def fork_at_current_lsn( """ current_lsn = pg.safe_psql("SELECT pg_current_wal_lsn()")[0][0] return env.neon_cli.create_branch(new_branch_name, ancestor_branch_name, tenant_id, current_lsn) + + +def wait_for_sk_commit_lsn_to_arrive_at_pageserver_last_record_lsn( + tenant_id: TenantId, + timeline_id: TimelineId, + safekeepers: List[Safekeeper], + pageserver: NeonPageserver, +): + sk_commit_lsns = [ + sk.http_client().timeline_status(tenant_id, timeline_id).commit_lsn for sk in safekeepers + ] + lsn = max(sk_commit_lsns) + ps_http = pageserver.http_client() + wait_for_last_record_lsn(ps_http, tenant_id, timeline_id, lsn) + return lsn + + +def wait_for_sk_commit_lsn_to_reach_remote_storage( + tenant_id: TenantId, + timeline_id: TimelineId, + safekeepers: List[Safekeeper], + pageserver: NeonPageserver, +): + lsn = wait_for_sk_commit_lsn_to_arrive_at_pageserver_last_record_lsn( + tenant_id, timeline_id, safekeepers, pageserver + ) + ps_http = pageserver.http_client() + # force a checkpoint to trigger upload + ps_http.timeline_checkpoint(tenant_id, timeline_id) + wait_for_upload(ps_http, tenant_id, timeline_id, lsn) + return lsn diff --git a/test_runner/regress/test_tenants_with_remote_storage.py b/test_runner/regress/test_tenants_with_remote_storage.py index afc413f3e3..57aaa70559 100644 --- a/test_runner/regress/test_tenants_with_remote_storage.py +++ b/test_runner/regress/test_tenants_with_remote_storage.py @@ -24,6 +24,7 @@ from fixtures.neon_fixtures import ( assert_no_in_progress_downloads_for_tenant, available_remote_storages, wait_for_last_record_lsn, + wait_for_sk_commit_lsn_to_reach_remote_storage, wait_for_upload, ) from fixtures.types import Lsn, TenantId, TimelineId @@ -161,16 +162,9 @@ def test_tenants_attached_after_download( ##### Stop the pageserver, erase its layer file to force it being downloaded from S3 env.postgres.stop_all() - sk_commit_lsns = [ - sk.http_client().timeline_status(tenant_id, timeline_id).commit_lsn - for sk in env.safekeepers - ] - log.info("wait for pageserver to process all the WAL") - wait_for_last_record_lsn(client, tenant_id, timeline_id, max(sk_commit_lsns)) - log.info("wait for it to reach remote storage") - pageserver_http.timeline_checkpoint(tenant_id, timeline_id) - wait_for_upload(client, tenant_id, timeline_id, max(sk_commit_lsns)) - log.info("latest safekeeper_commit_lsn reached remote storage") + wait_for_sk_commit_lsn_to_reach_remote_storage( + tenant_id, timeline_id, env.safekeepers, env.pageserver + ) detail_before = client.timeline_detail( tenant_id, timeline_id, include_non_incremental_physical_size=True