Fix wal_consistency_checking enhanced desc output.
authorPeter Geoghegan <[email protected]>
Wed, 19 Apr 2023 17:42:39 +0000 (10:42 -0700)
committerPeter Geoghegan <[email protected]>
Wed, 19 Apr 2023 17:42:39 +0000 (10:42 -0700)
Recent enhancements to rmgr desc routines that made the output summarize
certain block data (added by commits 7d8219a4 and 1c453cfd) dealt with
records that lack relevant block data (and so have nothing to give a
more detailed summary of) by testing !DecodedBkpBlock.has_image.  As a
result, more detailed descriptions of block data were not output when
wal_consistency_checking was enabled.

This bug affected records with summarizable block data that also
happened to have an FPI that the REDO routine isn't supposed to apply
(FPIs used for consistency checking purposes only).  The presence of
such an FPI was incorrectly taken to indicate the absence of block data.

To fix, test DecodedBkpBlock.has_data, not !DecodedBkpBlock.has_image.
This is the exact condition that we care about, not an inexact proxy.

Author: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzm5Sc9cBg1qWV_cEBfLNJCrW9FjS-SoHVt8FLA7Ldn8yg@mail.gmail.com

src/backend/access/rmgrdesc/heapdesc.c
src/backend/access/rmgrdesc/nbtdesc.c
src/include/access/xlogreader.h

index 1c0fbb3e8cc59c9209045e6a18b74f3cbe6ea663..d73248abddf27d70dd527959deee0687dfda64b6 100644 (file)
@@ -184,7 +184,7 @@ heap2_desc(StringInfo buf, XLogReaderState *record)
                         xlrec->nredirected,
                         xlrec->ndead);
 
-       if (!XLogRecHasBlockImage(record, 0))
+       if (XLogRecHasBlockData(record, 0))
        {
            OffsetNumber *end;
            OffsetNumber *redirected;
@@ -223,7 +223,7 @@ heap2_desc(StringInfo buf, XLogReaderState *record)
 
        appendStringInfo(buf, "nunused: %u", xlrec->nunused);
 
-       if (!XLogRecHasBlockImage(record, 0))
+       if (XLogRecHasBlockData(record, 0))
        {
            OffsetNumber *nowunused;
 
@@ -241,7 +241,7 @@ heap2_desc(StringInfo buf, XLogReaderState *record)
        appendStringInfo(buf, "snapshotConflictHorizon: %u, nplans: %u",
                         xlrec->snapshotConflictHorizon, xlrec->nplans);
 
-       if (!XLogRecHasBlockImage(record, 0))
+       if (XLogRecHasBlockData(record, 0))
        {
            xl_heap_freeze_plan *plans;
            OffsetNumber *offsets;
@@ -270,7 +270,7 @@ heap2_desc(StringInfo buf, XLogReaderState *record)
        appendStringInfo(buf, "ntuples: %d, flags: 0x%02X", xlrec->ntuples,
                         xlrec->flags);
 
-       if (!XLogRecHasBlockImage(record, 0) && !isinit)
+       if (XLogRecHasBlockData(record, 0) && !isinit)
        {
            appendStringInfoString(buf, ", offsets:");
            array_desc(buf, xlrec->offsets, sizeof(OffsetNumber),
index c50d5547de86462e50ead987f17870e390bc4f5c..281a015f5632989418935bd070e43801c5e935ea 100644 (file)
@@ -62,7 +62,7 @@ btree_desc(StringInfo buf, XLogReaderState *record)
                appendStringInfo(buf, "ndeleted: %u, nupdated: %u",
                                 xlrec->ndeleted, xlrec->nupdated);
 
-               if (!XLogRecHasBlockImage(record, 0))
+               if (XLogRecHasBlockData(record, 0))
                    delvacuum_desc(buf, XLogRecGetBlockData(record, 0, NULL),
                                   xlrec->ndeleted, xlrec->nupdated);
                break;
@@ -75,7 +75,7 @@ btree_desc(StringInfo buf, XLogReaderState *record)
                                 xlrec->snapshotConflictHorizon,
                                 xlrec->ndeleted, xlrec->nupdated);
 
-               if (!XLogRecHasBlockImage(record, 0))
+               if (XLogRecHasBlockData(record, 0))
                    delvacuum_desc(buf, XLogRecGetBlockData(record, 0, NULL),
                                   xlrec->ndeleted, xlrec->nupdated);
                break;
index d77bb2ab9bc1fcda074ced622697173637e03a46..30d20c323e61a9b157d7999305af87ddc3e71691 100644 (file)
@@ -423,6 +423,8 @@ extern bool DecodeXLogRecord(XLogReaderState *state,
    ((decoder)->record->blocks[block_id].has_image)
 #define XLogRecBlockImageApply(decoder, block_id)      \
    ((decoder)->record->blocks[block_id].apply_image)
+#define XLogRecHasBlockData(decoder, block_id)     \
+   ((decoder)->record->blocks[block_id].has_data)
 
 #ifndef FRONTEND
 extern FullTransactionId XLogRecGetFullXid(XLogReaderState *record);