From d5a96d3d50fbc1480d29a3acbd6fe5f33da47153 Mon Sep 17 00:00:00 2001 From: Arseny Sher Date: Mon, 14 Mar 2022 17:55:30 +0300 Subject: [PATCH] Fix finding end of WAL on safekeepers after f86cf93435133ee11. That commit dropped wal_start_lsn, now we're looking since commit_lsn, which is the real end of WAL if no records follow it. ref #1351 --- postgres_ffi/src/xlog_utils.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/postgres_ffi/src/xlog_utils.rs b/postgres_ffi/src/xlog_utils.rs index caf1940a9c..d2b2b5c122 100644 --- a/postgres_ffi/src/xlog_utils.rs +++ b/postgres_ffi/src/xlog_utils.rs @@ -132,6 +132,8 @@ pub fn get_current_timestamp() -> TimestampTz { } } +/// Return offset of the last valid record in the segment segno, starting +/// looking at start_offset. Returns start_offset if no records found. fn find_end_of_wal_segment( data_dir: &Path, segno: XLogSegNo, @@ -147,7 +149,7 @@ fn find_end_of_wal_segment( let mut rec_offs: usize = 0; let mut buf = [0u8; XLOG_BLCKSZ]; let file_name = XLogFileName(tli, segno, wal_seg_size); - let mut last_valid_rec_pos: usize = 0; + let mut last_valid_rec_pos: usize = start_offset; // assume at given start_offset begins new record let mut file = File::open(data_dir.join(file_name.clone() + ".partial")).unwrap(); file.seek(SeekFrom::Start(offs as u64))?; let mut rec_hdr = [0u8; XLOG_RECORD_CRC_OFFS];