~ubuntu-branches/debian/sid/postgresql-9.3/sid

« back to all changes in this revision

Viewing changes to src/backend/access/rmgrdesc/xactdesc.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-05-08 05:39:52 UTC
  • Revision ID: package-import@ubuntu.com-20130508053952-1j7uilp7mjtrvq8q
Tags: upstream-9.3~beta1
ImportĀ upstreamĀ versionĀ 9.3~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * xactdesc.c
 
4
 *    rmgr descriptor routines for access/transam/xact.c
 
5
 *
 
6
 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
 
7
 * Portions Copyright (c) 1994, Regents of the University of California
 
8
 *
 
9
 *
 
10
 * IDENTIFICATION
 
11
 *    src/backend/access/rmgrdesc/xactdesc.c
 
12
 *
 
13
 *-------------------------------------------------------------------------
 
14
 */
 
15
#include "postgres.h"
 
16
 
 
17
#include "access/xact.h"
 
18
#include "catalog/catalog.h"
 
19
#include "common/relpath.h"
 
20
#include "storage/sinval.h"
 
21
#include "utils/timestamp.h"
 
22
 
 
23
 
 
24
static void
 
25
xact_desc_commit(StringInfo buf, xl_xact_commit *xlrec)
 
26
{
 
27
        int                     i;
 
28
        TransactionId *subxacts;
 
29
 
 
30
        subxacts = (TransactionId *) &xlrec->xnodes[xlrec->nrels];
 
31
 
 
32
        appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time));
 
33
 
 
34
        if (xlrec->nrels > 0)
 
35
        {
 
36
                appendStringInfo(buf, "; rels:");
 
37
                for (i = 0; i < xlrec->nrels; i++)
 
38
                {
 
39
                        char       *path = relpathperm(xlrec->xnodes[i], MAIN_FORKNUM);
 
40
 
 
41
                        appendStringInfo(buf, " %s", path);
 
42
                        pfree(path);
 
43
                }
 
44
        }
 
45
        if (xlrec->nsubxacts > 0)
 
46
        {
 
47
                appendStringInfo(buf, "; subxacts:");
 
48
                for (i = 0; i < xlrec->nsubxacts; i++)
 
49
                        appendStringInfo(buf, " %u", subxacts[i]);
 
50
        }
 
51
        if (xlrec->nmsgs > 0)
 
52
        {
 
53
                SharedInvalidationMessage *msgs;
 
54
 
 
55
                msgs = (SharedInvalidationMessage *) &subxacts[xlrec->nsubxacts];
 
56
 
 
57
                if (XactCompletionRelcacheInitFileInval(xlrec->xinfo))
 
58
                        appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u",
 
59
                                                         xlrec->dbId, xlrec->tsId);
 
60
 
 
61
                appendStringInfo(buf, "; inval msgs:");
 
62
                for (i = 0; i < xlrec->nmsgs; i++)
 
63
                {
 
64
                        SharedInvalidationMessage *msg = &msgs[i];
 
65
 
 
66
                        if (msg->id >= 0)
 
67
                                appendStringInfo(buf, " catcache %d", msg->id);
 
68
                        else if (msg->id == SHAREDINVALCATALOG_ID)
 
69
                                appendStringInfo(buf, " catalog %u", msg->cat.catId);
 
70
                        else if (msg->id == SHAREDINVALRELCACHE_ID)
 
71
                                appendStringInfo(buf, " relcache %u", msg->rc.relId);
 
72
                        /* remaining cases not expected, but print something anyway */
 
73
                        else if (msg->id == SHAREDINVALSMGR_ID)
 
74
                                appendStringInfo(buf, " smgr");
 
75
                        else if (msg->id == SHAREDINVALRELMAP_ID)
 
76
                                appendStringInfo(buf, " relmap");
 
77
                        else
 
78
                                appendStringInfo(buf, " unknown id %d", msg->id);
 
79
                }
 
80
        }
 
81
}
 
82
 
 
83
static void
 
84
xact_desc_commit_compact(StringInfo buf, xl_xact_commit_compact *xlrec)
 
85
{
 
86
        int                     i;
 
87
 
 
88
        appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time));
 
89
 
 
90
        if (xlrec->nsubxacts > 0)
 
91
        {
 
92
                appendStringInfo(buf, "; subxacts:");
 
93
                for (i = 0; i < xlrec->nsubxacts; i++)
 
94
                        appendStringInfo(buf, " %u", xlrec->subxacts[i]);
 
95
        }
 
