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-2023, 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 CBC 4 : standby_desc_running_xacts(StringInfo buf, xl_running_xacts *xlrec)
21 : {
22 : int i;
23 :
24 4 : appendStringInfo(buf, "nextXid %u latestCompletedXid %u oldestRunningXid %u",
25 : xlrec->nextXid,
26 : xlrec->latestCompletedXid,
27 : xlrec->oldestRunningXid);
28 4 : if (xlrec->xcnt > 0)
29 : {
30 UBC 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 CBC 4 : if (xlrec->subxid_overflow)
36 UNC 0 : appendStringInfoString(buf, "; subxid overflowed");
37 :
38 GNC 4 : if (xlrec->subxcnt > 0)
39 : {
40 UNC 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 GIC 4 : }
45 ECB :
46 : void
47 GBC 6 : standby_desc(StringInfo buf, XLogReaderState *record)
48 EUB : {
49 GBC 6 : char *rec = XLogRecGetData(record);
50 GIC 6 : uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
51 ECB :
52 GIC 6 : if (info == XLOG_STANDBY_LOCK)
53 : {
54 CBC 2 : xl_standby_locks *xlrec = (xl_standby_locks *) rec;
55 : int i;
56 ECB :
57 CBC 4 : for (i = 0; i < xlrec->nlocks; i++)
58 GIC 2 : appendStringInfo(buf, "xid %u db %u rel %u ",
59 ECB : xlrec->locks[i].xid, xlrec->locks[i].dbOid,
60 : xlrec->locks[i].relOid);
61 : }
62 GIC 4 : else if (info == XLOG_RUNNING_XACTS)
63 : {
64 CBC 4 : xl_running_xacts *xlrec = (xl_running_xacts *) rec;
65 ECB :
66 GIC 4 : standby_desc_running_xacts(buf, xlrec);
67 : }
68 UIC 0 : else if (info == XLOG_INVALIDATIONS)
69 ECB : {
70 UIC 0 : xl_invalidations *xlrec = (xl_invalidations *) rec;
71 ECB :
72 UIC 0 : standby_desc_invalidations(buf, xlrec->nmsgs, xlrec->msgs,
73 ECB : xlrec->dbId, xlrec->tsId,
74 UIC 0 : xlrec->relcacheInitFileInval);
75 EUB : }
76 GIC 6 : }
77 EUB :
78 : const char *
79 GBC 6 : standby_identify(uint8 info)
80 : {
81 6 : const char *id = NULL;
82 :
83 CBC 6 : switch (info & ~XLR_INFO_MASK)
84 : {
85 GIC 2 : case XLOG_STANDBY_LOCK:
86 CBC 2 : id = "LOCK";
87 GIC 2 : break;
88 CBC 4 : case XLOG_RUNNING_XACTS:
89 GIC 4 : id = "RUNNING_XACTS";
90 CBC 4 : break;
91 UIC 0 : case XLOG_INVALIDATIONS:
92 LBC 0 : id = "INVALIDATIONS";
93 0 : break;
94 ECB : }
95 :
96 CBC 6 : return id;
97 ECB : }
98 EUB :
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 ECB : */
104 : void
105 GIC 28 : standby_desc_invalidations(StringInfo buf,
106 : int nmsgs, SharedInvalidationMessage *msgs,
107 : Oid dbId, Oid tsId,
108 : bool relcacheInitFileInval)
109 : {
110 : int i;
111 :
112 ECB : /* Do nothing if there are no invalidation messages */
113 GIC 28 : if (nmsgs <= 0)
114 7 : return;
115 :
116 21 : if (relcacheInitFileInval)
117 2 : appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u",
118 : dbId, tsId);
119 :
120 CBC 21 : appendStringInfoString(buf, "; inval msgs:");
121 573 : for (i = 0; i < nmsgs; i++)
122 : {
123 552 : SharedInvalidationMessage *msg = &msgs[i];
124 ECB :
125 GIC 552 : if (msg->id >= 0)
126 464 : appendStringInfo(buf, " catcache %d", msg->id);
127 CBC 88 : else if (msg->id == SHAREDINVALCATALOG_ID)
128 1 : appendStringInfo(buf, " catalog %u", msg->cat.catId);
129 GIC 87 : else if (msg->id == SHAREDINVALRELCACHE_ID)
130 CBC 53 : appendStringInfo(buf, " relcache %u", msg->rc.relId);
131 : /* not expected, but print something anyway */
132 34 : else if (msg->id == SHAREDINVALSMGR_ID)
133 LBC 0 : appendStringInfoString(buf, " smgr");
134 ECB : /* not expected, but print something anyway */
135 CBC 34 : else if (msg->id == SHAREDINVALRELMAP_ID)
136 LBC 0 : appendStringInfo(buf, " relmap db %u", msg->rm.dbId);
137 CBC 34 : else if (msg->id == SHAREDINVALSNAPSHOT_ID)
138 GIC 34 : appendStringInfo(buf, " snapshot %u", msg->sn.relId);
139 ECB : else
140 UBC 0 : appendStringInfo(buf, " unrecognized id %d", msg->id);
141 : }
142 ECB : }
|