Age Owner Branch data TLA 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
4931 alvherre@alvh.no-ip. 20 :CBC 31 : standby_desc_running_xacts(StringInfo buf, xl_running_xacts *xlrec)
21 : : {
22 : : int i;
23 : :
4271 andres@anarazel.de 24 : 31 : appendStringInfo(buf, "nextXid %u latestCompletedXid %u oldestRunningXid %u",
25 : : xlrec->nextXid,
26 : : xlrec->latestCompletedXid,
27 : : xlrec->oldestRunningXid);
4931 alvherre@alvh.no-ip. 28 [ + + ]: 31 : 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 [ - + ]: 31 : if (xlrec->subxid_overflow)
1305 akapila@postgresql.o 36 :UBC 0 : appendStringInfoString(buf, "; subxid overflowed");
37 : :
1305 akapila@postgresql.o 38 [ - + ]:CBC 31 : if (xlrec->subxcnt > 0)
39 : : {
1305 akapila@postgresql.o 40 :UBC 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 : : }
4931 alvherre@alvh.no-ip. 44 :CBC 31 : }
45 : :
46 : : void
4209 heikki.linnakangas@i 47 : 3075 : standby_desc(StringInfo buf, XLogReaderState *record)
48 : : {
4368 49 : 3075 : char *rec = XLogRecGetData(record);
4209 50 : 3075 : uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
51 : :
4931 alvherre@alvh.no-ip. 52 [ + + ]: 3075 : if (info == XLOG_STANDBY_LOCK)
53 : : {
54 : 1033 : xl_standby_locks *xlrec = (xl_standby_locks *) rec;
55 : : int i;
56 : :
57 [ + + ]: 2066 : for (i = 0; i < xlrec->nlocks; i++)
4271 andres@anarazel.de 58 : 1033 : appendStringInfo(buf, "xid %u db %u rel %u ",
59 : : xlrec->locks[i].xid, xlrec->locks[i].dbOid,
60 : : xlrec->locks[i].relOid);
61 : : }
4931 alvherre@alvh.no-ip. 62 [ + + ]: 2042 : else if (info == XLOG_RUNNING_XACTS)
63 : : {
64 : 31 : xl_running_xacts *xlrec = (xl_running_xacts *) rec;
65 : :
66 : 31 : standby_desc_running_xacts(buf, xlrec);
67 : : }
3689 andres@anarazel.de 68 [ + - ]: 2011 : else if (info == XLOG_INVALIDATIONS)
69 : : {
70 : 2011 : xl_invalidations *xlrec = (xl_invalidations *) rec;
71 : :
72 : 2011 : standby_desc_invalidations(buf, xlrec->nmsgs, xlrec->msgs,
73 : : xlrec->dbId, xlrec->tsId,
74 : 2011 : xlrec->relcacheInitFileInval);
75 : : }
4271 76 : 3075 : }
77 : :
78 : : const char *
79 : 3084 : standby_identify(uint8 info)
80 : : {
81 : 3084 : const char *id = NULL;
82 : :
4268 83 [ + + + - ]: 3084 : switch (info & ~XLR_INFO_MASK)
84 : : {
4271 85 : 1036 : case XLOG_STANDBY_LOCK:
86 : 1036 : id = "LOCK";
87 : 1036 : break;
88 : 34 : case XLOG_RUNNING_XACTS:
89 : 34 : id = "RUNNING_XACTS";
90 : 34 : break;
3689 91 : 2014 : case XLOG_INVALIDATIONS:
92 : 2014 : id = "INVALIDATIONS";
93 : 2014 : break;
94 : : }
95 : :
4271 96 : 3084 : return id;
97 : : }
98 : :
99 : : /* also used by non-standby records having analogous invalidation fields */
100 : : void
3689 101 : 9035 : 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 */
2390 fujii@postgresql.org 109 [ + + ]: 9035 : if (nmsgs <= 0)
110 : 172 : return;
111 : :
3689 andres@anarazel.de 112 [ + + ]: 8863 : if (relcacheInitFileInval)
113 : 2184 : appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u",
114 : : dbId, tsId);
115 : :
116 : 8863 : appendStringInfoString(buf, "; inval msgs:");
117 [ + + ]: 69067 : for (i = 0; i < nmsgs; i++)
118 : : {
119 : 60204 : SharedInvalidationMessage *msg = &msgs[i];
120 : :
121 [ + + ]: 60204 : if (msg->id >= 0)
122 : 45968 : appendStringInfo(buf, " catcache %d", msg->id);
123 [ + + ]: 14236 : else if (msg->id == SHAREDINVALCATALOG_ID)
124 : 28 : appendStringInfo(buf, " catalog %u", msg->cat.catId);
125 [ + + ]: 14208 : else if (msg->id == SHAREDINVALRELCACHE_ID)
126 : 10599 : appendStringInfo(buf, " relcache %u", msg->rc.relId);
127 : : /* not expected, but print something anyway */
128 [ - + ]: 3609 : else if (msg->id == SHAREDINVALSMGR_ID)
3689 andres@anarazel.de 129 :UBC 0 : appendStringInfoString(buf, " smgr");
130 : : /* not expected, but print something anyway */
3689 andres@anarazel.de 131 [ - + ]:CBC 3609 : else if (msg->id == SHAREDINVALRELMAP_ID)
3689 andres@anarazel.de 132 :UBC 0 : appendStringInfo(buf, " relmap db %u", msg->rm.dbId);
3689 andres@anarazel.de 133 [ + - ]:CBC 3609 : else if (msg->id == SHAREDINVALSNAPSHOT_ID)
134 : 3609 : appendStringInfo(buf, " snapshot %u", msg->sn.relId);
443 akapila@postgresql.o 135 [ # # ]:UBC 0 : else if (msg->id == SHAREDINVALRELSYNC_ID)
136 : 0 : appendStringInfo(buf, " relsync %u", msg->rs.relid);
137 : : else
3536 tgl@sss.pgh.pa.us 138 : 0 : appendStringInfo(buf, " unrecognized id %d", msg->id);
139 : : }
140 : : }
|