Skip to content

Commit 0fcef01

Browse files
arssherololobus
authored andcommitted
Fix basebackup LSN comparison in walproposer.
as basebackup LSN always skips over page header
1 parent 038b2b9 commit 0fcef01

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/backend/replication/walproposer.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,21 @@ GetEpoch(Safekeeper *sk)
11591159
return GetHighestTerm(&sk->voteResponse.termHistory);
11601160
}
11611161

1162+
/* If LSN points to the page header, skip it */
1163+
static XLogRecPtr
1164+
SkipXLogPageHeader(XLogRecPtr lsn)
1165+
{
1166+
if (XLogSegmentOffset(lsn, wal_segment_size) == 0)
1167+
{
1168+
lsn += SizeOfXLogLongPHD;
1169+
}
1170+
else if (lsn % XLOG_BLCKSZ == 0)
1171+
{
1172+
lsn += SizeOfXLogShortPHD;
1173+
}
1174+
return lsn;
1175+
}
1176+
11621177
/*
11631178
* Called after majority of acceptors gave votes, it calculates the most
11641179
* advanced safekeeper (who will be the donor) and epochStartLsn -- LSN since
@@ -1260,7 +1275,13 @@ DetermineEpochStartLsn(void)
12601275
*/
12611276
if (!syncSafekeepers)
12621277
{
1263-
if (propEpochStartLsn != GetRedoStartLsn())
1278+
/*
1279+
* Basebackup LSN always points to the beginning of the record (not the
1280+
* page), as StartupXLOG most probably wants it this way. Safekeepers
1281+
* don't skip header as they need continious stream of data, so
1282+
* correct LSN for comparison.
1283+
*/
1284+
if (SkipXLogPageHeader(propEpochStartLsn) != GetRedoStartLsn())
12641285
{
12651286
/*
12661287
* However, allow to proceed if previously elected leader was me; plain

0 commit comments

Comments
 (0)