Skip to content

Commit

Permalink
Use redo field to distinguish shutdown andonine checkpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Knizhnik committed Dec 4, 2024
1 parent 4dbb469 commit 13dd2f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 3 additions & 10 deletions pageserver/src/basebackup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
Expand Down
14 changes: 12 additions & 2 deletions pageserver/src/walingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 13dd2f1

Please sign in to comment.