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-2025, 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
4665 alvherre@alvh.no-ip. 20 :CBC 17 : standby_desc_running_xacts(StringInfo buf, xl_running_xacts *xlrec)
21 : : {
22 : : int i;
23 : :
4005 andres@anarazel.de 24 : 17 : appendStringInfo(buf, "nextXid %u latestCompletedXid %u oldestRunningXid %u",
25 : : xlrec->nextXid,
26 : : xlrec->latestCompletedXid,
27 : : xlrec->oldestRunningXid);
4665 alvherre@alvh.no-ip. 28 [ + + ]: 17 : 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 [ - + ]: 17 : if (xlrec->subxid_overflow)
1039 akapila@postgresql.o 36 :UBC 0 : appendStringInfoString(buf, "; subxid overflowed");
37 : :
1039 akapila@postgresql.o 38 [ - + ]:CBC 17 : if (xlrec->subxcnt > 0)
39 : : {
1039 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 : : }
4665 alvherre@alvh.no-ip. 44 :CBC 17 : }
45 : :
46 : : void
3943 heikki.linnakangas@i 47 : 1717 : standby_desc(StringInfo buf, XLogReaderState *record)
48 : : {
4102 49 : 1717 : char *rec = XLogRecGetData(record);
3943 50 : 1717 : uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
51 : :
4665 alvherre@alvh.no-ip. 52 [ + + ]: 1717 : if (info == XLOG_STANDBY_LOCK)
53 : : {
54 : 731 : xl_standby_locks *xlrec = (xl_standby_locks *) rec;
55 : : int i;
56 : :
57 [ + + ]: 1462 : for (i = 0; i < xlrec->nlocks; i++)
4005 andres@anarazel.de 58 : 731 : appendStringInfo(buf, "xid %u db %u rel %u ",
59 : : xlrec->locks[i].xid, xlrec->locks[i].dbOid,
60 : : xlrec->locks[i].relOid);
61 : : }
4665 alvherre@alvh.no-ip. 62 [ + + ]: 986 : else if (info == XLOG_RUNNING_XACTS)
63 : : {
64 : 17 : xl_running_xacts *xlrec = (xl_running_xacts *) rec;
65 : :
66 : 17 : standby_desc_running_xacts(buf, xlrec);
67 : : }
3423 andres@anarazel.de 68 [ + - ]: 969 : else if (info == XLOG_INVALIDATIONS)
69 : : {
70 : 969 : xl_invalidations *xlrec = (xl_invalidations *) rec;
71 : :
72 : 969 : standby_desc_invalidations(buf, xlrec->nmsgs, xlrec->msgs,
73 : : xlrec->dbId, xlrec->tsId,
74 : 969 : xlrec->relcacheInitFileInval);
75 : : }
4005 76 : 1717 : }
77 : :
78 : : const char *
79 : 1720 : standby_identify(uint8 info)
80 : : {
81 : 1720 : const char *id = NULL;
82 : :
4002 83 [ + + + - ]: 1720 : switch (info & ~XLR_INFO_MASK)
84 : : {
4005 85 : 732 : case XLOG_STANDBY_LOCK:
86 : 732 : id = "LOCK";
87 : 732 : break;
88 : 18 : case XLOG_RUNNING_XACTS:
89 : 18 : id = "RUNNING_XACTS";
90 : 18 : break;
3423 91 : 970 : case XLOG_INVALIDATIONS:
92 : 970 : id = "INVALIDATIONS";
93 : 970 : break;
94 : : }
95 : :
4005 96 : 1720 : return id;
97 : : }
98 : :
99 : : /* also used by non-standby records having analogous invalidation fields */
100 : : void
3423 101 : 5041 : 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 */
2124 fujii@postgresql.org 109 [ + + ]: 5041 : if (nmsgs <= 0)
110 : 75 : return;
111 : :
3423 andres@anarazel.de 112 [ + + ]: 4966 : if (relcacheInitFileInval)
113 : 1158 : appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u",
114 : : dbId, tsId);
115 : :
116 : 4966 : appendStringInfoString(buf, "; inval msgs:");
117 [ + + ]: 45115 : for (i = 0; i < nmsgs; i++)
118 : : {
119 : 40149 : SharedInvalidationMessage *msg = &msgs[i];
120 : :
121 [ + + ]: 40149 : if (msg->id >= 0)
122 : 31396 : appendStringInfo(buf, " catcache %d", msg->id);
123 [ + + ]: 8753 : else if (msg->id == SHAREDINVALCATALOG_ID)
124 : 12 : appendStringInfo(buf, " catalog %u", msg->cat.catId);
125 [ + + ]: 8741 : else if (msg->id == SHAREDINVALRELCACHE_ID)
126 : 5684 : appendStringInfo(buf, " relcache %u", msg->rc.relId);
127 : : /* not expected, but print something anyway */
128 [ - + ]: 3057 : else if (msg->id == SHAREDINVALSMGR_ID)
3423 andres@anarazel.de 129 :UBC 0 : appendStringInfoString(buf, " smgr");
130 : : /* not expected, but print something anyway */
3423 andres@anarazel.de 131 [ - + ]:CBC 3057 : else if (msg->id == SHAREDINVALRELMAP_ID)
3423 andres@anarazel.de 132 :UBC 0 : appendStringInfo(buf, " relmap db %u", msg->rm.dbId);
3423 andres@anarazel.de 133 [ + - ]:CBC 3057 : else if (msg->id == SHAREDINVALSNAPSHOT_ID)
134 : 3057 : appendStringInfo(buf, " snapshot %u", msg->sn.relId);
177 akapila@postgresql.o 135 [ # # ]:UBC 0 : else if (msg->id == SHAREDINVALRELSYNC_ID)
136 : 0 : appendStringInfo(buf, " relsync %u", msg->rs.relid);
137 : : else
3270 tgl@sss.pgh.pa.us 138 : 0 : appendStringInfo(buf, " unrecognized id %d", msg->id);
139 : : }
140 : : }
|