Improve description of some WAL records with transaction commands
authorMichael Paquier
Mon, 13 Dec 2021 02:02:47 +0000 (11:02 +0900)
committerMichael Paquier
Mon, 13 Dec 2021 02:02:47 +0000 (11:02 +0900)
This commit improves the description of some WAL records for the
Transaction RMGR:
- Track remote_apply for a transaction commit.  This GUC is
user-settable, so this information can be useful for debugging.
- Add replication origin information for PREPARE TRANSACTION, with the
origin ID, LSN and timestamp
- Same as above, for ROLLBACK PREPARED.

This impacts the format of pg_waldump or anything using these
description routines, so no backpatch is done.

Author: Masahiko Sawada, Michael Paquier
Discussion: https://postgr.es/m/CAD21AoD2dJfgsdxk4_KciAZMZQoUiCvmV9sDpp8ZuKLtKCNXaA@mail.gmail.com

src/backend/access/rmgrdesc/xactdesc.c

index 4b0d10f0735fffe22d5ea6279b1dafca511ad7f8..fca03a00d9883f663e2a0408ec134def0024ec25 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "access/transam.h"
 #include "access/xact.h"
+#include "replication/origin.h"
 #include "storage/sinval.h"
 #include "storage/standbydefs.h"
 #include "utils/timestamp.h"
@@ -299,6 +300,9 @@ xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId
                               parsed.tsId,
                               XactCompletionRelcacheInitFileInval(parsed.xinfo));
 
+   if (XactCompletionApplyFeedback(parsed.xinfo))
+       appendStringInfoString(buf, "; apply_feedback");
+
    if (XactCompletionForceSyncCommit(parsed.xinfo))
        appendStringInfoString(buf, "; sync");
 
@@ -312,7 +316,7 @@ xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId
 }
 
 static void
-xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec)
+xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec, RepOriginId origin_id)
 {
    xl_xact_parsed_abort parsed;
 
@@ -326,10 +330,18 @@ xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec)
 
    xact_desc_relations(buf, "rels", parsed.nrels, parsed.xnodes);
    xact_desc_subxacts(buf, parsed.nsubxacts, parsed.subxacts);
+
+   if (parsed.xinfo & XACT_XINFO_HAS_ORIGIN)
+   {
+       appendStringInfo(buf, "; origin: node %u, lsn %X/%X, at %s",
+                        origin_id,
+                        LSN_FORMAT_ARGS(parsed.origin_lsn),
+                        timestamptz_to_str(parsed.origin_timestamp));
+   }
 }
 
 static void
-xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec)
+xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec, RepOriginId origin_id)
 {
    xl_xact_parsed_prepare parsed;
 
@@ -345,6 +357,16 @@ xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec)
 
    standby_desc_invalidations(buf, parsed.nmsgs, parsed.msgs, parsed.dbId,
                               parsed.tsId, xlrec->initfileinval);
+
+   /*
+    * Check if the replication origin has been set in this record in the
+    * same way as PrepareRedoAdd().
+    */
+   if (origin_id != InvalidRepOriginId)
+       appendStringInfo(buf, "; origin: node %u, lsn %X/%X, at %s",
+                        origin_id,
+                        LSN_FORMAT_ARGS(parsed.origin_lsn),
+                        timestamptz_to_str(parsed.origin_timestamp));
 }
 
 static void
@@ -375,13 +397,15 @@ xact_desc(StringInfo buf, XLogReaderState *record)
    {
        xl_xact_abort *xlrec = (xl_xact_abort *) rec;
 
-       xact_desc_abort(buf, XLogRecGetInfo(record), xlrec);
+       xact_desc_abort(buf, XLogRecGetInfo(record), xlrec,
+                       XLogRecGetOrigin(record));
    }
    else if (info == XLOG_XACT_PREPARE)
    {
        xl_xact_prepare *xlrec = (xl_xact_prepare *) rec;
 
-       xact_desc_prepare(buf, XLogRecGetInfo(record), xlrec);
+       xact_desc_prepare(buf, XLogRecGetInfo(record), xlrec,
+                         XLogRecGetOrigin(record));
    }
    else if (info == XLOG_XACT_ASSIGNMENT)
    {