Use redo field to distinguish shutdown andonine checkpoints

This commit is contained in:
Konstantin Knizhnik
2024-12-04 15:33:42 +02:00
parent 4dbb469539
commit 13dd2f11c6
2 changed files with 15 additions and 12 deletions

View File

@@ -29,9 +29,7 @@ use crate::tenant::Timeline;
use pageserver_api::reltag::{RelTag, SlruKind};
use postgres_ffi::pg_constants::{DEFAULTTABLESPACE_OID, GLOBALTABLESPACE_OID};
use postgres_ffi::pg_constants::{
PGDATA_SPECIAL_FILES, PG_HBA, SIZE_OF_XLOG_RECORD_DATA_HEADER_SHORT,
};
use postgres_ffi::pg_constants::{PGDATA_SPECIAL_FILES, PG_HBA};
use postgres_ffi::relfile_utils::{INIT_FORKNUM, MAIN_FORKNUM};
use postgres_ffi::XLogFileName;
use postgres_ffi::PG_TLI;
@@ -264,13 +262,8 @@ where
if let Ok(checkpoint_bytes) = self.timeline.get_checkpoint(self.lsn, self.ctx).await {
let checkpoint =
CheckPoint::decode(&checkpoint_bytes).context("deserialize checkpoint")?;
let checkpoint_end_lsn = calculate_walrecord_end_lsn(
Lsn(checkpoint.redo),
XLOG_SIZE_OF_XLOG_RECORD
+ SIZE_OF_XLOG_RECORD_DATA_HEADER_SHORT
+ SIZEOF_CHECKPOINT,
);
checkpoint_end_lsn == self.lsn
// We store "redo" field only for shutdown checkpoint
checkpoint.redo != 0
} else {
false
};

View File

@@ -1187,8 +1187,18 @@ impl WalIngest {
} else {
cp.oldestActiveXid = xlog_checkpoint.oldestActiveXid;
}
cp.redo = xlog_checkpoint.redo;
//
// There is no any field in CheckPoint which allows to distinguish online
// and shutdown checkpoint. And we need to know it to detect normal shutdown.
// Previously "redo" field was not set at all.
// So let's assign this field only for shutdown checkpoint and left it zero
// for online checkpoint.
//
cp.redo = if info == pg_constants::XLOG_CHECKPOINT_SHUTDOWN {
xlog_checkpoint.redo
} else {
0
};
// Write a new checkpoint key-value pair on every checkpoint record, even
// if nothing really changed. Not strictly required, but it seems nice to
// have some trace of the checkpoint records in the layer files at the same