mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-18 21:50:37 +00:00
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:
@@ -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)]
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user