@@ -209,43 +209,95 @@ ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
209
209
}
210
210
}
211
211
212
- static void
213
- xact_desc_commit (StringInfo buf , uint8 info , xl_xact_commit * xlrec , RepOriginId origin_id )
212
+ /*
213
+ * ParsePrepareRecord
214
+ */
215
+ void
216
+ ParsePrepareRecord (uint8 info , xl_xact_prepare * xlrec , xl_xact_parsed_prepare * parsed )
214
217
{
215
- xl_xact_parsed_commit parsed ;
216
- int i ;
218
+ char * bufptr ;
217
219
218
- ParseCommitRecord ( info , xlrec , & parsed );
220
+ bufptr = (( char * ) xlrec ) + MAXALIGN ( sizeof ( xl_xact_prepare ) );
219
221
220
- /* If this is a prepared xact, show the xid of the original xact */
221
- if (TransactionIdIsValid (parsed .twophase_xid ))
222
- appendStringInfo (buf , "%u: " , parsed .twophase_xid );
222
+ memset (parsed , 0 , sizeof (* parsed ));
223
223
224
- appendStringInfoString (buf , timestamptz_to_str (xlrec -> xact_time ));
224
+ parsed -> xact_time = xlrec -> prepared_at ;
225
+ parsed -> origin_lsn = xlrec -> origin_lsn ;
226
+ parsed -> origin_timestamp = xlrec -> origin_timestamp ;
227
+ parsed -> twophase_xid = xlrec -> xid ;
228
+ parsed -> dbId = xlrec -> database ;
229
+ parsed -> nsubxacts = xlrec -> nsubxacts ;
230
+ parsed -> nrels = xlrec -> ncommitrels ;
231
+ parsed -> nabortrels = xlrec -> nabortrels ;
232
+ parsed -> nmsgs = xlrec -> ninvalmsgs ;
233
+
234
+ strncpy (parsed -> twophase_gid , bufptr , xlrec -> gidlen );
235
+ bufptr += MAXALIGN (xlrec -> gidlen );
236
+
237
+ parsed -> subxacts = (TransactionId * ) bufptr ;
238
+ bufptr += MAXALIGN (xlrec -> nsubxacts * sizeof (TransactionId ));
239
+
240
+ parsed -> xnodes = (RelFileNode * ) bufptr ;
241
+ bufptr += MAXALIGN (xlrec -> ncommitrels * sizeof (RelFileNode ));
242
+
243
+ parsed -> abortnodes = (RelFileNode * ) bufptr ;
244
+ bufptr += MAXALIGN (xlrec -> nabortrels * sizeof (RelFileNode ));
225
245
226
- if (parsed .nrels > 0 )
246
+ parsed -> msgs = (SharedInvalidationMessage * ) bufptr ;
247
+ bufptr += MAXALIGN (xlrec -> ninvalmsgs * sizeof (SharedInvalidationMessage ));
248
+ }
249
+
250
+ static void
251
+ xact_desc_relations (StringInfo buf , char * label , int nrels ,
252
+ RelFileNode * xnodes )
253
+ {
254
+ int i ;
255
+
256
+ if (nrels > 0 )
227
257
{
228
- appendStringInfoString (buf , "; rels:" );
229
- for (i = 0 ; i < parsed . nrels ; i ++ )
258
+ appendStringInfo (buf , "; %s:" , label );
259
+ for (i = 0 ; i < nrels ; i ++ )
230
260
{
231
- char * path = relpathperm (parsed . xnodes [i ], MAIN_FORKNUM );
261
+ char * path = relpathperm (xnodes [i ], MAIN_FORKNUM );
232
262
233
263
appendStringInfo (buf , " %s" , path );
234
264
pfree (path );
235
265
}
236
266
}
237
- if (parsed .nsubxacts > 0 )
267
+ }
268
+
269
+ static void
270
+ xact_desc_subxacts (StringInfo buf , int nsubxacts , TransactionId * subxacts )
271
+ {
272
+ int i ;
273
+
274
+ if (nsubxacts > 0 )
238
275
{
239
276
appendStringInfoString (buf , "; subxacts:" );
240
- for (i = 0 ; i < parsed .nsubxacts ; i ++ )
241
- appendStringInfo (buf , " %u" , parsed .subxacts [i ]);
242
- }
243
- if (parsed .nmsgs > 0 )
244
- {
245
- standby_desc_invalidations (
246
- buf , parsed .nmsgs , parsed .msgs , parsed .dbId , parsed .tsId ,
247
- XactCompletionRelcacheInitFileInval (parsed .xinfo ));
277
+ for (i = 0 ; i < nsubxacts ; i ++ )
278
+ appendStringInfo (buf , " %u" , subxacts [i ]);
248
279
}
280
+ }
281
+
282
+ static void
283
+ xact_desc_commit (StringInfo buf , uint8 info , xl_xact_commit * xlrec , RepOriginId origin_id )
284
+ {
285
+ xl_xact_parsed_commit parsed ;
286
+
287
+ ParseCommitRecord (info , xlrec , & parsed );
288
+
289
+ /* If this is a prepared xact, show the xid of the original xact */
290
+ if (TransactionIdIsValid (parsed .twophase_xid ))
291
+ appendStringInfo (buf , "%u: " , parsed .twophase_xid );
292
+
293
+ appendStringInfoString (buf , timestamptz_to_str (xlrec -> xact_time ));
294
+
295
+ xact_desc_relations (buf , "rels" , parsed .nrels , parsed .xnodes );
296
+ xact_desc_subxacts (buf , parsed .nsubxacts , parsed .subxacts );
297
+
298
+ standby_desc_invalidations (
299
+ buf , parsed .nmsgs , parsed .msgs , parsed .dbId , parsed .tsId ,
300
+ XactCompletionRelcacheInitFileInval (parsed .xinfo ));
249
301
250
302
if (XactCompletionForceSyncCommit (parsed .xinfo ))
251
303
appendStringInfoString (buf , "; sync" );
@@ -264,7 +316,6 @@ static void
264
316
xact_desc_abort (StringInfo buf , uint8 info , xl_xact_abort * xlrec )
265
317
{
266
318
xl_xact_parsed_abort parsed ;
267
- int i ;
268
319
269
320
ParseAbortRecord (info , xlrec , & parsed );
270
321
@@ -273,24 +324,29 @@ xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec)
273
324
appendStringInfo (buf , "%u: " , parsed .twophase_xid );
274
325
275
326
appendStringInfoString (buf , timestamptz_to_str (xlrec -> xact_time ));
276
- if (parsed .nrels > 0 )
277
- {
278
- appendStringInfoString (buf , "; rels:" );
279
- for (i = 0 ; i < parsed .nrels ; i ++ )
280
- {
281
- char * path = relpathperm (parsed .xnodes [i ], MAIN_FORKNUM );
282
327
283
- appendStringInfo (buf , " %s" , path );
284
- pfree (path );
285
- }
286
- }
328
+ xact_desc_relations (buf , "rels" , parsed .nrels , parsed .xnodes );
329
+ xact_desc_subxacts (buf , parsed .nsubxacts , parsed .subxacts );
330
+ }
287
331
288
- if (parsed .nsubxacts > 0 )
289
- {
290
- appendStringInfoString (buf , "; subxacts:" );
291
- for (i = 0 ; i < parsed .nsubxacts ; i ++ )
292
- appendStringInfo (buf , " %u" , parsed .subxacts [i ]);
293
- }
332
+ static void
333
+ xact_desc_prepare (StringInfo buf , uint8 info , xl_xact_prepare * xlrec )
334
+ {
335
+ xl_xact_parsed_prepare parsed ;
336
+
337
+ ParsePrepareRecord (info , xlrec , & parsed );
338
+
339
+ appendStringInfo (buf , "gid %s: " , parsed .twophase_gid );
340
+ appendStringInfoString (buf , timestamptz_to_str (parsed .xact_time ));
341
+
342
+ xact_desc_relations (buf , "rels(commit)" , parsed .nrels , parsed .xnodes );
343
+ xact_desc_relations (buf , "rels(abort)" , parsed .nabortrels ,
344
+ parsed .abortnodes );
345
+ xact_desc_subxacts (buf , parsed .nsubxacts , parsed .subxacts );
346
+
347
+ standby_desc_invalidations (
348
+ buf , parsed .nmsgs , parsed .msgs , parsed .dbId , parsed .tsId ,
349
+ xlrec -> initfileinval );
294
350
}
295
351
296
352
static void
@@ -323,6 +379,12 @@ xact_desc(StringInfo buf, XLogReaderState *record)
323
379
324
380
xact_desc_abort (buf , XLogRecGetInfo (record ), xlrec );
325
381
}
382
+ else if (info == XLOG_XACT_PREPARE )
383
+ {
384
+ xl_xact_prepare * xlrec = (xl_xact_prepare * ) rec ;
385
+
386
+ xact_desc_prepare (buf , XLogRecGetInfo (record ), xlrec );
387
+ }
326
388
else if (info == XLOG_XACT_ASSIGNMENT )
327
389
{
328
390
xl_xact_assignment * xlrec = (xl_xact_assignment * ) rec ;
0 commit comments