From d15116f2cc4b26ad36f9cf28c5cf9f9343269cc3 Mon Sep 17 00:00:00 2001 From: Arthur Petukhovsky Date: Fri, 23 Sep 2022 14:36:08 +0000 Subject: [PATCH] Update pg_version for old timelines --- safekeeper/src/control_file_upgrade.rs | 12 ++++++++++++ safekeeper/src/safekeeper.rs | 3 +-- safekeeper/src/timeline.rs | 2 ++ safekeeper/src/wal_storage.rs | 16 +++++----------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/safekeeper/src/control_file_upgrade.rs b/safekeeper/src/control_file_upgrade.rs index d8434efb20..1ce9186085 100644 --- a/safekeeper/src/control_file_upgrade.rs +++ b/safekeeper/src/control_file_upgrade.rs @@ -248,6 +248,18 @@ pub fn upgrade_control_file(buf: &[u8], version: u32) -> Result oldstate.timeline_start_lsn = Lsn(1); oldstate.local_start_lsn = Lsn(1); + return Ok(oldstate); + } else if version == 6 { + info!("reading safekeeper control file version {}", version); + let mut oldstate = SafeKeeperState::des(&buf[..buf.len()])?; + if oldstate.server.pg_version != 0 { + return Ok(oldstate); + } + + // set pg_version to the default v14 + info!("setting pg_version to 140005"); + oldstate.server.pg_version = 140005; + return Ok(oldstate); } bail!("unsupported safekeeper control file version {}", version) diff --git a/safekeeper/src/safekeeper.rs b/safekeeper/src/safekeeper.rs index eec24faf2f..7869aa8b3a 100644 --- a/safekeeper/src/safekeeper.rs +++ b/safekeeper/src/safekeeper.rs @@ -25,7 +25,7 @@ use utils::{ }; pub const SK_MAGIC: u32 = 0xcafeceefu32; -pub const SK_FORMAT_VERSION: u32 = 6; +pub const SK_FORMAT_VERSION: u32 = 7; const SK_PROTOCOL_VERSION: u32 = 2; pub const UNKNOWN_SERVER_VERSION: u32 = 0; @@ -639,7 +639,6 @@ where let mut state = self.state.clone(); state.server.system_id = msg.system_id; - state.server.wal_seg_size = msg.wal_seg_size; if msg.pg_version != UNKNOWN_SERVER_VERSION { state.server.pg_version = msg.pg_version; } diff --git a/safekeeper/src/timeline.rs b/safekeeper/src/timeline.rs index c16fc9f40c..dc7503af65 100644 --- a/safekeeper/src/timeline.rs +++ b/safekeeper/src/timeline.rs @@ -314,6 +314,8 @@ impl Timeline { ttid: TenantTimelineId, wal_backup_launcher_tx: Sender, ) -> Result { + let _enter = info_span!("load_timeline", timeline = %ttid.timeline_id).entered(); + let shared_state = SharedState::restore(&conf, &ttid)?; let (commit_lsn_watch_tx, commit_lsn_watch_rx) = watch::channel(shared_state.sk.state.commit_lsn); diff --git a/safekeeper/src/wal_storage.rs b/safekeeper/src/wal_storage.rs index eee7c703f9..8fbd479d95 100644 --- a/safekeeper/src/wal_storage.rs +++ b/safekeeper/src/wal_storage.rs @@ -111,6 +111,10 @@ impl PhysicalStorage { // Find out where stored WAL ends, starting at commit_lsn which is a // known recent record boundary (unless we don't have WAL at all). + // + // NB: find_end_of_wal MUST be backwards compatible with the previously + // written WAL. If find_end_of_wal fails to read any WAL written by an + // older version of the code, we could lose data forever. let write_lsn = if state.commit_lsn == Lsn(0) { Lsn(0) } else { @@ -125,17 +129,7 @@ impl PhysicalStorage { wal_seg_size, state.commit_lsn, )?, - pg_majorversion => { - // This is a quik hack to work with old timelines that don't have - // pg_version in the control file. We can remove it after this is fixed properly. - const DEFAULT_PG_MAJOR_VERSION: u32 = 14; - warn!("unknown postgres version {pg_majorversion} assume {DEFAULT_PG_MAJOR_VERSION}"); - postgres_ffi::v14::xlog_utils::find_end_of_wal( - &timeline_dir, - wal_seg_size, - state.commit_lsn, - )? - } + _ => bail!("unsupported postgres version: {}", state.server.pg_version), } };