Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix WAL format incompatibility introduced by backpatching of 52ac6cd2d0
authorAlexander Korotkov <akorotkov@postgresql.org>
Sun, 24 Mar 2019 12:26:45 +0000 (15:26 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Sun, 24 Mar 2019 13:31:23 +0000 (16:31 +0300)
52ac6cd2d0 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

src/backend/access/gin/ginxlog.c
src/include/access/gin_private.h

index 76dabf19736cb574a10a8b92ba5542bca875f61f..11b2da163129d998dff59540d40a26cee88afff3 100644 (file)
@@ -720,12 +720,30 @@ ginRedoDeletePage(XLogRecPtr lsn, XLogRecord *record)
    else
    {
        dbuffer = XLogReadBuffer(data->node, data->blkno, false);
+
+       /*
+        * deleteXid field of ginxlogDeletePage was added during backpatching.
+        * But, non-backpatched instances will continue generate WAL without
+        * this field.  We should be able to correctly apply that.  We can
+        * distinguish new WAL records by size their data, because
+        * ginxlogDeletePage changes its size on both 32-bit and 64-bit
+        * platforms.
+        */
+       StaticAssertStmt(sizeof(ginxlogDeletePage) !=
+                        sizeof(ginxlogDeletePageOld),
+                        "ginxlogDeletePage size should be changed "
+                        "with addition of deleteXid field");
+       Assert(record->xl_len == sizeof(ginxlogDeletePage) ||
+              record->xl_len == sizeof(ginxlogDeletePageOld));
+
        if (BufferIsValid(dbuffer))
        {
            page = BufferGetPage(dbuffer);
            if (lsn > PageGetLSN(page))
            {
                Assert(GinPageIsData(page));
+               if (record->xl_len == sizeof(ginxlogDeletePage))
+                   GinPageSetDeleteXid(page, data->deleteXid);
                GinPageGetOpaque(page)->flags = GIN_DELETED;
                PageSetLSN(page, lsn);
                MarkBufferDirty(dbuffer);
index 6b1ada5d006338b95beff6819cb1ab53a586bf0f..54e55940eb051e3d4dfb891f4573801aa7a53cc6 100644 (file)
@@ -586,6 +586,20 @@ typedef struct ginxlogDeletePage
    TransactionId deleteXid;    /* last Xid which could see this page in scan */
 } ginxlogDeletePage;
 
+/*
+ * Previous version of ginxlogDeletePage struct, which didn't have deleteXid
+ * field.  Used for size comparison (see ginRedoDeletePage()).
+ */
+typedef struct ginxlogDeletePageOld
+{
+   RelFileNode node;
+   BlockNumber blkno;
+   BlockNumber parentBlkno;
+   OffsetNumber parentOffset;
+   BlockNumber leftBlkno;
+   BlockNumber rightLink;
+} ginxlogDeletePageOld;
+
 #define XLOG_GIN_UPDATE_META_PAGE 0x60
 
 typedef struct ginxlogUpdateMeta