Skip to content

Commit 56801f6

Browse files
arsshertristan957
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 110f3ea commit 56801f6

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
@@ -7874,14 +7874,20 @@ StartupXLOG(void)
78747874
{
78757875
int offs = (EndRecPtr % XLOG_BLCKSZ);
78767876
XLogRecPtr lastPage = EndRecPtr - offs;
7877+
int lastPageSize = ((lastPage % wal_segment_size) == 0) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD;
78777878
int idx = XLogRecPtrToBufIdx(lastPage);
78787879
XLogPageHeader xlogPageHdr = (XLogPageHeader) (XLogCtl->pages + idx * XLOG_BLCKSZ);
78797880

78807881
xlogPageHdr->xlp_pageaddr = lastPage;
78817882
xlogPageHdr->xlp_magic = XLOG_PAGE_MAGIC;
78827883
xlogPageHdr->xlp_tli = ThisTimeLineID;
7883-
xlogPageHdr->xlp_info = XLP_FIRST_IS_CONTRECORD; // FIXME
7884-
xlogPageHdr->xlp_rem_len = offs - SizeOfXLogShortPHD;
7884+
/*
7885+
* If we start writing with offset from page beginning, pretend in
7886+
* page header there is a record ending where actual data will
7887+
* start.
7888+
*/
7889+
xlogPageHdr->xlp_rem_len = offs - lastPageSize;
7890+
xlogPageHdr->xlp_info = (xlogPageHdr->xlp_rem_len > 0) ? XLP_FIRST_IS_CONTRECORD : 0;
78857891
readOff = XLogSegmentOffset(lastPage, wal_segment_size);
78867892

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

0 commit comments

Comments
 (0)