LCOV - code coverage report
Current view: top level - src/bin/pg_waldump - standbydesc.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 85.9 % 64 55
Test Date: 2026-02-17 17:20:33 Functions: 100.0 % 4 4
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  * standbydesc.c
       4              :  *    rmgr descriptor routines for storage/ipc/standby.c
       5              :  *
       6              :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       7              :  * Portions Copyright (c) 1994, Regents of the University of California
       8              :  *
       9              :  *
      10              :  * IDENTIFICATION
      11              :  *    src/backend/access/rmgrdesc/standbydesc.c
      12              :  *
      13              :  *-------------------------------------------------------------------------
      14              :  */
      15              : #include "postgres.h"
      16              : 
      17              : #include "storage/standbydefs.h"
      18              : 
      19              : static void
      20           14 : standby_desc_running_xacts(StringInfo buf, xl_running_xacts *xlrec)
      21              : {
      22              :     int         i;
      23              : 
      24           14 :     appendStringInfo(buf, "nextXid %u latestCompletedXid %u oldestRunningXid %u",
      25              :                      xlrec->nextXid,
      26              :                      xlrec->latestCompletedXid,
      27              :                      xlrec->oldestRunningXid);
      28           14 :     if (xlrec->xcnt > 0)
      29              :     {
      30           14 :         appendStringInfo(buf, "; %d xacts:", xlrec->xcnt);
      31           28 :         for (i = 0; i < xlrec->xcnt; i++)
      32           14 :             appendStringInfo(buf, " %u", xlrec->xids[i]);
      33              :     }
      34              : 
      35           14 :     if (xlrec->subxid_overflow)
      36            0 :         appendStringInfoString(buf, "; subxid overflowed");
      37              : 
      38           14 :     if (xlrec->subxcnt > 0)
      39              :     {
      40            0 :         appendStringInfo(buf, "; %d subxacts:", xlrec->subxcnt);
      41            0 :         for (i = 0; i < xlrec->subxcnt; i++)
      42            0 :             appendStringInfo(buf, " %u", xlrec->xids[xlrec->xcnt + i]);
      43              :     }
      44           14 : }
      45              : 
      46              : void
      47         1711 : standby_desc(StringInfo buf, XLogReaderState *record)
      48              : {
      49         1711 :     char       *rec = XLogRecGetData(record);
      50         1711 :     uint8       info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
      51              : 
      52         1711 :     if (info == XLOG_STANDBY_LOCK)
      53              :     {
      54          729 :         xl_standby_locks *xlrec = (xl_standby_locks *) rec;
      55              :         int         i;
      56              : 
      57         1458 :         for (i = 0; i < xlrec->nlocks; i++)
      58          729 :             appendStringInfo(buf, "xid %u db %u rel %u ",
      59              :                              xlrec->locks[i].xid, xlrec->locks[i].dbOid,
      60              :                              xlrec->locks[i].relOid);
      61              :     }
      62          982 :     else if (info == XLOG_RUNNING_XACTS)
      63              :     {
      64           14 :         xl_running_xacts *xlrec = (xl_running_xacts *) rec;
      65              : 
      66           14 :         standby_desc_running_xacts(buf, xlrec);
      67              :     }
      68          968 :     else if (info == XLOG_INVALIDATIONS)
      69              :     {
      70          968 :         xl_invalidations *xlrec = (xl_invalidations *) rec;
      71              : 
      72          968 :         standby_desc_invalidations(buf, xlrec->nmsgs, xlrec->msgs,
      73              :                                    xlrec->dbId, xlrec->tsId,
      74          968 :                                    xlrec->relcacheInitFileInval);
      75              :     }
      76         1711 : }
      77              : 
      78              : const char *
      79         1714 : standby_identify(uint8 info)
      80              : {
      81         1714 :     const char *id = NULL;
      82              : 
      83         1714 :     switch (info & ~XLR_INFO_MASK)
      84              :     {
      85          730 :         case XLOG_STANDBY_LOCK:
      86          730 :             id = "LOCK";
      87          730 :             break;
      88           15 :         case XLOG_RUNNING_XACTS:
      89           15 :             id = "RUNNING_XACTS";
      90           15 :             break;
      91          969 :         case XLOG_INVALIDATIONS:
      92          969 :             id = "INVALIDATIONS";
      93          969 :             break;
      94              :     }
      95              : 
      96         1714 :     return id;
      97              : }
      98              : 
      99              : /* also used by non-standby records having analogous invalidation fields */
     100              : void
     101         5042 : standby_desc_invalidations(StringInfo buf,
     102              :                            int nmsgs, SharedInvalidationMessage *msgs,
     103              :                            Oid dbId, Oid tsId,
     104              :                            bool relcacheInitFileInval)
     105              : {
     106              :     int         i;
     107              : 
     108              :     /* Do nothing if there are no invalidation messages */
     109         5042 :     if (nmsgs <= 0)
     110           68 :         return;
     111              : 
     112         4974 :     if (relcacheInitFileInval)
     113         1158 :         appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u",
     114              :                          dbId, tsId);
     115              : 
     116         4974 :     appendStringInfoString(buf, "; inval msgs:");
     117        42590 :     for (i = 0; i < nmsgs; i++)
     118              :     {
     119        37616 :         SharedInvalidationMessage *msg = &msgs[i];
     120              : 
     121        37616 :         if (msg->id >= 0)
     122        28854 :             appendStringInfo(buf, " catcache %d", msg->id);
     123         8762 :         else if (msg->id == SHAREDINVALCATALOG_ID)
     124           12 :             appendStringInfo(buf, " catalog %u", msg->cat.catId);
     125         8750 :         else if (msg->id == SHAREDINVALRELCACHE_ID)
     126         5654 :             appendStringInfo(buf, " relcache %u", msg->rc.relId);
     127              :         /* not expected, but print something anyway */
     128         3096 :         else if (msg->id == SHAREDINVALSMGR_ID)
     129            0 :             appendStringInfoString(buf, " smgr");
     130              :         /* not expected, but print something anyway */
     131         3096 :         else if (msg->id == SHAREDINVALRELMAP_ID)
     132            0 :             appendStringInfo(buf, " relmap db %u", msg->rm.dbId);
     133         3096 :         else if (msg->id == SHAREDINVALSNAPSHOT_ID)
     134         3096 :             appendStringInfo(buf, " snapshot %u", msg->sn.relId);
     135            0 :         else if (msg->id == SHAREDINVALRELSYNC_ID)
     136            0 :             appendStringInfo(buf, " relsync %u", msg->rs.relid);
     137              :         else
     138            0 :             appendStringInfo(buf, " unrecognized id %d", msg->id);
     139              :     }
     140              : }
        

Generated by: LCOV version 2.0-1