Skip to content

Commit

Permalink
pageserver: guard against WAL gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLazar committed Feb 17, 2025
1 parent 0ab2f3a commit 8497de9
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pub(super) async fn handle_walreceiver_connection(
} => Some((format, compression)),
};

let mut expected_wal_start = startpoint;
while let Some(replication_message) = {
select! {
_ = cancellation.cancelled() => {
Expand Down Expand Up @@ -340,6 +341,21 @@ pub(super) async fn handle_walreceiver_connection(
)
})?;

// Guard against WAL gaps. If the start LSN of the PG WAL section
// from which the interpreted records were extracted, doesn't match
// the end of the previous batch (or the starting point for the first batch),
// then kill this WAL receiver connection and start a new one.
if let Some(raw_wal_start_lsn) = batch.raw_wal_start_lsn {
if raw_wal_start_lsn != expected_wal_start {
let msg = format!(
"Received batch from raw WAL start LSN {}. Expected {}",
raw_wal_start_lsn, expected_wal_start,
);
critical!("{msg}");
return Err(WalReceiverError::Other(anyhow!(msg)));
}
}

let InterpretedWalRecords {
records,
next_record_lsn,
Expand Down Expand Up @@ -447,6 +463,7 @@ pub(super) async fn handle_walreceiver_connection(
);

last_rec_lsn = next_record_lsn;
expected_wal_start = streaming_lsn;

Some(streaming_lsn)
}
Expand Down

0 comments on commit 8497de9

Please sign in to comment.