Update pg_version for old timelines

This commit is contained in:
Arthur Petukhovsky
2022-09-23 14:36:08 +00:00
committed by Stas Kelvich
parent df45c0d0e5
commit d15116f2cc
4 changed files with 20 additions and 13 deletions

View File

@@ -248,6 +248,18 @@ pub fn upgrade_control_file(buf: &[u8], version: u32) -> Result<SafeKeeperState>
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)

View File

@@ -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;
}

View File

@@ -314,6 +314,8 @@ impl Timeline {
ttid: TenantTimelineId,
wal_backup_launcher_tx: Sender<TenantTimelineId>,
) -> Result<Timeline> {
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);

View File

@@ -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),
}
};