Allow WAL record data on first modification after a checkpoint.
authorThomas Munro <[email protected]>
Fri, 11 Jan 2019 13:17:02 +0000 (02:17 +1300)
committerThomas Munro <[email protected]>
Wed, 17 Jul 2019 03:28:27 +0000 (15:28 +1200)
Provide a way to attach data to WAL record conditionally, so that it is
included only if this turns out to the be first modification to a given
block after a checkpoint.

This will be used to record undo log meta-data, to avoid a data
synchronization problem with online checkpoints.

Author: Thomas Munro
Reviewed-by:
Discussion:

src/backend/access/transam/xloginsert.c
src/include/access/xloginsert.h

index 3ec67d468b5a22a0570f2d4f27fca70619070ab9..001d7cb05b15e68dd840ae09978b32cae3299dc3 100644 (file)
@@ -565,6 +565,21 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
                        needs_data = false;
                else if ((regbuf->flags & REGBUF_KEEP_DATA) != 0)
                        needs_data = true;
+               else if ((regbuf->flags & REGBUF_KEEP_DATA_AFTER_CP) != 0)
+               {
+                       XLogRecPtr      page_lsn = PageGetLSN(regbuf->page);
+
+                       needs_data = (page_lsn <= RedoRecPtr);
+                       if (!needs_data)
+                       {
+                               /*
+                                * XLogInsertRecord() will detect if our view of the latest
+                                * checkpoint's RedoRecPtr is out of date.
+                                */
+                               if (*fpw_lsn == InvalidXLogRecPtr || page_lsn < *fpw_lsn)
+                                       *fpw_lsn = page_lsn;
+                       }
+               }
                else
                        needs_data = !needs_backup;
 
index df24089ea453991fce16479dc54789f9cf11ba86..22b388cb337fc76e665f570fb1091a742e2df509 100644 (file)
@@ -37,6 +37,8 @@
                                                                         * will be skipped) */
 #define REGBUF_KEEP_DATA       0x10    /* include data even if a full-page image
                                                                         * is taken */
+#define REGBUF_KEEP_DATA_AFTER_CP 0x20 /* include data on the first
+                                                                               * modification after a checkpoint */
 
 /* prototypes for public functions in xloginsert.c: */
 extern void XLogBeginInsert(void);