Be more consistent about masking xl_info with ~XLR_INFO_MASK.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 4 Nov 2016 17:26:49 +0000 (13:26 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 4 Nov 2016 17:26:49 +0000 (13:26 -0400)
Generally, WAL resource managers are only supposed to examine the
top 4 bits of a WAL record's xl_info; the rest are reserved for
the WAL mechanism itself.  A few places were not consistent about
doing this with respect to XLOG_CHECKPOINT and XLOG_SWITCH records.
There's no bug currently, since no additional bits ever get set in
these specific record types, but that might not be true forever.
Let's follow the generic coding rule here too.

Michael Paquier

src/backend/access/transam/xlog.c
src/backend/access/transam/xlogreader.c

index 6b1f24ef1f645d57a476b0a6d564bfcfff13261c..813f6467fdfcfff30c7c830e2a4de0b347ce1908 100644 (file)
@@ -903,8 +903,9 @@ XLogInsertRecord(XLogRecData *rdata, XLogRecPtr fpw_lsn)
        pg_crc32c       rdata_crc;
        bool            inserted;
        XLogRecord *rechdr = (XLogRecord *) rdata->data;
+       uint8           info = rechdr->xl_info & ~XLR_INFO_MASK;
        bool            isLogSwitch = (rechdr->xl_rmid == RM_XLOG_ID &&
-                                                          rechdr->xl_info == XLOG_SWITCH);
+                                                          info == XLOG_SWITCH);
        XLogRecPtr      StartPos;
        XLogRecPtr      EndPos;
 
@@ -6170,7 +6171,7 @@ StartupXLOG(void)
                if (record != NULL)
                {
                        memcpy(&checkPoint, XLogRecGetData(xlogreader), sizeof(CheckPoint));
-                       wasShutdown = (record->xl_info == XLOG_CHECKPOINT_SHUTDOWN);
+                       wasShutdown = ((record->xl_info & ~XLR_INFO_MASK) == XLOG_CHECKPOINT_SHUTDOWN);
                        ereport(DEBUG1,
                                        (errmsg("checkpoint record is at %X/%X",
                                   (uint32) (checkPointLoc >> 32), (uint32) checkPointLoc)));
@@ -6328,7 +6329,7 @@ StartupXLOG(void)
                                         (errmsg("could not locate a valid checkpoint record")));
                }
                memcpy(&checkPoint, XLogRecGetData(xlogreader), sizeof(CheckPoint));
-               wasShutdown = (record->xl_info == XLOG_CHECKPOINT_SHUTDOWN);
+               wasShutdown = ((record->xl_info & ~XLR_INFO_MASK) == XLOG_CHECKPOINT_SHUTDOWN);
        }
 
        /*
@@ -7785,6 +7786,7 @@ ReadCheckpointRecord(XLogReaderState *xlogreader, XLogRecPtr RecPtr,
                                         int whichChkpt, bool report)
 {
        XLogRecord *record;
+       uint8           info;
 
        if (!XRecOffIsValid(RecPtr))
        {
@@ -7810,6 +7812,7 @@ ReadCheckpointRecord(XLogReaderState *xlogreader, XLogRecPtr RecPtr,
        }
 
        record = ReadRecord(xlogreader, RecPtr, LOG, true);
+       info = record->xl_info & ~XLR_INFO_MASK;
 
        if (record == NULL)
        {
@@ -7852,8 +7855,8 @@ ReadCheckpointRecord(XLogReaderState *xlogreader, XLogRecPtr RecPtr,
                }
                return NULL;
        }
-       if (record->xl_info != XLOG_CHECKPOINT_SHUTDOWN &&
-               record->xl_info != XLOG_CHECKPOINT_ONLINE)
+       if (info != XLOG_CHECKPOINT_SHUTDOWN &&
+               info != XLOG_CHECKPOINT_ONLINE)
        {
                switch (whichChkpt)
                {
index f2da505892408bcf31d9ab1bb4bb4f63e5a4804c..56d4c66ebbc0a167e32755d6ac4988c3afc10fd5 100644 (file)
@@ -462,7 +462,8 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg)
        /*
         * Special processing if it's an XLOG SWITCH record
         */
-       if (record->xl_rmid == RM_XLOG_ID && record->xl_info == XLOG_SWITCH)
+       if (record->xl_rmid == RM_XLOG_ID &&
+               (record->xl_info & ~XLR_INFO_MASK) == XLOG_SWITCH)
        {
                /* Pretend it extends to end of segment */
                state->EndRecPtr += XLogSegSize - 1;