Don't restart WAL streaming in the middle of a record.

I think this was changed inadvertently by commit 2c308da4d2. Change it
back.

Fixes https://github.com/zenithdb/zenith/issues/98
This commit is contained in:
Heikki Linnakangas
2021-05-06 11:33:10 +03:00
parent bf0a0cb55d
commit 29f122009a
3 changed files with 15 additions and 6 deletions

View File

@@ -47,10 +47,12 @@ pub trait Timeline {
src_tablespace_id: Oid,
) -> Result<()>;
fn advance_last_record_lsn(&self, lsn: Lsn);
fn advance_last_valid_lsn(&self, lsn: Lsn);
fn init_valid_lsn(&self, lsn: Lsn);
fn get_last_valid_lsn(&self) -> Lsn;
fn init_valid_lsn(&self, lsn: Lsn);
fn advance_last_record_lsn(&self, lsn: Lsn);
fn get_last_record_lsn(&self) -> Lsn;
}
#[derive(Clone)]

View File

@@ -828,6 +828,10 @@ impl Timeline for RocksTimeline {
}
}
fn get_last_record_lsn(&self) -> Lsn {
self.last_record_lsn.load()
}
fn init_valid_lsn(&self, lsn: Lsn) {
let old = self.last_valid_lsn.advance(lsn);
assert!(old == Lsn(0));

View File

@@ -158,8 +158,11 @@ fn walreceiver_main(
//
// Start streaming the WAL, from where we left off previously.
//
let mut startpoint = timeline.get_last_valid_lsn();
let last_valid_lsn = timeline.get_last_valid_lsn();
// If we had previously received WAL up to some point in the middle of a WAL record, we
// better start from the end of last full WAL record, not in the middle of one. Hence,
// 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
@@ -180,8 +183,8 @@ fn walreceiver_main(
startpoint += startpoint.calc_padding(8u32);
}
debug!(
"last_valid_lsn {} starting replication from {} for timeline {}, server is at {}...",
last_valid_lsn, startpoint, timelineid, end_of_wal
"last_record_lsn {} starting replication from {} for timeline {}, server is at {}...",
last_rec_lsn, startpoint, timelineid, end_of_wal
);
let query = format!("START_REPLICATION PHYSICAL {}", startpoint);