00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "postgres.h"
00016
00017 #include "access/xact.h"
00018 #include "catalog/catalog.h"
00019 #include "common/relpath.h"
00020 #include "storage/sinval.h"
00021 #include "utils/timestamp.h"
00022
00023
00024 static void
00025 xact_desc_commit(StringInfo buf, xl_xact_commit *xlrec)
00026 {
00027 int i;
00028 TransactionId *subxacts;
00029
00030 subxacts = (TransactionId *) &xlrec->xnodes[xlrec->nrels];
00031
00032 appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time));
00033
00034 if (xlrec->nrels > 0)
00035 {
00036 appendStringInfo(buf, "; rels:");
00037 for (i = 0; i < xlrec->nrels; i++)
00038 {
00039 char *path = relpathperm(xlrec->xnodes[i], MAIN_FORKNUM);
00040
00041 appendStringInfo(buf, " %s", path);
00042 pfree(path);
00043 }
00044 }
00045 if (xlrec->nsubxacts > 0)
00046 {
00047 appendStringInfo(buf, "; subxacts:");
00048 for (i = 0; i < xlrec->nsubxacts; i++)
00049 appendStringInfo(buf, " %u", subxacts[i]);
00050 }
00051 if (xlrec->nmsgs > 0)
00052 {
00053 SharedInvalidationMessage *msgs;
00054
00055 msgs = (SharedInvalidationMessage *) &subxacts[xlrec->nsubxacts];
00056
00057 if (XactCompletionRelcacheInitFileInval(xlrec->xinfo))
00058 appendStringInfo(buf, "; relcache init file inval dbid %u tsid %u",
00059 xlrec->dbId, xlrec->tsId);
00060
00061 appendStringInfo(buf, "; inval msgs:");
00062 for (i = 0; i < xlrec->nmsgs; i++)
00063 {
00064 SharedInvalidationMessage *msg = &msgs[i];
00065
00066 if (msg->id >= 0)
00067 appendStringInfo(buf, " catcache %d", msg->id);
00068 else if (msg->id == SHAREDINVALCATALOG_ID)
00069 appendStringInfo(buf, " catalog %u", msg->cat.catId);
00070 else if (msg->id == SHAREDINVALRELCACHE_ID)
00071 appendStringInfo(buf, " relcache %u", msg->rc.relId);
00072
00073 else if (msg->id == SHAREDINVALSMGR_ID)
00074 appendStringInfo(buf, " smgr");
00075 else if (msg->id == SHAREDINVALRELMAP_ID)
00076 appendStringInfo(buf, " relmap");
00077 else
00078 appendStringInfo(buf, " unknown id %d", msg->id);
00079 }
00080 }
00081 }
00082
00083 static void
00084 xact_desc_commit_compact(StringInfo buf, xl_xact_commit_compact *xlrec)
00085 {
00086 int i;
00087
00088 appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time));
00089
00090 if (xlrec->nsubxacts > 0)
00091 {
00092 appendStringInfo(buf, "; subxacts:");
00093 for (i = 0; i < xlrec->nsubxacts; i++)
00094 appendStringInfo(buf, " %u", xlrec->subxacts[i]);
00095 }
00096 }
00097
00098 static void
00099 xact_desc_abort(StringInfo buf, xl_xact_abort *xlrec)
00100 {
00101 int i;
00102
00103 appendStringInfoString(buf, timestamptz_to_str(xlrec->xact_time));
00104 if (xlrec->nrels > 0)
00105 {
00106 appendStringInfo(buf, "; rels:");
00107 for (i = 0; i < xlrec->nrels; i++)
00108 {
00109 char *path = relpathperm(xlrec->xnodes[i], MAIN_FORKNUM);
00110
00111 appendStringInfo(buf, " %s", path);
00112 pfree(path);
00113 }
00114 }
00115 if (xlrec->nsubxacts > 0)
00116 {
00117 TransactionId *xacts = (TransactionId *)
00118 &xlrec->xnodes[xlrec->nrels];
00119
00120 appendStringInfo(buf, "; subxacts:");
00121 for (i = 0; i < xlrec->nsubxacts; i++)
00122 appendStringInfo(buf, " %u", xacts[i]);
00123 }
00124 }
00125
00126 static void
00127 xact_desc_assignment(StringInfo buf, xl_xact_assignment *xlrec)
00128 {
00129 int i;
00130
00131 appendStringInfo(buf, "subxacts:");
00132
00133 for (i = 0; i < xlrec->nsubxacts; i++)
00134 appendStringInfo(buf, " %u", xlrec->xsub[i]);
00135 }
00136
00137 void
00138 xact_desc(StringInfo buf, uint8 xl_info, char *rec)
00139 {
00140 uint8 info = xl_info & ~XLR_INFO_MASK;
00141
00142 if (info == XLOG_XACT_COMMIT_COMPACT)
00143 {
00144 xl_xact_commit_compact *xlrec = (xl_xact_commit_compact *) rec;
00145
00146 appendStringInfo(buf, "commit: ");
00147 xact_desc_commit_compact(buf, xlrec);
00148 }
00149 else if (info == XLOG_XACT_COMMIT)
00150 {
00151 xl_xact_commit *xlrec = (xl_xact_commit *) rec;
00152
00153 appendStringInfo(buf, "commit: ");
00154 xact_desc_commit(buf, xlrec);
00155 }
00156 else if (info == XLOG_XACT_ABORT)
00157 {
00158 xl_xact_abort *xlrec = (xl_xact_abort *) rec;
00159
00160 appendStringInfo(buf, "abort: ");
00161 xact_desc_abort(buf, xlrec);
00162 }
00163 else if (info == XLOG_XACT_PREPARE)
00164 {
00165 appendStringInfo(buf, "prepare");
00166 }
00167 else if (info == XLOG_XACT_COMMIT_PREPARED)
00168 {
00169 xl_xact_commit_prepared *xlrec = (xl_xact_commit_prepared *) rec;
00170
00171 appendStringInfo(buf, "commit prepared %u: ", xlrec->xid);
00172 xact_desc_commit(buf, &xlrec->crec);
00173 }
00174 else if (info == XLOG_XACT_ABORT_PREPARED)
00175 {
00176 xl_xact_abort_prepared *xlrec = (xl_xact_abort_prepared *) rec;
00177
00178 appendStringInfo(buf, "abort prepared %u: ", xlrec->xid);
00179 xact_desc_abort(buf, &xlrec->arec);
00180 }
00181 else if (info == XLOG_XACT_ASSIGNMENT)
00182 {
00183 xl_xact_assignment *xlrec = (xl_xact_assignment *) rec;
00184
00185
00186
00187
00188
00189
00190 appendStringInfo(buf, "xid assignment xtop %u: ", xlrec->xtop);
00191 xact_desc_assignment(buf, xlrec);
00192 }
00193 else
00194 appendStringInfo(buf, "UNKNOWN");
00195 }