96
}
 
97
 
 
98
static void
 
99
xact_desc_abort(StringInfo buf, xl_xact_abort *xlrec)
 
100
{
 
101
        int                     i;
 
102
 
 
103
        appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time));
 
104
        if (xlrec->nrels > 0)
 
105
        {
 
106
                appendStringInfo(buf, "; rels:");
 
107
                for (i = 0; i < xlrec->nrels; i++)
 
108
                {
 
109
                        char       *path = relpathperm(xlrec->xnodes[i], MAIN_FORKNUM);
 
110
 
 
111
                        appendStringInfo(buf, " %s", path);
 
112
                        pfree(path);
 
113
                }
 
114
        }
 
115
        if (xlrec->nsubxacts > 0)
 
116
        {
 
117
                TransactionId *xacts = (TransactionId *)
 
118
                &xlrec->xnodes[xlrec->nrels];
 
119
 
 
120
                appendStringInfo(buf, "; subxacts:");
 
121
                for (i = 0; i < xlrec->nsubxacts; i++)
 
122
                        appendStringInfo(buf, " %u", xacts[i]);
 
123
        }
 
124
}
 
125
 
 
126
static void
 
127
xact_desc_assignment(StringInfo buf, xl_xact_assignment *xlrec)
 
128
{
 
129
        int                     i;
 
130
 
 
131
        appendStringInfo(buf, "subxacts:");
 
132
 
 
133
        for (i = 0; i < xlrec->nsubxacts; i++)
 
134
                appendStringInfo(buf, " %u", xlrec->xsub[i]);
 
135
}
 
136
 
 
137
void
 
138
xact_desc(StringInfo buf, uint8 xl_info, char *rec)
 
139
{
 
140
        uint8           info = xl_info & ~XLR_INFO_MASK;
 
141
 
 
142
        if (info == XLOG_XACT_COMMIT_COMPACT)
 
143
        {
 
144
                xl_xact_commit_compact *xlrec = (xl_xact_commit_compact *) rec;
 
145
 
 
146
                appendStringInfo(buf, "commit: ");
 
147
                xact_desc_commit_compact(buf, xlrec);
 
148
        }
 
149
        else if (info == XLOG_XACT_COMMIT)
 
150
        {
 
151
                xl_xact_commit *xlrec = (xl_xact_commit *) rec;
 
152
 
 
153
                appendStringInfo(buf, "commit: ");
 
154
                xact_desc_commit(buf, xlrec);
 
155
        }
 
156
        else if (info == XLOG_XACT_ABORT)
 
157
        {
 
158
                xl_xact_abort *xlrec = (xl_xact_abort *) rec;
 
159
 
 
160
                appendStringInfo(buf, "abort: ");
 
161
                xact_desc_abort(buf, xlrec);
 
162
        }
 
163
        else if (info == XLOG_XACT_PREPARE)
 
164
        {
 
165
                appendStringInfo(buf, "prepare");
 
166
        }
 
167
        else if (info == XLOG_XACT_COMMIT_PREPARED)
 
168
        {
 
169
                xl_xact_commit_prepared *xlrec = (xl_xact_commit_prepared *) rec;
 
170
 
 
171
                appendStringInfo(buf, "commit prepared %u: ", xlrec->xid);
 
172
                xact_desc_commit(buf, &xlrec->crec);
 
173
        }
 
174
        else if (info == XLOG_XACT_ABORT_PREPARED)
 
175
        {
 
176
                xl_xact_abort_prepared *xlrec = (xl_xact_abort_prepared *) rec;
 
177
 
 
178
                appendStringInfo(buf, "abort prepared %u: ", xlrec->xid);
 
179
                xact_desc_abort(buf, &xlrec->arec);
 
180
        }
 
181
        else if (info == XLOG_XACT_ASSIGNMENT)
 
182
        {
 
183
                xl_xact_assignment *xlrec = (xl_xact_assignment *) rec;
 
184
 
 
185
                /*
 
186
                 * Note that we ignore the WAL record's xid, since we're more
 
187
                 * interested in the top-level xid that issued the record and which
 
188
                 * xids are being reported here.
 
189
                 */
 
190
                appendStringInfo(buf, "xid assignment xtop %u: ", xlrec->xtop);
 
191
                xact_desc_assignment(buf, xlrec);
 
192
        }
 
193
        else
 
194
                appendStringInfo(buf, "UNKNOWN");
 
195
}