From 01e2e88135dddd1141afd56246fe8bff60582749 Mon Sep 17 00:00:00 2001 From: anastasia Date: Tue, 10 Aug 2021 09:37:19 +0300 Subject: [PATCH] Fixes to checkpoint.nextXid accounting: - Advance next_xid only when incoming xlog record has one. - Advance next_xid by one. Remove XID_CHECKPOINT_INTERVAL. --- pageserver/src/restore_local_repo.rs | 4 +++- postgres_ffi/src/xlog_utils.rs | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pageserver/src/restore_local_repo.rs b/pageserver/src/restore_local_repo.rs index 141eab10a6..d817ba23f2 100644 --- a/pageserver/src/restore_local_repo.rs +++ b/pageserver/src/restore_local_repo.rs @@ -351,7 +351,9 @@ pub fn save_decoded_record( recdata: Bytes, lsn: Lsn, ) -> Result<()> { - checkpoint.update_next_xid(decoded.xl_xid); + if decoded.xl_xid > 0 { + checkpoint.update_next_xid(decoded.xl_xid); + } // Iterate through all the blocks that the record modifies, and // "put" a separate copy of the record for each block. diff --git a/postgres_ffi/src/xlog_utils.rs b/postgres_ffi/src/xlog_utils.rs index 38a9b1612e..1dd95f9f70 100644 --- a/postgres_ffi/src/xlog_utils.rs +++ b/postgres_ffi/src/xlog_utils.rs @@ -44,8 +44,6 @@ pub type TimeLineID = u32; pub type TimestampTz = i64; pub type XLogSegNo = u64; -const XID_CHECKPOINT_INTERVAL: u32 = 1024; - #[allow(non_snake_case)] pub fn XLogSegmentsPerXLogId(wal_segsz_bytes: usize) -> XLogSegNo { (0x100000000u64 / wal_segsz_bytes as u64) as XLogSegNo @@ -330,9 +328,11 @@ impl CheckPoint { // Next XID should be greater than new_xid. // Also take in account 32-bit wrap-around. pub fn update_next_xid(&mut self, xid: u32) { - let xid = xid.wrapping_add(XID_CHECKPOINT_INTERVAL - 1) & !(XID_CHECKPOINT_INTERVAL - 1); let full_xid = self.nextXid.value; - let new_xid = std::cmp::max(xid + 1, pg_constants::FIRST_NORMAL_TRANSACTION_ID); + let new_xid = std::cmp::max( + xid.wrapping_add(1), + pg_constants::FIRST_NORMAL_TRANSACTION_ID, + ); let old_xid = full_xid as u32; if new_xid.wrapping_sub(old_xid) as i32 > 0 { let mut epoch = full_xid >> 32;