Skip to content

Commit a1af529

Browse files
arssherMMeent
authored andcommitted
Stamp XLP_FIRST_IS_CONTRECORD only if we start writing with page offset.
Without this patch, on bootstrap XLP_FIRST_IS_CONTRECORD has been always put on header of a page where WAL writing continues. This confuses WAL decoding on safekeepers, making it think decoding starts in the middle of a record, leading to 2022-08-12T17:48:13.816665Z ERROR {tid=37}: query handler for 'START_WAL_PUSH postgresql://no_user:@localhost:15050' failed: failed to run ReceiveWalConn Caused by: 0: failed to process ProposerAcceptorMessage 1: invalid xlog page header: unexpected XLP_FIRST_IS_CONTRECORD at 0/2CF8000
1 parent 0d5f886 commit a1af529

File tree

1 file changed

+8
-2
lines changed
  • src/backend/access/transam

1 file changed

+8
-2
lines changed

src/backend/access/transam/xlog.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7861,14 +7861,20 @@ StartupXLOG(void)
78617861
{
78627862
int offs = (EndRecPtr % XLOG_BLCKSZ);
78637863
XLogRecPtr lastPage = EndRecPtr - offs;
7864+
int lastPageSize = ((lastPage % wal_segment_size) == 0) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD;
78647865
int idx = XLogRecPtrToBufIdx(lastPage);
78657866
XLogPageHeader xlogPageHdr = (XLogPageHeader) (XLogCtl->pages + idx * XLOG_BLCKSZ);
78667867

78677868
xlogPageHdr->xlp_pageaddr = lastPage;
78687869
xlogPageHdr->xlp_magic = XLOG_PAGE_MAGIC;
78697870
xlogPageHdr->xlp_tli = ThisTimeLineID;
7870-
xlogPageHdr->xlp_info = XLP_FIRST_IS_CONTRECORD; // FIXME
7871-
xlogPageHdr->xlp_rem_len = offs - SizeOfXLogShortPHD;
7871+
/*
7872+
* If we start writing with offset from page beginning, pretend in
7873+
* page header there is a record ending where actual data will
7874+
* start.
7875+
*/
7876+
xlogPageHdr->xlp_rem_len = offs - lastPageSize;
7877+
xlogPageHdr->xlp_info = (xlogPageHdr->xlp_rem_len > 0) ? XLP_FIRST_IS_CONTRECORD : 0;
78727878
readOff = XLogSegmentOffset(lastPage, wal_segment_size);
78737879

78747880
elog(LOG, "Continue writing WAL at %X/%X", LSN_FORMAT_ARGS(EndRecPtr));

0 commit comments

Comments
 (0)