LCOV - code coverage report
Current view: top level - src/bin/pg_waldump - standbydesc.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 55 62 88.7 %
Date: 2024-04-19 12:11:01 Functions: 4 4 100.0 %
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-2024, 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          28 : standby_desc_running_xacts(StringInfo buf, xl_running_xacts *xlrec)
      21             : {
      22             :     int         i;
      23             : 
      24          28 :     appendStringInfo(buf, "nextXid %u latestCompletedXid %u oldestRunningXid %u",
      25             :                      xlrec->nextXid,
      26             :                      xlrec->latestCompletedXid,
      27             :                      xlrec->oldestRunningXid);
      28          28 :     if (xlrec->xcnt > 0)
      29             :     {
      30          28 :         appendStringInfo(buf, "; %d xacts:", xlrec->xcnt);
      31          56 :         for (i = 0; i < xlrec->xcnt; i++)
      32          28 :             appendStringInfo(buf, " %u", xlrec->xids[i]);
      33             :     }
      34             : 
      35          28 :     if (xlrec->subxid_overflow)
      36           0 :         appendStringInfoString(buf, "; subxid overflowed");
      37             : 
      38          28 :     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          28 : }
      45             : 
      46             : void
      47        3416 : standby_desc(StringInfo buf, XLogReaderState *record)
      48             : {
      49        3416 :     char       *rec = XLogRecGetData(record);
      50        3416 :     uint8       info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
      51             : 
      52        3416 :     if (info == XLOG_STANDBY_LOCK)
      53             :     {
      54        1436 :         xl_standby_locks *xlrec = (xl_standby_locks *) rec;
      55             :         int         i;
      56             : 
      57        2872 :         for (i = 0; i < xlrec->nlocks; i++)
      58        1436 :             appendStringInfo(buf, "xid %u db %u rel %u ",
      59             :                              xlrec->locks[i].xid, xlrec->locks[i].dbOid,
      60             :                              xlrec->locks[i].relOid);
      61             :     }
      62        1980 :     else if (info == XLOG_RUNNING_XACTS)
      63             :     {
      64          28 :         xl_running_xacts *xlrec = (xl_running_xacts *) rec;
      65             : 
      66          28 :         standby_desc_running_xacts(buf, xlrec);
      67             :     }
      68        1952 :     else if (info == XLOG_INVALIDATIONS)
      69             :     {
      70        1952 :         xl_invalidations *xlrec = (xl_invalidations *) rec;
      71             : 
      72        1952 :         standby_desc_invalidations(buf, xlrec->nmsgs, xlrec->msgs,
      73             :                                    xlrec->dbId, xlrec->tsId,
      74        1952 :                                    xlrec->relcacheInitFileInval);
      75             :     }
      76        3416 : }
      77             : 
      78             : const char *
      79        3422 : standby_identify(uint8 info)
      80             : {
      81        3422 :     const char *id = NULL;
      82             : 
      83        3422 :     switch (info & ~XLR_INFO_MASK)
      84             :     {
      85        1438 :         case XLOG_STANDBY_LOCK:
      86        1438 :             id = "LOCK";
      87        1438 :             break;
      88          30 :         case XLOG_RUNNING_XACTS:
      89          30 :             id = "RUNNING_XACTS";
      90          30 :             break;
      91        1954 :         case XLOG_INVALIDATIONS:
      92        1954 :             id = "INVALIDATIONS";
      93        1954 :             break;
      94             :     }
      95             : 
      96        3422 :     return id;
      97             : }
      98             : 
      99             : /*
     100             :  * This routine is used by both standby_desc and xact_desc, because
     101             :  * transaction commits and XLOG_INVALIDATIONS messages contain invalidations;
     102             :  * it seems pointless to duplicate the code.
     103             :  */
     104             : void
     105        7460 : standby_desc_invalidations(StringInfo buf,
     106             :                            int nmsgs, SharedInvalidationMessage *msgs,
     107             :                            Oid dbId, Oid tsId,
     108             :                            bool relcacheInitFileInval)
     109             : {
     110             :     int         i;
     111             : 
     112             :     /* Do nothing if there are no invalidation messages */
     113        7460 :     if (nmsgs <= 0)
     114         136 :         return;
     115             : 
     116        7324 :     if (relcacheInitFileInval)
     117        1180 :         appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u",
     118             :                          dbId, tsId);
     119             : 
     120        7324 :     appendStringInfoString(buf, "; inval msgs:");
     121       73776 :     for (i = 0; i < nmsgs; i++)
     122             :     {
     123       66452 :         SharedInvalidationMessage *msg = &msgs[i];
     124             : 
     125       66452 :         if (msg->id >= 0)
     126       51932 :             appendStringInfo(buf, " catcache %d", msg->id);
     127       14520 :         else if (msg->id == SHAREDINVALCATALOG_ID)
     128          24 :             appendStringInfo(buf, " catalog %u", msg->cat.catId);
     129       14496 :         else if (msg->id == SHAREDINVALRELCACHE_ID)
     130        8636 :             appendStringInfo(buf, " relcache %u", msg->rc.relId);
     131             :         /* not expected, but print something anyway */
     132        5860 :         else if (msg->id == SHAREDINVALSMGR_ID)
     133           0 :             appendStringInfoString(buf, " smgr");
     134             :         /* not expected, but print something anyway */
     135        5860 :         else if (msg->id == SHAREDINVALRELMAP_ID)
     136           0 :             appendStringInfo(buf, " relmap db %u", msg->rm.dbId);
     137        5860 :         else if (msg->id == SHAREDINVALSNAPSHOT_ID)
     138        5860 :             appendStringInfo(buf, " snapshot %u", msg->sn.relId);
     139             :         else
     140           0 :             appendStringInfo(buf, " unrecognized id %d", msg->id);
     141             :     }
     142             : }

Generated by: LCOV version 1.14