From 5f4e32f50528436daef5182e2b959a6f813af9d5 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 11 May 2021 11:12:14 +0300 Subject: [PATCH] Require valid WAL streaming point. If timeline doesn't have a valid "last valid LSN", refuse WAL streaming. The previous behavior was to start streaming from the very beginning of time. That was needed to support bootstrapping the page server with no data at all (see commit bd606ab37a), but we no longer do that. --- pageserver/src/walreceiver.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/pageserver/src/walreceiver.rs b/pageserver/src/walreceiver.rs index 046c42534c..1d7cb1b455 100644 --- a/pageserver/src/walreceiver.rs +++ b/pageserver/src/walreceiver.rs @@ -142,25 +142,18 @@ fn walreceiver_main( // use 'last_record_lsn' rather than 'last_valid_lsn' here. let last_rec_lsn = timeline.get_last_record_lsn(); let mut startpoint = last_rec_lsn; + if startpoint == Lsn(0) { - // If we start here with identify.xlogpos we will have race condition with - // postgres start: insert into postgres may request page that was modified with lsn - // smaller than identify.xlogpos. - // - // Current procedure for starting postgres will anyway be changed to something - // different like having 'initdb' method on a pageserver (or importing some shared - // empty database snapshot), so for now I just put start of first segment which - // seems to be a valid record. - timeline.init_valid_lsn(Lsn(0x0100_0000)); - startpoint = Lsn(0x0100_0000); - } else { - // There might be some padding after the last full record, skip it. - // - // FIXME: It probably would be better to always start streaming from the beginning - // of the page, or the segment, so that we could check the page/segment headers - // too. Just for the sake of paranoia. - startpoint += startpoint.calc_padding(8u32); + error!("No previous WAL position"); } + + // There might be some padding after the last full record, skip it. + // + // FIXME: It probably would be better to always start streaming from the beginning + // of the page, or the segment, so that we could check the page/segment headers + // too. Just for the sake of paranoia. + startpoint += startpoint.calc_padding(8u32); + debug!( "last_record_lsn {} starting replication from {} for timeline {}, server is at {}...", last_rec_lsn, startpoint, timelineid, end_of_wal