LCOV - code coverage report
Current view: top level - src/bin/pg_waldump - standbydesc.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 86.2 % 65 56
Test Date: 2026-04-07 14:16:30 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           22 : standby_desc_running_xacts(StringInfo buf, xl_running_xacts *xlrec)
      21              : {
      22              :     int         i;
      23              : 
      24           22 :     appendStringInfo(buf, "nextXid %u latestCompletedXid %u oldestRunningXid %u",
      25              :                      xlrec->nextXid,
      26              :                      xlrec->latestCompletedXid,
      27              :                      xlrec->oldestRunningXid);
      28           22 :     if (xlrec->xcnt > 0)
      29              :     {
      30           22 :         appendStringInfo(buf, "; %d xacts:", xlrec->xcnt);
      31           44 :         for (i = 0; i < xlrec->xcnt; i++)
      32           22 :             appendStringInfo(buf, " %u", xlrec->xids[i]);
      33              :     }
      34              : 
      35           22 :     if (xlrec->subxid_overflow)
      36            0 :         appendStringInfoString(buf, "; subxid overflowed");
      37              : 
      38           22 :     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              : 
      45           22 :     appendStringInfo(buf, "; dbid: %u", xlrec->dbid);
      46           22 : }
      47              : 
      48              : void
      49         3061 : standby_desc(StringInfo buf, XLogReaderState *record)
      50              : {
      51         3061 :     char       *rec = XLogRecGetData(record);
      52         3061 :     uint8       info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
      53              : 
      54         3061 :     if (info == XLOG_STANDBY_LOCK)
      55              :     {
      56         1029 :         xl_standby_locks *xlrec = (xl_standby_locks *) rec;
      57              :         int         i;
      58              : 
      59         2058 :         for (i = 0; i < xlrec->nlocks; i++)
      60         1029 :             appendStringInfo(buf, "xid %u db %u rel %u ",
      61              :                              xlrec->locks[i].xid, xlrec->locks[i].dbOid,
      62              :                              xlrec->locks[i].relOid);
      63              :     }
      64         2032 :     else if (info == XLOG_RUNNING_XACTS)
      65              :     {
      66           22 :         xl_running_xacts *xlrec = (xl_running_xacts *) rec;
      67              : 
      68           22 :         standby_desc_running_xacts(buf, xlrec);
      69              :     }
      70         2010 :     else if (info == XLOG_INVALIDATIONS)
      71              :     {
      72         2010 :         xl_invalidations *xlrec = (xl_invalidations *) rec;
      73              : 
      74         2010 :         standby_desc_invalidations(buf, xlrec->nmsgs, xlrec->msgs,
      75              :                                    xlrec->dbId, xlrec->tsId,
      76         2010 :                                    xlrec->relcacheInitFileInval);
      77              :     }
      78         3061 : }
      79              : 
      80              : const char *
      81         3070 : standby_identify(uint8 info)
      82              : {
      83         3070 :     const char *id = NULL;
      84              : 
      85         3070 :     switch (info & ~XLR_INFO_MASK)
      86              :     {
      87         1032 :         case XLOG_STANDBY_LOCK:
      88         1032 :             id = "LOCK";
      89         1032 :             break;
      90           25 :         case XLOG_RUNNING_XACTS:
      91           25 :             id = "RUNNING_XACTS";
      92           25 :             break;
      93         2013 :         case XLOG_INVALIDATIONS:
      94         2013 :             id = "INVALIDATIONS";
      95         2013 :             break;
      96              :     }
      97              : 
      98         3070 :     return id;
      99              : }
     100              : 
     101              : /* also used by non-standby records having analogous invalidation fields */
     102              : void
     103         9008 : standby_desc_invalidations(StringInfo buf,
     104              :                            int nmsgs, SharedInvalidationMessage *msgs,
     105              :                            Oid dbId, Oid tsId,
     106              :                            bool relcacheInitFileInval)
     107              : {
     108              :     int         i;
     109              : 
     110              :     /* Do nothing if there are no invalidation messages */
     111         9008 :     if (nmsgs <= 0)
     112          165 :         return;
     113              : 
     114         8843 :     if (relcacheInitFileInval)
     115         2183 :         appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u",
     116              :                          dbId, tsId);
     117              : 
     118         8843 :     appendStringInfoString(buf, "; inval msgs:");
     119        66232 :     for (i = 0; i < nmsgs; i++)
     120              :     {
     121        57389 :         SharedInvalidationMessage *msg = &msgs[i];
     122              : 
     123        57389 :         if (msg->id >= 0)
     124        43178 :             appendStringInfo(buf, " catcache %d", msg->id);
     125        14211 :         else if (msg->id == SHAREDINVALCATALOG_ID)
     126           28 :             appendStringInfo(buf, " catalog %u", msg->cat.catId);
     127        14183 :         else if (msg->id == SHAREDINVALRELCACHE_ID)
     128        10563 :             appendStringInfo(buf, " relcache %u", msg->rc.relId);
     129              :         /* not expected, but print something anyway */
     130         3620 :         else if (msg->id == SHAREDINVALSMGR_ID)
     131            0 :             appendStringInfoString(buf, " smgr");
     132              :         /* not expected, but print something anyway */
     133         3620 :         else if (msg->id == SHAREDINVALRELMAP_ID)
     134            0 :             appendStringInfo(buf, " relmap db %u", msg->rm.dbId);
     135         3620 :         else if (msg->id == SHAREDINVALSNAPSHOT_ID)
     136         3620 :             appendStringInfo(buf, " snapshot %u", msg->sn.relId);
     137            0 :         else if (msg->id == SHAREDINVALRELSYNC_ID)
     138            0 :             appendStringInfo(buf, " relsync %u", msg->rs.relid);
     139              :         else
     140            0 :             appendStringInfo(buf, " unrecognized id %d", msg->id);
     141              :     }
     142              : }
        

Generated by: LCOV version 2.0-1