Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix recent pg_walinspect fpi_length bug.
authorPeter Geoghegan <pg@bowt.ie>
Tue, 28 Mar 2023 17:53:48 +0000 (10:53 -0700)
committerPeter Geoghegan <pg@bowt.ie>
Tue, 28 Mar 2023 17:53:48 +0000 (10:53 -0700)
Commit 0276ae42dd taught pg_walinspect's pg_get_wal_record_info()
function to output NULLs rather than empty strings for its record
description and block_ref output parameters.  However, it inadvertently
moved the function call that sets fpi_length until after it was already
set.  As a result, pg_get_wal_record_info() always output spurious
fpi_length values of 0.

Fix by switching the order back (but keep the behavioral change).

Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Discussion: https://postgr.es/m/CAH2-WzkJmgSYkt6-smQ+57SxSmov+EKqFZdSimFewosoL_JKoA@mail.gmail.com

contrib/pg_walinspect/pg_walinspect.c

index 2933734122b78330f740cad7669efaf4945bb486..062e90dbce9b931ec6165e3da112ab71cdbc7958 100644 (file)
@@ -186,6 +186,7 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
    RmgrData    desc;
    uint32      fpi_len = 0;
    StringInfoData rec_desc;
+   StringInfoData rec_blk_ref;
    int         i = 0;
 
    desc = GetRmgr(XLogRecGetRmid(record));
@@ -197,6 +198,12 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
    initStringInfo(&rec_desc);
    desc.rm_desc(&rec_desc, record);
 
+   if (XLogRecHasAnyBlockRefs(record))
+   {
+       initStringInfo(&rec_blk_ref);
+       XLogRecGetBlockRefInfo(record, false, true, &rec_blk_ref, &fpi_len);
+   }
+
    values[i++] = LSNGetDatum(record->ReadRecPtr);
    values[i++] = LSNGetDatum(record->EndRecPtr);
    values[i++] = LSNGetDatum(XLogRecGetPrev(record));
@@ -205,7 +212,6 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
    values[i++] = CStringGetTextDatum(id);
    values[i++] = UInt32GetDatum(XLogRecGetTotalLen(record));
    values[i++] = UInt32GetDatum(XLogRecGetDataLen(record));
-
    values[i++] = UInt32GetDatum(fpi_len);
 
    if (rec_desc.len > 0)
@@ -213,15 +219,8 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
    else
        nulls[i++] = true;
 
-   /* Block references. */
    if (XLogRecHasAnyBlockRefs(record))
-   {
-       StringInfoData rec_blk_ref;
-
-       initStringInfo(&rec_blk_ref);
-       XLogRecGetBlockRefInfo(record, false, true, &rec_blk_ref, &fpi_len);
        values[i++] = CStringGetTextDatum(rec_blk_ref.data);
-   }
    else
        nulls[i++] = true;