Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 89f3973

Browse files
committed
Fix WAL format incompatibility introduced by backpatching of 52ac6cd
52ac6cd added new field to ginxlogDeletePage and was backpatched to 9.4. That led to problems when patched postgres instance applies WAL records generated by non-patched one. WAL records generated by non-patched instance don't contain new field, which patched one is expecting to see. Thankfully, we can distinguish patched and non-patched WAL records by their data size. If we see that WAL record is generated by non-patched instance, we skip processing of new field. This commit comes with some assertions. In particular, if it appears that on some platform struct data size didn't change then static assertion will trigger. Reported-by: Simon Riggs Discussion: https://postgr.es/m/CANP8%2Bj%2BK4whxf7ET7%2BgO%2BG-baC3-WxqqH%3DnV4X2CgfEPA3Yu3g%40mail.gmail.com Author: Alexander Korotkov Reviewed-by: Simon Riggs, Alvaro Herrera Backpatch-through: 9.4
1 parent 7d7435c commit 89f3973

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/backend/access/gin/ginxlog.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,24 @@ ginRedoDeletePage(XLogReaderState *record)
531531
page = BufferGetPage(dbuffer);
532532
Assert(GinPageIsData(page));
533533
GinPageGetOpaque(page)->flags = GIN_DELETED;
534-
GinPageSetDeleteXid(page, data->deleteXid);
534+
535+
/*
536+
* deleteXid field of ginxlogDeletePage was added during backpatching.
537+
* But, non-backpatched instances will continue generate WAL without
538+
* this field. We should be able to correctly apply that. We can
539+
* distinguish new WAL records by size their data, because
540+
* ginxlogDeletePage changes its size on both 32-bit and 64-bit
541+
* platforms.
542+
*/
543+
StaticAssertStmt(sizeof(ginxlogDeletePage) !=
544+
sizeof(ginxlogDeletePageOld),
545+
"ginxlogDeletePage size should be changed "
546+
"with addition of deleteXid field");
547+
Assert(XLogRecGetDataLen(record) == sizeof(ginxlogDeletePage) ||
548+
XLogRecGetDataLen(record) == sizeof(ginxlogDeletePageOld));
549+
if (XLogRecGetDataLen(record) == sizeof(ginxlogDeletePage))
550+
GinPageSetDeleteXid(page, data->deleteXid);
551+
535552
PageSetLSN(page, lsn);
536553
MarkBufferDirty(dbuffer);
537554
}

src/include/access/ginxlog.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ typedef struct ginxlogDeletePage
161161
TransactionId deleteXid; /* last Xid which could see this page in scan */
162162
} ginxlogDeletePage;
163163

164+
/*
165+
* Previous version of ginxlogDeletePage struct, which didn't have deleteXid
166+
* field. Used for size comparison (see ginRedoDeletePage()).
167+
*/
168+
typedef struct ginxlogDeletePageOld
169+
{
170+
OffsetNumber parentOffset;
171+
BlockNumber rightLink;
172+
} ginxlogDeletePageOld;
173+
164174
#define XLOG_GIN_UPDATE_META_PAGE 0x60
165175

166176
/*

0 commit comments

Comments
 (0)