From a5b898a31c0d4d497e67b7e5c0d738e688434fc9 Mon Sep 17 00:00:00 2001 From: Alexander Stanovoy <38102252+alexstanovoy@users.noreply.github.com> Date: Tue, 22 Nov 2022 02:28:41 +0200 Subject: [PATCH] Fix the order of checks in LSN (#2882) We should check if LSN is in the lower range because it's constant and only after wait for LSN to arrive if needed. --- pageserver/src/tenant.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pageserver/src/tenant.rs b/pageserver/src/tenant.rs index c5fcfda756..4405e0b236 100644 --- a/pageserver/src/tenant.rs +++ b/pageserver/src/tenant.rs @@ -461,14 +461,7 @@ impl Tenant { .context("Cannot branch off the timeline that's not present in pageserver")?; if let Some(lsn) = ancestor_start_lsn.as_mut() { - // Wait for the WAL to arrive and be processed on the parent branch up - // to the requested branch point. The repository code itself doesn't - // require it, but if we start to receive WAL on the new timeline, - // decoding the new WAL might need to look up previous pages, relation - // sizes etc. and that would get confused if the previous page versions - // are not in the repository yet. *lsn = lsn.align(); - ancestor_timeline.wait_lsn(*lsn).await?; let ancestor_ancestor_lsn = ancestor_timeline.get_ancestor_lsn(); if ancestor_ancestor_lsn > *lsn { @@ -480,6 +473,14 @@ impl Tenant { ancestor_ancestor_lsn, ); } + + // Wait for the WAL to arrive and be processed on the parent branch up + // to the requested branch point. The repository code itself doesn't + // require it, but if we start to receive WAL on the new timeline, + // decoding the new WAL might need to look up previous pages, relation + // sizes etc. and that would get confused if the previous page versions + // are not in the repository yet. + ancestor_timeline.wait_lsn(*lsn).await?; } self.branch_timeline(ancestor_timeline_id, new_timeline_id, ancestor_start_lsn)?