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

Generated by: LCOV version 1.13