Fixes to checkpoint.nextXid accounting:

- Advance next_xid only when incoming xlog record has one.
- Advance next_xid by one. Remove XID_CHECKPOINT_INTERVAL.
This commit is contained in:
anastasia
2021-08-10 09:37:19 +03:00
parent d64c083dad
commit 01e2e88135
2 changed files with 7 additions and 5 deletions

View File

@@ -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.

View File

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