PostgreSQL Source Code  git master
decode.c
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  *
3  * decode.c
4  * This module decodes WAL records read using xlogreader.h's APIs for the
5  * purpose of logical decoding by passing information to the
6  * reorderbuffer module (containing the actual changes) and to the
7  * snapbuild module to build a fitting catalog snapshot (to be able to
8  * properly decode the changes in the reorderbuffer).
9  *
10  * NOTE:
11  * This basically tries to handle all low level xlog stuff for
12  * reorderbuffer.c and snapbuild.c. There's some minor leakage where a
13  * specific record's struct is used to pass data along, but those just
14  * happen to contain the right amount of data in a convenient
15  * format. There isn't and shouldn't be much intelligence about the
16  * contents of records in here except turning them into a more usable
17  * format.
18  *
19  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
20  * Portions Copyright (c) 1994, Regents of the University of California
21  *
22  * IDENTIFICATION
23  * src/backend/replication/logical/decode.c
24  *
25  * -------------------------------------------------------------------------
26  */
27 #include "postgres.h"
28 
29 #include "access/heapam.h"
30 #include "access/heapam_xlog.h"
31 #include "access/transam.h"
32 #include "access/xact.h"
33 #include "access/xlog_internal.h"
34 #include "access/xlogreader.h"
35 #include "access/xlogrecord.h"
36 #include "access/xlogutils.h"
37 #include "catalog/pg_control.h"
38 #include "replication/decode.h"
39 #include "replication/logical.h"
40 #include "replication/message.h"
41 #include "replication/origin.h"
43 #include "replication/snapbuild.h"
44 #include "storage/standby.h"
45 
46 /* individual record(group)'s handlers */
53 
56  bool two_phase);
59  bool two_phase);
61  xl_xact_parsed_prepare *parsed);
62 
63 
64 /* common function to decode tuples */
65 static void DecodeXLogTuple(char *data, Size len, ReorderBufferTupleBuf *tuple);
66 
67 /* helper functions for decoding transactions */
68 static inline bool FilterPrepare(LogicalDecodingContext *ctx,
69  TransactionId xid, const char *gid);
71  XLogRecordBuffer *buf, Oid txn_dbid,
72  RepOriginId origin_id);
73 
74 /*
75  * Take every XLogReadRecord()ed record and perform the actions required to
76  * decode it using the output plugin already setup in the logical decoding
77  * context.
78  *
79  * NB: Note that every record's xid needs to be processed by reorderbuffer
80  * (xids contained in the content of records are not relevant for this rule).
81  * That means that for records which'd otherwise not go through the
82  * reorderbuffer ReorderBufferProcessXid() has to be called. We don't want to
83  * call ReorderBufferProcessXid for each record type by default, because
84  * e.g. empty xacts can be handled more efficiently if there's no previous
85  * state for them.
86  *
87  * We also support the ability to fast forward thru records, skipping some
88  * record types completely - see individual record types for details.
89  */
90 void
92 {
94  TransactionId txid;
95  RmgrData rmgr;
96 
97  buf.origptr = ctx->reader->ReadRecPtr;
98  buf.endptr = ctx->reader->EndRecPtr;
99  buf.record = record;
100 
101  txid = XLogRecGetTopXid(record);
102 
103  /*
104  * If the top-level xid is valid, we need to assign the subxact to the
105  * top-level xact. We need to do this for all records, hence we do it
106  * before the switch.
107  */
108  if (TransactionIdIsValid(txid))
109  {
111  txid,
112  XLogRecGetXid(record),
113  buf.origptr);
114  }
115 
116  rmgr = GetRmgr(XLogRecGetRmid(record));
117 
118  if (rmgr.rm_decode != NULL)
119  rmgr.rm_decode(ctx, &buf);
120  else
121  {
122  /* just deal with xid, and done */
124  buf.origptr);
125  }
126 }
127 
128 /*
129  * Handle rmgr XLOG_ID records for LogicalDecodingProcessRecord().
130  */
131 void
133 {
134  SnapBuild *builder = ctx->snapshot_builder;
135  uint8 info = XLogRecGetInfo(buf->record) & ~XLR_INFO_MASK;
136 
138  buf->origptr);
139 
140  switch (info)
141  {
142  /* this is also used in END_OF_RECOVERY checkpoints */
145  SnapBuildSerializationPoint(builder, buf->origptr);
146 
147  break;
149 
150  /*
151  * a RUNNING_XACTS record will have been logged near to this, we
152  * can restart from there.
153  */
154  break;
156  {
157  xl_parameter_change *xlrec =
159 
160  /*
161  * If wal_level on the primary is reduced to less than
162  * logical, we want to prevent existing logical slots from
163  * being used. Existing logical slots on the standby get
164  * invalidated when this WAL record is replayed; and further,
165  * slot creation fails when wal_level is not sufficient; but
166  * all these operations are not synchronized, so a logical
167  * slot may creep in while the wal_level is being reduced.
168  * Hence this extra check.
169  */
170  if (xlrec->wal_level < WAL_LEVEL_LOGICAL)
171  {
172  /*
173  * This can occur only on a standby, as a primary would
174  * not allow to restart after changing wal_level < logical
175  * if there is pre-existing logical slot.
176  */
178  ereport(ERROR,
179  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
180  errmsg("logical decoding on standby requires wal_level >= logical on the primary")));
181  }
182  break;
183  }
184  case XLOG_NOOP:
185  case XLOG_NEXTOID:
186  case XLOG_SWITCH:
187  case XLOG_BACKUP_END:
188  case XLOG_RESTORE_POINT:
189  case XLOG_FPW_CHANGE:
190  case XLOG_FPI_FOR_HINT:
191  case XLOG_FPI:
193  break;
194  default:
195  elog(ERROR, "unexpected RM_XLOG_ID record type: %u", info);
196  }
197 }
198 
199 /*
200  * Handle rmgr XACT_ID records for LogicalDecodingProcessRecord().
201  */
202 void
204 {
205  SnapBuild *builder = ctx->snapshot_builder;
206  ReorderBuffer *reorder = ctx->reorder;
207  XLogReaderState *r = buf->record;
209 
210  /*
211  * If the snapshot isn't yet fully built, we cannot decode anything, so
212  * bail out.
213  */
215  return;
216 
217  switch (info)
218  {
219  case XLOG_XACT_COMMIT:
221  {
222  xl_xact_commit *xlrec;
223  xl_xact_parsed_commit parsed;
224  TransactionId xid;
225  bool two_phase = false;
226 
227  xlrec = (xl_xact_commit *) XLogRecGetData(r);
228  ParseCommitRecord(XLogRecGetInfo(buf->record), xlrec, &parsed);
229 
230  if (!TransactionIdIsValid(parsed.twophase_xid))
231  xid = XLogRecGetXid(r);
232  else
233  xid = parsed.twophase_xid;
234 
235  /*
236  * We would like to process the transaction in a two-phase
237  * manner iff output plugin supports two-phase commits and
238  * doesn't filter the transaction at prepare time.
239  */
240  if (info == XLOG_XACT_COMMIT_PREPARED)
241  two_phase = !(FilterPrepare(ctx, xid,
242  parsed.twophase_gid));
243 
244  DecodeCommit(ctx, buf, &parsed, xid, two_phase);
245  break;
246  }
247  case XLOG_XACT_ABORT:
249  {
250  xl_xact_abort *xlrec;
251  xl_xact_parsed_abort parsed;
252  TransactionId xid;
253  bool two_phase = false;
254 
255  xlrec = (xl_xact_abort *) XLogRecGetData(r);
256  ParseAbortRecord(XLogRecGetInfo(buf->record), xlrec, &parsed);
257 
258  if (!TransactionIdIsValid(parsed.twophase_xid))
259  xid = XLogRecGetXid(r);
260  else
261  xid = parsed.twophase_xid;
262 
263  /*
264  * We would like to process the transaction in a two-phase
265  * manner iff output plugin supports two-phase commits and
266  * doesn't filter the transaction at prepare time.
267  */
268  if (info == XLOG_XACT_ABORT_PREPARED)
269  two_phase = !(FilterPrepare(ctx, xid,
270  parsed.twophase_gid));
271 
272  DecodeAbort(ctx, buf, &parsed, xid, two_phase);
273  break;
274  }
276 
277  /*
278  * We assign subxact to the toplevel xact while processing each
279  * record if required. So, we don't need to do anything here. See
280  * LogicalDecodingProcessRecord.
281  */
282  break;
284  {
285  TransactionId xid;
286  xl_xact_invals *invals;
287 
288  xid = XLogRecGetXid(r);
289  invals = (xl_xact_invals *) XLogRecGetData(r);
290 
291  /*
292  * Execute the invalidations for xid-less transactions,
293  * otherwise, accumulate them so that they can be processed at
294  * the commit time.
295  */
296  if (TransactionIdIsValid(xid))
297  {
298  if (!ctx->fast_forward)
299  ReorderBufferAddInvalidations(reorder, xid,
300  buf->origptr,
301  invals->nmsgs,
302  invals->msgs);
304  buf->origptr);
305  }
306  else if ((!ctx->fast_forward))
308  invals->nmsgs,
309  invals->msgs);
310  }
311  break;
312  case XLOG_XACT_PREPARE:
313  {
314  xl_xact_parsed_prepare parsed;
315  xl_xact_prepare *xlrec;
316 
317  /* ok, parse it */
318  xlrec = (xl_xact_prepare *) XLogRecGetData(r);
320  xlrec, &parsed);
321 
322  /*
323  * We would like to process the transaction in a two-phase
324  * manner iff output plugin supports two-phase commits and
325  * doesn't filter the transaction at prepare time.
326  */
327  if (FilterPrepare(ctx, parsed.twophase_xid,
328  parsed.twophase_gid))
329  {
330  ReorderBufferProcessXid(reorder, parsed.twophase_xid,
331  buf->origptr);
332  break;
333  }
334 
335  /*
336  * Note that if the prepared transaction has locked [user]
337  * catalog tables exclusively then decoding prepare can block
338  * till the main transaction is committed because it needs to
339  * lock the catalog tables.
340  *
341  * XXX Now, this can even lead to a deadlock if the prepare
342  * transaction is waiting to get it logically replicated for
343  * distributed 2PC. This can be avoided by disallowing
344  * preparing transactions that have locked [user] catalog
345  * tables exclusively but as of now, we ask users not to do
346  * such an operation.
347  */
348  DecodePrepare(ctx, buf, &parsed);
349  break;
350  }
351  default:
352  elog(ERROR, "unexpected RM_XACT_ID record type: %u", info);
353  }
354 }
355 
356 /*
357  * Handle rmgr STANDBY_ID records for LogicalDecodingProcessRecord().
358  */
359 void
361 {
362  SnapBuild *builder = ctx->snapshot_builder;
363  XLogReaderState *r = buf->record;
364  uint8 info = XLogRecGetInfo(r) & ~XLR_INFO_MASK;
365 
366  ReorderBufferProcessXid(ctx->reorder, XLogRecGetXid(r), buf->origptr);
367 
368  switch (info)
369  {
370  case XLOG_RUNNING_XACTS:
371  {
373 
374  SnapBuildProcessRunningXacts(builder, buf->origptr, running);
375 
376  /*
377  * Abort all transactions that we keep track of, that are
378  * older than the record's oldestRunningXid. This is the most
379  * convenient spot for doing so since, in contrast to shutdown
380  * or end-of-recovery checkpoints, we have information about
381  * all running transactions which includes prepared ones,
382  * while shutdown checkpoints just know that no non-prepared
383  * transactions are in progress.
384  */
386  }
387  break;
388  case XLOG_STANDBY_LOCK:
389  break;
390  case XLOG_INVALIDATIONS:
391 
392  /*
393  * We are processing the invalidations at the command level via
394  * XLOG_XACT_INVALIDATIONS. So we don't need to do anything here.
395  */
396  break;
397  default:
398  elog(ERROR, "unexpected RM_STANDBY_ID record type: %u", info);
399  }
400 }
401 
402 /*
403  * Handle rmgr HEAP2_ID records for LogicalDecodingProcessRecord().
404  */
405 void
407 {
408  uint8 info = XLogRecGetInfo(buf->record) & XLOG_HEAP_OPMASK;
409  TransactionId xid = XLogRecGetXid(buf->record);
410  SnapBuild *builder = ctx->snapshot_builder;
411 
412  ReorderBufferProcessXid(ctx->reorder, xid, buf->origptr);
413 
414  /*
415  * If we don't have snapshot or we are just fast-forwarding, there is no
416  * point in decoding changes.
417  */
419  ctx->fast_forward)
420  return;
421 
422  switch (info)
423  {
425  if (SnapBuildProcessChange(builder, xid, buf->origptr))
426  DecodeMultiInsert(ctx, buf);
427  break;
428  case XLOG_HEAP2_NEW_CID:
429  {
430  xl_heap_new_cid *xlrec;
431 
432  xlrec = (xl_heap_new_cid *) XLogRecGetData(buf->record);
433  SnapBuildProcessNewCid(builder, xid, buf->origptr, xlrec);
434 
435  break;
436  }
437  case XLOG_HEAP2_REWRITE:
438 
439  /*
440  * Although these records only exist to serve the needs of logical
441  * decoding, all the work happens as part of crash or archive
442  * recovery, so we don't need to do anything here.
443  */
444  break;
445 
446  /*
447  * Everything else here is just low level physical stuff we're not
448  * interested in.
449  */
451  case XLOG_HEAP2_PRUNE:
452  case XLOG_HEAP2_VACUUM:
453  case XLOG_HEAP2_VISIBLE:
455  break;
456  default:
457  elog(ERROR, "unexpected RM_HEAP2_ID record type: %u", info);
458  }
459 }
460 
461 /*
462  * Handle rmgr HEAP_ID records for LogicalDecodingProcessRecord().
463  */
464 void
466 {
467  uint8 info = XLogRecGetInfo(buf->record) & XLOG_HEAP_OPMASK;
468  TransactionId xid = XLogRecGetXid(buf->record);
469  SnapBuild *builder = ctx->snapshot_builder;
470 
471  ReorderBufferProcessXid(ctx->reorder, xid, buf->origptr);
472 
473  /*
474  * If we don't have snapshot or we are just fast-forwarding, there is no
475  * point in decoding data changes.
476  */
478  ctx->fast_forward)
479  return;
480 
481  switch (info)
482  {
483  case XLOG_HEAP_INSERT:
484  if (SnapBuildProcessChange(builder, xid, buf->origptr))
485  DecodeInsert(ctx, buf);
486  break;
487 
488  /*
489  * Treat HOT update as normal updates. There is no useful
490  * information in the fact that we could make it a HOT update
491  * locally and the WAL layout is compatible.
492  */
494  case XLOG_HEAP_UPDATE:
495  if (SnapBuildProcessChange(builder, xid, buf->origptr))
496  DecodeUpdate(ctx, buf);
497  break;
498 
499  case XLOG_HEAP_DELETE:
500  if (SnapBuildProcessChange(builder, xid, buf->origptr))
501  DecodeDelete(ctx, buf);
502  break;
503 
504  case XLOG_HEAP_TRUNCATE:
505  if (SnapBuildProcessChange(builder, xid, buf->origptr))
506  DecodeTruncate(ctx, buf);
507  break;
508 
509  case XLOG_HEAP_INPLACE:
510 
511  /*
512  * Inplace updates are only ever performed on catalog tuples and
513  * can, per definition, not change tuple visibility. Since we
514  * don't decode catalog tuples, we're not interested in the
515  * record's contents.
516  *
517  * In-place updates can be used either by XID-bearing transactions
518  * (e.g. in CREATE INDEX CONCURRENTLY) or by XID-less
519  * transactions (e.g. VACUUM). In the former case, the commit
520  * record will include cache invalidations, so we mark the
521  * transaction as catalog modifying here. Currently that's
522  * redundant because the commit will do that as well, but once we
523  * support decoding in-progress relations, this will be important.
524  */
525  if (!TransactionIdIsValid(xid))
526  break;
527 
528  (void) SnapBuildProcessChange(builder, xid, buf->origptr);
529  ReorderBufferXidSetCatalogChanges(ctx->reorder, xid, buf->origptr);
530  break;
531 
532  case XLOG_HEAP_CONFIRM:
533  if (SnapBuildProcessChange(builder, xid, buf->origptr))
534  DecodeSpecConfirm(ctx, buf);
535  break;
536 
537  case XLOG_HEAP_LOCK:
538  /* we don't care about row level locks for now */
539  break;
540 
541  default:
542  elog(ERROR, "unexpected RM_HEAP_ID record type: %u", info);
543  break;
544  }
545 }
546 
547 /*
548  * Ask output plugin whether we want to skip this PREPARE and send
549  * this transaction as a regular commit later.
550  */
551 static inline bool
553  const char *gid)
554 {
555  /*
556  * Skip if decoding of two-phase transactions at PREPARE time is not
557  * enabled. In that case, all two-phase transactions are considered
558  * filtered out and will be applied as regular transactions at COMMIT
559  * PREPARED.
560  */
561  if (!ctx->twophase)
562  return true;
563 
564  /*
565  * The filter_prepare callback is optional. When not supplied, all
566  * prepared transactions should go through.
567  */
568  if (ctx->callbacks.filter_prepare_cb == NULL)
569  return false;
570 
571  return filter_prepare_cb_wrapper(ctx, xid, gid);
572 }
573 
574 static inline bool
576 {
577  if (ctx->callbacks.filter_by_origin_cb == NULL)
578  return false;
579 
580  return filter_by_origin_cb_wrapper(ctx, origin_id);
581 }
582 
583 /*
584  * Handle rmgr LOGICALMSG_ID records for LogicalDecodingProcessRecord().
585  */
586 void
588 {
589  SnapBuild *builder = ctx->snapshot_builder;
590  XLogReaderState *r = buf->record;
591  TransactionId xid = XLogRecGetXid(r);
592  uint8 info = XLogRecGetInfo(r) & ~XLR_INFO_MASK;
593  RepOriginId origin_id = XLogRecGetOrigin(r);
594  Snapshot snapshot = NULL;
595  xl_logical_message *message;
596 
597  if (info != XLOG_LOGICAL_MESSAGE)
598  elog(ERROR, "unexpected RM_LOGICALMSG_ID record type: %u", info);
599 
600  ReorderBufferProcessXid(ctx->reorder, XLogRecGetXid(r), buf->origptr);
601 
602  /*
603  * If we don't have snapshot or we are just fast-forwarding, there is no
604  * point in decoding messages.
605  */
607  ctx->fast_forward)
608  return;
609 
610  message = (xl_logical_message *) XLogRecGetData(r);
611 
612  if (message->dbId != ctx->slot->data.database ||
613  FilterByOrigin(ctx, origin_id))
614  return;
615 
616  if (message->transactional &&
617  !SnapBuildProcessChange(builder, xid, buf->origptr))
618  return;
619  else if (!message->transactional &&
621  SnapBuildXactNeedsSkip(builder, buf->origptr)))
622  return;
623 
624  /*
625  * If this is a non-transactional change, get the snapshot we're expected
626  * to use. We only get here when the snapshot is consistent, and the
627  * change is not meant to be skipped.
628  *
629  * For transactional changes we don't need a snapshot, we'll use the
630  * regular snapshot maintained by ReorderBuffer. We just leave it NULL.
631  */
632  if (!message->transactional)
633  snapshot = SnapBuildGetOrBuildSnapshot(builder);
634 
635  ReorderBufferQueueMessage(ctx->reorder, xid, snapshot, buf->endptr,
636  message->transactional,
637  message->message, /* first part of message is
638  * prefix */
639  message->message_size,
640  message->message + message->prefix_size);
641 }
642 
643 /*
644  * Consolidated commit record handling between the different form of commit
645  * records.
646  *
647  * 'two_phase' indicates that caller wants to process the transaction in two
648  * phases, first process prepare if not already done and then process
649  * commit_prepared.
650  */
651 static void
654  bool two_phase)
655 {
656  XLogRecPtr origin_lsn = InvalidXLogRecPtr;
657  TimestampTz commit_time = parsed->xact_time;
658  RepOriginId origin_id = XLogRecGetOrigin(buf->record);
659  int i;
660 
661  if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
662  {
663  origin_lsn = parsed->origin_lsn;
664  commit_time = parsed->origin_timestamp;
665  }
666 
667  SnapBuildCommitTxn(ctx->snapshot_builder, buf->origptr, xid,
668  parsed->nsubxacts, parsed->subxacts,
669  parsed->xinfo);
670 
671  /* ----
672  * Check whether we are interested in this specific transaction, and tell
673  * the reorderbuffer to forget the content of the (sub-)transactions
674  * if not.
675  *
676  * We can't just use ReorderBufferAbort() here, because we need to execute
677  * the transaction's invalidations. This currently won't be needed if
678  * we're just skipping over the transaction because currently we only do
679  * so during startup, to get to the first transaction the client needs. As
680  * we have reset the catalog caches before starting to read WAL, and we
681  * haven't yet touched any catalogs, there can't be anything to invalidate.
682  * But if we're "forgetting" this commit because it happened in another
683  * database, the invalidations might be important, because they could be
684  * for shared catalogs and we might have loaded data into the relevant
685  * syscaches.
686  * ---
687  */
688  if (DecodeTXNNeedSkip(ctx, buf, parsed->dbId, origin_id))
689  {
690  for (i = 0; i < parsed->nsubxacts; i++)
691  {
692  ReorderBufferForget(ctx->reorder, parsed->subxacts[i], buf->origptr);
693  }
694  ReorderBufferForget(ctx->reorder, xid, buf->origptr);
695 
696  return;
697  }
698 
699  /* tell the reorderbuffer about the surviving subtransactions */
700  for (i = 0; i < parsed->nsubxacts; i++)
701  {
702  ReorderBufferCommitChild(ctx->reorder, xid, parsed->subxacts[i],
703  buf->origptr, buf->endptr);
704  }
705 
706  /*
707  * Send the final commit record if the transaction data is already
708  * decoded, otherwise, process the entire transaction.
709  */
710  if (two_phase)
711  {
712  ReorderBufferFinishPrepared(ctx->reorder, xid, buf->origptr, buf->endptr,
714  commit_time, origin_id, origin_lsn,
715  parsed->twophase_gid, true);
716  }
717  else
718  {
719  ReorderBufferCommit(ctx->reorder, xid, buf->origptr, buf->endptr,
720  commit_time, origin_id, origin_lsn);
721  }
722 
723  /*
724  * Update the decoding stats at transaction prepare/commit/abort.
725  * Additionally we send the stats when we spill or stream the changes to
726  * avoid losing them in case the decoding is interrupted. It is not clear
727  * that sending more or less frequently than this would be better.
728  */
729  UpdateDecodingStats(ctx);
730 }
731 
732 /*
733  * Decode PREPARE record. Similar logic as in DecodeCommit.
734  *
735  * Note that we don't skip prepare even if have detected concurrent abort
736  * because it is quite possible that we had already sent some changes before we
737  * detect abort in which case we need to abort those changes in the subscriber.
738  * To abort such changes, we do send the prepare and then the rollback prepared
739  * which is what happened on the publisher-side as well. Now, we can invent a
740  * new abort API wherein in such cases we send abort and skip sending prepared
741  * and rollback prepared but then it is not that straightforward because we
742  * might have streamed this transaction by that time in which case it is
743  * handled when the rollback is encountered. It is not impossible to optimize
744  * the concurrent abort case but it can introduce design complexity w.r.t
745  * handling different cases so leaving it for now as it doesn't seem worth it.
746  */
747 static void
749  xl_xact_parsed_prepare *parsed)
750 {
751  SnapBuild *builder = ctx->snapshot_builder;
752  XLogRecPtr origin_lsn = parsed->origin_lsn;
753  TimestampTz prepare_time = parsed->xact_time;
754  RepOriginId origin_id = XLogRecGetOrigin(buf->record);
755  int i;
756  TransactionId xid = parsed->twophase_xid;
757 
758  if (parsed->origin_timestamp != 0)
759  prepare_time = parsed->origin_timestamp;
760 
761  /*
762  * Remember the prepare info for a txn so that it can be used later in
763  * commit prepared if required. See ReorderBufferFinishPrepared.
764  */
765  if (!ReorderBufferRememberPrepareInfo(ctx->reorder, xid, buf->origptr,
766  buf->endptr, prepare_time, origin_id,
767  origin_lsn))
768  return;
769 
770  /* We can't start streaming unless a consistent state is reached. */
772  {
774  return;
775  }
776 
777  /*
778  * Check whether we need to process this transaction. See
779  * DecodeTXNNeedSkip for the reasons why we sometimes want to skip the
780  * transaction.
781  *
782  * We can't call ReorderBufferForget as we did in DecodeCommit as the txn
783  * hasn't yet been committed, removing this txn before a commit might
784  * result in the computation of an incorrect restart_lsn. See
785  * SnapBuildProcessRunningXacts. But we need to process cache
786  * invalidations if there are any for the reasons mentioned in
787  * DecodeCommit.
788  */
789  if (DecodeTXNNeedSkip(ctx, buf, parsed->dbId, origin_id))
790  {
792  ReorderBufferInvalidate(ctx->reorder, xid, buf->origptr);
793  return;
794  }
795 
796  /* Tell the reorderbuffer about the surviving subtransactions. */
797  for (i = 0; i < parsed->nsubxacts; i++)
798  {
799  ReorderBufferCommitChild(ctx->reorder, xid, parsed->subxacts[i],
800  buf->origptr, buf->endptr);
801  }
802 
803  /* replay actions of all transaction + subtransactions in order */
804  ReorderBufferPrepare(ctx->reorder, xid, parsed->twophase_gid);
805 
806  /*
807  * Update the decoding stats at transaction prepare/commit/abort.
808  * Additionally we send the stats when we spill or stream the changes to
809  * avoid losing them in case the decoding is interrupted. It is not clear
810  * that sending more or less frequently than this would be better.
811  */
812  UpdateDecodingStats(ctx);
813 }
814 
815 
816 /*
817  * Get the data from the various forms of abort records and pass it on to
818  * snapbuild.c and reorderbuffer.c.
819  *
820  * 'two_phase' indicates to finish prepared transaction.
821  */
822 static void
824  xl_xact_parsed_abort *parsed, TransactionId xid,
825  bool two_phase)
826 {
827  int i;
828  XLogRecPtr origin_lsn = InvalidXLogRecPtr;
829  TimestampTz abort_time = parsed->xact_time;
830  RepOriginId origin_id = XLogRecGetOrigin(buf->record);
831  bool skip_xact;
832 
833  if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
834  {
835  origin_lsn = parsed->origin_lsn;
836  abort_time = parsed->origin_timestamp;
837  }
838 
839  /*
840  * Check whether we need to process this transaction. See
841  * DecodeTXNNeedSkip for the reasons why we sometimes want to skip the
842  * transaction.
843  */
844  skip_xact = DecodeTXNNeedSkip(ctx, buf, parsed->dbId, origin_id);
845 
846  /*
847  * Send the final rollback record for a prepared transaction unless we
848  * need to skip it. For non-two-phase xacts, simply forget the xact.
849  */
850  if (two_phase && !skip_xact)
851  {
852  ReorderBufferFinishPrepared(ctx->reorder, xid, buf->origptr, buf->endptr,
854  abort_time, origin_id, origin_lsn,
855  parsed->twophase_gid, false);
856  }
857  else
858  {
859  for (i = 0; i < parsed->nsubxacts; i++)
860  {
861  ReorderBufferAbort(ctx->reorder, parsed->subxacts[i],
862  buf->record->EndRecPtr, abort_time);
863  }
864 
865  ReorderBufferAbort(ctx->reorder, xid, buf->record->EndRecPtr,
866  abort_time);
867  }
868 
869  /* update the decoding stats */
870  UpdateDecodingStats(ctx);
871 }
872 
873 /*
874  * Parse XLOG_HEAP_INSERT (not MULTI_INSERT!) records into tuplebufs.
875  *
876  * Deletes can contain the new tuple.
877  */
878 static void
880 {
881  Size datalen;
882  char *tupledata;
883  Size tuplelen;
884  XLogReaderState *r = buf->record;
885  xl_heap_insert *xlrec;
886  ReorderBufferChange *change;
887  RelFileLocator target_locator;
888 
889  xlrec = (xl_heap_insert *) XLogRecGetData(r);
890 
891  /*
892  * Ignore insert records without new tuples (this does happen when
893  * raw_heap_insert marks the TOAST record as HEAP_INSERT_NO_LOGICAL).
894  */
895  if (!(xlrec->flags & XLH_INSERT_CONTAINS_NEW_TUPLE))
896  return;
897 
898  /* only interested in our database */
899  XLogRecGetBlockTag(r, 0, &target_locator, NULL, NULL);
900  if (target_locator.dbOid != ctx->slot->data.database)
901  return;
902 
903  /* output plugin doesn't look for this origin, no need to queue */
904  if (FilterByOrigin(ctx, XLogRecGetOrigin(r)))
905  return;
906 
907  change = ReorderBufferGetChange(ctx->reorder);
908  if (!(xlrec->flags & XLH_INSERT_IS_SPECULATIVE))
910  else
912  change->origin_id = XLogRecGetOrigin(r);
913 
914  memcpy(&change->data.tp.rlocator, &target_locator, sizeof(RelFileLocator));
915 
916  tupledata = XLogRecGetBlockData(r, 0, &datalen);
917  tuplelen = datalen - SizeOfHeapHeader;
918 
919  change->data.tp.newtuple =
920  ReorderBufferGetTupleBuf(ctx->reorder, tuplelen);
921 
922  DecodeXLogTuple(tupledata, datalen, change->data.tp.newtuple);
923 
924  change->data.tp.clear_toast_afterwards = true;
925 
927  change,
929 }
930 
931 /*
932  * Parse XLOG_HEAP_UPDATE and XLOG_HEAP_HOT_UPDATE, which have the same layout
933  * in the record, from wal into proper tuplebufs.
934  *
935  * Updates can possibly contain a new tuple and the old primary key.
936  */
937 static void
939 {
940  XLogReaderState *r = buf->record;
941  xl_heap_update *xlrec;
942  ReorderBufferChange *change;
943  char *data;
944  RelFileLocator target_locator;
945 
946  xlrec = (xl_heap_update *) XLogRecGetData(r);
947 
948  /* only interested in our database */
949  XLogRecGetBlockTag(r, 0, &target_locator, NULL, NULL);
950  if (target_locator.dbOid != ctx->slot->data.database)
951  return;
952 
953  /* output plugin doesn't look for this origin, no need to queue */
954  if (FilterByOrigin(ctx, XLogRecGetOrigin(r)))
955  return;
956 
957  change = ReorderBufferGetChange(ctx->reorder);
959  change->origin_id = XLogRecGetOrigin(r);
960  memcpy(&change->data.tp.rlocator, &target_locator, sizeof(RelFileLocator));
961 
963  {
964  Size datalen;
965  Size tuplelen;
966 
967  data = XLogRecGetBlockData(r, 0, &datalen);
968 
969  tuplelen = datalen - SizeOfHeapHeader;
970 
971  change->data.tp.newtuple =
972  ReorderBufferGetTupleBuf(ctx->reorder, tuplelen);
973 
974  DecodeXLogTuple(data, datalen, change->data.tp.newtuple);
975  }
976 
977  if (xlrec->flags & XLH_UPDATE_CONTAINS_OLD)
978  {
979  Size datalen;
980  Size tuplelen;
981 
982  /* caution, remaining data in record is not aligned */
984  datalen = XLogRecGetDataLen(r) - SizeOfHeapUpdate;
985  tuplelen = datalen - SizeOfHeapHeader;
986 
987  change->data.tp.oldtuple =
988  ReorderBufferGetTupleBuf(ctx->reorder, tuplelen);
989 
990  DecodeXLogTuple(data, datalen, change->data.tp.oldtuple);
991  }
992 
993  change->data.tp.clear_toast_afterwards = true;
994 
996  change, false);
997 }
998 
999 /*
1000  * Parse XLOG_HEAP_DELETE from wal into proper tuplebufs.
1001  *
1002  * Deletes can possibly contain the old primary key.
1003  */
1004 static void
1006 {
1007  XLogReaderState *r = buf->record;
1008  xl_heap_delete *xlrec;
1009  ReorderBufferChange *change;
1010  RelFileLocator target_locator;
1011 
1012  xlrec = (xl_heap_delete *) XLogRecGetData(r);
1013 
1014  /* only interested in our database */
1015  XLogRecGetBlockTag(r, 0, &target_locator, NULL, NULL);
1016  if (target_locator.dbOid != ctx->slot->data.database)
1017  return;
1018 
1019  /* output plugin doesn't look for this origin, no need to queue */
1020  if (FilterByOrigin(ctx, XLogRecGetOrigin(r)))
1021  return;
1022 
1023  change = ReorderBufferGetChange(ctx->reorder);
1024 
1025  if (xlrec->flags & XLH_DELETE_IS_SUPER)
1027  else
1029 
1030  change->origin_id = XLogRecGetOrigin(r);
1031 
1032  memcpy(&change->data.tp.rlocator, &target_locator, sizeof(RelFileLocator));
1033 
1034  /* old primary key stored */
1035  if (xlrec->flags & XLH_DELETE_CONTAINS_OLD)
1036  {
1037  Size datalen = XLogRecGetDataLen(r) - SizeOfHeapDelete;
1038  Size tuplelen = datalen - SizeOfHeapHeader;
1039 
1041 
1042  change->data.tp.oldtuple =
1043  ReorderBufferGetTupleBuf(ctx->reorder, tuplelen);
1044 
1045  DecodeXLogTuple((char *) xlrec + SizeOfHeapDelete,
1046  datalen, change->data.tp.oldtuple);
1047  }
1048 
1049  change->data.tp.clear_toast_afterwards = true;
1050 
1052  change, false);
1053 }
1054 
1055 /*
1056  * Parse XLOG_HEAP_TRUNCATE from wal
1057  */
1058 static void
1060 {
1061  XLogReaderState *r = buf->record;
1062  xl_heap_truncate *xlrec;
1063  ReorderBufferChange *change;
1064 
1065  xlrec = (xl_heap_truncate *) XLogRecGetData(r);
1066 
1067  /* only interested in our database */
1068  if (xlrec->dbId != ctx->slot->data.database)
1069  return;
1070 
1071  /* output plugin doesn't look for this origin, no need to queue */
1072  if (FilterByOrigin(ctx, XLogRecGetOrigin(r)))
1073  return;
1074 
1075  change = ReorderBufferGetChange(ctx->reorder);
1077  change->origin_id = XLogRecGetOrigin(r);
1078  if (xlrec->flags & XLH_TRUNCATE_CASCADE)
1079  change->data.truncate.cascade = true;
1080  if (xlrec->flags & XLH_TRUNCATE_RESTART_SEQS)
1081  change->data.truncate.restart_seqs = true;
1082  change->data.truncate.nrelids = xlrec->nrelids;
1083  change->data.truncate.relids = ReorderBufferGetRelids(ctx->reorder,
1084  xlrec->nrelids);
1085  memcpy(change->data.truncate.relids, xlrec->relids,
1086  xlrec->nrelids * sizeof(Oid));
1088  buf->origptr, change, false);
1089 }
1090 
1091 /*
1092  * Decode XLOG_HEAP2_MULTI_INSERT record into multiple tuplebufs.
1093  *
1094  * Currently MULTI_INSERT will always contain the full tuples.
1095  */
1096 static void
1098 {
1099  XLogReaderState *r = buf->record;
1100  xl_heap_multi_insert *xlrec;
1101  int i;
1102  char *data;
1103  char *tupledata;
1104  Size tuplelen;
1105  RelFileLocator rlocator;
1106 
1107  xlrec = (xl_heap_multi_insert *) XLogRecGetData(r);
1108 
1109  /*
1110  * Ignore insert records without new tuples. This happens when a
1111  * multi_insert is done on a catalog or on a non-persistent relation.
1112  */
1113  if (!(xlrec->flags & XLH_INSERT_CONTAINS_NEW_TUPLE))
1114  return;
1115 
1116  /* only interested in our database */
1117  XLogRecGetBlockTag(r, 0, &rlocator, NULL, NULL);
1118  if (rlocator.dbOid != ctx->slot->data.database)
1119  return;
1120 
1121  /* output plugin doesn't look for this origin, no need to queue */
1122  if (FilterByOrigin(ctx, XLogRecGetOrigin(r)))
1123  return;
1124 
1125  /*
1126  * We know that this multi_insert isn't for a catalog, so the block should
1127  * always have data even if a full-page write of it is taken.
1128  */
1129  tupledata = XLogRecGetBlockData(r, 0, &tuplelen);
1130  Assert(tupledata != NULL);
1131 
1132  data = tupledata;
1133  for (i = 0; i < xlrec->ntuples; i++)
1134  {
1135  ReorderBufferChange *change;
1136  xl_multi_insert_tuple *xlhdr;
1137  int datalen;
1138  ReorderBufferTupleBuf *tuple;
1139  HeapTupleHeader header;
1140 
1141  change = ReorderBufferGetChange(ctx->reorder);
1143  change->origin_id = XLogRecGetOrigin(r);
1144 
1145  memcpy(&change->data.tp.rlocator, &rlocator, sizeof(RelFileLocator));
1146 
1147  xlhdr = (xl_multi_insert_tuple *) SHORTALIGN(data);
1148  data = ((char *) xlhdr) + SizeOfMultiInsertTuple;
1149  datalen = xlhdr->datalen;
1150 
1151  change->data.tp.newtuple =
1152  ReorderBufferGetTupleBuf(ctx->reorder, datalen);
1153 
1154  tuple = change->data.tp.newtuple;
1155  header = tuple->tuple.t_data;
1156 
1157  /* not a disk based tuple */
1159 
1160  /*
1161  * We can only figure this out after reassembling the transactions.
1162  */
1163  tuple->tuple.t_tableOid = InvalidOid;
1164 
1165  tuple->tuple.t_len = datalen + SizeofHeapTupleHeader;
1166 
1167  memset(header, 0, SizeofHeapTupleHeader);
1168 
1169  memcpy((char *) tuple->tuple.t_data + SizeofHeapTupleHeader,
1170  (char *) data,
1171  datalen);
1172  header->t_infomask = xlhdr->t_infomask;
1173  header->t_infomask2 = xlhdr->t_infomask2;
1174  header->t_hoff = xlhdr->t_hoff;
1175 
1176  /*
1177  * Reset toast reassembly state only after the last row in the last
1178  * xl_multi_insert_tuple record emitted by one heap_multi_insert()
1179  * call.
1180  */
1181  if (xlrec->flags & XLH_INSERT_LAST_IN_MULTI &&
1182  (i + 1) == xlrec->ntuples)
1183  change->data.tp.clear_toast_afterwards = true;
1184  else
1185  change->data.tp.clear_toast_afterwards = false;
1186 
1188  buf->origptr, change, false);
1189 
1190  /* move to the next xl_multi_insert_tuple entry */
1191  data += datalen;
1192  }
1193  Assert(data == tupledata + tuplelen);
1194 }
1195 
1196 /*
1197  * Parse XLOG_HEAP_CONFIRM from wal into a confirmation change.
1198  *
1199  * This is pretty trivial, all the state essentially already setup by the
1200  * speculative insertion.
1201  */
1202 static void
1204 {
1205  XLogReaderState *r = buf->record;
1206  ReorderBufferChange *change;
1207  RelFileLocator target_locator;
1208 
1209  /* only interested in our database */
1210  XLogRecGetBlockTag(r, 0, &target_locator, NULL, NULL);
1211  if (target_locator.dbOid != ctx->slot->data.database)
1212  return;
1213 
1214  /* output plugin doesn't look for this origin, no need to queue */
1215  if (FilterByOrigin(ctx, XLogRecGetOrigin(r)))
1216  return;
1217 
1218  change = ReorderBufferGetChange(ctx->reorder);
1220  change->origin_id = XLogRecGetOrigin(r);
1221 
1222  memcpy(&change->data.tp.rlocator, &target_locator, sizeof(RelFileLocator));
1223 
1224  change->data.tp.clear_toast_afterwards = true;
1225 
1227  change, false);
1228 }
1229 
1230 
1231 /*
1232  * Read a HeapTuple as WAL logged by heap_insert, heap_update and heap_delete
1233  * (but not by heap_multi_insert) into a tuplebuf.
1234  *
1235  * The size 'len' and the pointer 'data' in the record need to be
1236  * computed outside as they are record specific.
1237  */
1238 static void
1240 {
1241  xl_heap_header xlhdr;
1242  int datalen = len - SizeOfHeapHeader;
1243  HeapTupleHeader header;
1244 
1245  Assert(datalen >= 0);
1246 
1247  tuple->tuple.t_len = datalen + SizeofHeapTupleHeader;
1248  header = tuple->tuple.t_data;
1249 
1250  /* not a disk based tuple */
1252 
1253  /* we can only figure this out after reassembling the transactions */
1254  tuple->tuple.t_tableOid = InvalidOid;
1255 
1256  /* data is not stored aligned, copy to aligned storage */
1257  memcpy((char *) &xlhdr,
1258  data,
1260 
1261  memset(header, 0, SizeofHeapTupleHeader);
1262 
1263  memcpy(((char *) tuple->tuple.t_data) + SizeofHeapTupleHeader,
1265  datalen);
1266 
1267  header->t_infomask = xlhdr.t_infomask;
1268  header->t_infomask2 = xlhdr.t_infomask2;
1269  header->t_hoff = xlhdr.t_hoff;
1270 }
1271 
1272 /*
1273  * Check whether we are interested in this specific transaction.
1274  *
1275  * There can be several reasons we might not be interested in this
1276  * transaction:
1277  * 1) We might not be interested in decoding transactions up to this
1278  * LSN. This can happen because we previously decoded it and now just
1279  * are restarting or if we haven't assembled a consistent snapshot yet.
1280  * 2) The transaction happened in another database.
1281  * 3) The output plugin is not interested in the origin.
1282  * 4) We are doing fast-forwarding
1283  */
1284 static bool
1286  Oid txn_dbid, RepOriginId origin_id)
1287 {
1288  return (SnapBuildXactNeedsSkip(ctx->snapshot_builder, buf->origptr) ||
1289  (txn_dbid != InvalidOid && txn_dbid != ctx->slot->data.database) ||
1290  ctx->fast_forward || FilterByOrigin(ctx, origin_id));
1291 }
#define SHORTALIGN(LEN)
Definition: c.h:796
unsigned char uint8
Definition: c.h:493
uint32 TransactionId
Definition: c.h:641
size_t Size
Definition: c.h:594
int64 TimestampTz
Definition: timestamp.h:39
static bool DecodeTXNNeedSkip(LogicalDecodingContext *ctx, XLogRecordBuffer *buf, Oid txn_dbid, RepOriginId origin_id)
Definition: decode.c:1285
void heap2_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:406
static void DecodeAbort(LogicalDecodingContext *ctx, XLogRecordBuffer *buf, xl_xact_parsed_abort *parsed, TransactionId xid, bool two_phase)
Definition: decode.c:823
static bool FilterPrepare(LogicalDecodingContext *ctx, TransactionId xid, const char *gid)
Definition: decode.c:552
static void DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:1097
void LogicalDecodingProcessRecord(LogicalDecodingContext *ctx, XLogReaderState *record)
Definition: decode.c:91
static void DecodeCommit(LogicalDecodingContext *ctx, XLogRecordBuffer *buf, xl_xact_parsed_commit *parsed, TransactionId xid, bool two_phase)
Definition: decode.c:652
static void DecodeDelete(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:1005
void heap_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:465
void xlog_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:132
void xact_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:203
static void DecodeXLogTuple(char *data, Size len, ReorderBufferTupleBuf *tuple)
Definition: decode.c:1239
void standby_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:360
static bool FilterByOrigin(LogicalDecodingContext *ctx, RepOriginId origin_id)
Definition: decode.c:575
static void DecodeInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:879
static void DecodeTruncate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:1059
void logicalmsg_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:587
static void DecodeUpdate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:938
static void DecodePrepare(LogicalDecodingContext *ctx, XLogRecordBuffer *buf, xl_xact_parsed_prepare *parsed)
Definition: decode.c:748
static void DecodeSpecConfirm(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:1203
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define XLH_INSERT_ON_TOAST_RELATION
Definition: heapam_xlog.h:70
#define XLOG_HEAP2_PRUNE
Definition: heapam_xlog.h:54
#define XLOG_HEAP2_MULTI_INSERT
Definition: heapam_xlog.h:58
#define SizeOfHeapUpdate
Definition: heapam_xlog.h:227
#define XLOG_HEAP_HOT_UPDATE
Definition: heapam_xlog.h:36
#define XLOG_HEAP_DELETE
Definition: heapam_xlog.h:33
#define XLOG_HEAP2_VACUUM
Definition: heapam_xlog.h:55
#define XLH_INSERT_IS_SPECULATIVE
Definition: heapam_xlog.h:68
#define XLOG_HEAP2_REWRITE
Definition: heapam_xlog.h:53
#define XLOG_HEAP_TRUNCATE
Definition: heapam_xlog.h:35
#define XLH_UPDATE_CONTAINS_NEW_TUPLE
Definition: heapam_xlog.h:84
#define XLH_INSERT_LAST_IN_MULTI
Definition: heapam_xlog.h:67
#define XLOG_HEAP_OPMASK
Definition: heapam_xlog.h:41
#define XLH_UPDATE_CONTAINS_OLD
Definition: heapam_xlog.h:89
#define XLH_TRUNCATE_RESTART_SEQS
Definition: heapam_xlog.h:121
#define XLOG_HEAP_UPDATE
Definition: heapam_xlog.h:34
#define XLH_DELETE_CONTAINS_OLD
Definition: heapam_xlog.h:103
#define SizeOfHeapHeader
Definition: heapam_xlog.h:151
#define XLOG_HEAP_INPLACE
Definition: heapam_xlog.h:39
#define XLOG_HEAP2_LOCK_UPDATED
Definition: heapam_xlog.h:59
#define XLOG_HEAP2_FREEZE_PAGE
Definition: heapam_xlog.h:56
#define SizeOfMultiInsertTuple
Definition: heapam_xlog.h:193
#define XLOG_HEAP2_NEW_CID
Definition: heapam_xlog.h:60
#define XLOG_HEAP_LOCK
Definition: heapam_xlog.h:38
#define XLH_TRUNCATE_CASCADE
Definition: heapam_xlog.h:120
#define XLOG_HEAP_INSERT
Definition: heapam_xlog.h:32
#define SizeOfHeapDelete
Definition: heapam_xlog.h:115
#define XLH_DELETE_IS_SUPER
Definition: heapam_xlog.h:99
#define XLOG_HEAP2_VISIBLE
Definition: heapam_xlog.h:57
#define XLH_INSERT_CONTAINS_NEW_TUPLE
Definition: heapam_xlog.h:69
#define XLOG_HEAP_CONFIRM
Definition: heapam_xlog.h:37
#define SizeofHeapTupleHeader
Definition: htup_details.h:185
int i
Definition: isn.c:73
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
Assert(fmt[strlen(fmt) - 1] !='\n')
void UpdateDecodingStats(LogicalDecodingContext *ctx)
Definition: logical.c:1912
bool filter_prepare_cb_wrapper(LogicalDecodingContext *ctx, TransactionId xid, const char *gid)
Definition: logical.c:1164
bool filter_by_origin_cb_wrapper(LogicalDecodingContext *ctx, RepOriginId origin_id)
Definition: logical.c:1196
#define XLOG_LOGICAL_MESSAGE
Definition: message.h:36
#define XLOG_RESTORE_POINT
Definition: pg_control.h:74
#define XLOG_FPW_CHANGE
Definition: pg_control.h:75
#define XLOG_OVERWRITE_CONTRECORD
Definition: pg_control.h:80
#define XLOG_FPI
Definition: pg_control.h:78
#define XLOG_FPI_FOR_HINT
Definition: pg_control.h:77
#define XLOG_NEXTOID
Definition: pg_control.h:70
#define XLOG_NOOP
Definition: pg_control.h:69
#define XLOG_CHECKPOINT_SHUTDOWN
Definition: pg_control.h:67
#define XLOG_SWITCH
Definition: pg_control.h:71
#define XLOG_BACKUP_END
Definition: pg_control.h:72
#define XLOG_PARAMETER_CHANGE
Definition: pg_control.h:73
#define XLOG_CHECKPOINT_ONLINE
Definition: pg_control.h:68
#define XLOG_END_OF_RECOVERY
Definition: pg_control.h:76
const void size_t len
const void * data
static bool two_phase
static char * buf
Definition: pg_test_fsync.c:67
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
void ReorderBufferXidSetCatalogChanges(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
void ReorderBufferAbort(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, TimestampTz abort_time)
void ReorderBufferInvalidate(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, ReorderBufferChange *change, bool toast_insert)
void ReorderBufferPrepare(ReorderBuffer *rb, TransactionId xid, char *gid)
void ReorderBufferForget(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
void ReorderBufferCommitChild(ReorderBuffer *rb, TransactionId xid, TransactionId subxid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn)
void ReorderBufferSkipPrepare(ReorderBuffer *rb, TransactionId xid)
Oid * ReorderBufferGetRelids(ReorderBuffer *rb, int nrelids)
void ReorderBufferAddInvalidations(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, Size nmsgs, SharedInvalidationMessage *msgs)
void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid, Snapshot snap, XLogRecPtr lsn, bool transactional, const char *prefix, Size message_size, const char *message)
ReorderBufferChange * ReorderBufferGetChange(ReorderBuffer *rb)
void ReorderBufferFinishPrepared(ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, XLogRecPtr two_phase_at, TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn, char *gid, bool is_commit)
void ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn)
bool ReorderBufferRememberPrepareInfo(ReorderBuffer *rb, TransactionId xid, XLogRecPtr prepare_lsn, XLogRecPtr end_lsn, TimestampTz prepare_time, RepOriginId origin_id, XLogRecPtr origin_lsn)
void ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations)
ReorderBufferTupleBuf * ReorderBufferGetTupleBuf(ReorderBuffer *rb, Size tuple_len)
void ReorderBufferProcessXid(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
void ReorderBufferAssignChild(ReorderBuffer *rb, TransactionId xid, TransactionId subxid, XLogRecPtr lsn)
void ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM
Definition: reorderbuffer.h:74
@ REORDER_BUFFER_CHANGE_INSERT
Definition: reorderbuffer.h:65
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT
Definition: reorderbuffer.h:75
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT
Definition: reorderbuffer.h:73
@ REORDER_BUFFER_CHANGE_TRUNCATE
Definition: reorderbuffer.h:76
@ REORDER_BUFFER_CHANGE_DELETE
Definition: reorderbuffer.h:67
@ REORDER_BUFFER_CHANGE_UPDATE
Definition: reorderbuffer.h:66
bool SnapBuildXactNeedsSkip(SnapBuild *builder, XLogRecPtr ptr)
Definition: snapbuild.c:434
bool SnapBuildProcessChange(SnapBuild *builder, TransactionId xid, XLogRecPtr lsn)
Definition: snapbuild.c:769
XLogRecPtr SnapBuildGetTwoPhaseAt(SnapBuild *builder)
Definition: snapbuild.c:416
SnapBuildState SnapBuildCurrentState(SnapBuild *builder)
Definition: snapbuild.c:407
Snapshot SnapBuildGetOrBuildSnapshot(SnapBuild *builder)
Definition: snapbuild.c:709
void SnapBuildSerializationPoint(SnapBuild *builder, XLogRecPtr lsn)
Definition: snapbuild.c:1593
void SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn, TransactionId xid, int nsubxacts, TransactionId *subxacts, uint32 xinfo)
Definition: snapbuild.c:1025
void SnapBuildProcessNewCid(SnapBuild *builder, TransactionId xid, XLogRecPtr lsn, xl_heap_new_cid *xlrec)
Definition: snapbuild.c:819
void SnapBuildProcessRunningXacts(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *running)
Definition: snapbuild.c:1218
@ SNAPBUILD_FULL_SNAPSHOT
Definition: snapbuild.h:39
@ SNAPBUILD_CONSISTENT
Definition: snapbuild.h:46
#define XLOG_INVALIDATIONS
Definition: standbydefs.h:36
#define XLOG_STANDBY_LOCK
Definition: standbydefs.h:34
#define XLOG_RUNNING_XACTS
Definition: standbydefs.h:35
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid t_tableOid
Definition: htup.h:66
XLogReaderState * reader
Definition: logical.h:42
struct SnapBuild * snapshot_builder
Definition: logical.h:44
OutputPluginCallbacks callbacks
Definition: logical.h:53
ReplicationSlot * slot
Definition: logical.h:39
struct ReorderBuffer * reorder
Definition: logical.h:43
LogicalDecodeFilterPrepareCB filter_prepare_cb
LogicalDecodeFilterByOriginCB filter_by_origin_cb
struct ReorderBufferChange::@100::@101 tp
ReorderBufferChangeType action
Definition: reorderbuffer.h:94
struct ReorderBufferChange::@100::@102 truncate
RepOriginId origin_id
Definition: reorderbuffer.h:99
union ReorderBufferChange::@100 data
HeapTupleData tuple
Definition: reorderbuffer.h:38
ReplicationSlotPersistentData data
Definition: slot.h:162
void(* rm_decode)(struct LogicalDecodingContext *ctx, struct XLogRecordBuffer *buf)
XLogRecPtr EndRecPtr
Definition: xlogreader.h:207
XLogRecPtr ReadRecPtr
Definition: xlogreader.h:206
uint16 t_infomask
Definition: heapam_xlog.h:147
uint16 t_infomask2
Definition: heapam_xlog.h:146
Oid relids[FLEXIBLE_ARRAY_MEMBER]
Definition: heapam_xlog.h:133
bool transactional
Definition: message.h:23
char message[FLEXIBLE_ARRAY_MEMBER]
Definition: message.h:27
TransactionId oldestRunningXid
Definition: standbydefs.h:53
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:299
int nmsgs
Definition: xact.h:298
TransactionId twophase_xid
Definition: xact.h:421
TimestampTz xact_time
Definition: xact.h:406
TransactionId * subxacts
Definition: xact.h:413
XLogRecPtr origin_lsn
Definition: xact.h:424
char twophase_gid[GIDSIZE]
Definition: xact.h:422
TimestampTz origin_timestamp
Definition: xact.h:425
TimestampTz xact_time
Definition: xact.h:373
TransactionId twophase_xid
Definition: xact.h:391
TimestampTz origin_timestamp
Definition: xact.h:399
TransactionId * subxacts
Definition: xact.h:380
char twophase_gid[GIDSIZE]
Definition: xact.h:392
XLogRecPtr origin_lsn
Definition: xact.h:398
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:172
#define XLOG_XACT_INVALIDATIONS
Definition: xact.h:175
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:193
#define XLOG_XACT_PREPARE
Definition: xact.h:170
#define XLOG_XACT_COMMIT
Definition: xact.h:169
#define XLOG_XACT_OPMASK
Definition: xact.h:179
#define XLOG_XACT_ABORT
Definition: xact.h:171
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:174
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:173
void ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
Definition: xactdesc.c:35
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
Definition: xactdesc.c:141
void ParsePrepareRecord(uint8 info, xl_xact_prepare *xlrec, xl_xact_parsed_prepare *parsed)
Definition: xactdesc.c:239
bool RecoveryInProgress(void)
Definition: xlog.c:5948
@ WAL_LEVEL_LOGICAL
Definition: xlog.h:71
static RmgrData GetRmgr(RmgrId rmid)
uint16 RepOriginId
Definition: xlogdefs.h:65
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
void XLogRecGetBlockTag(XLogReaderState *record, uint8 block_id, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum)
Definition: xlogreader.c:1979
char * XLogRecGetBlockData(XLogReaderState *record, uint8 block_id, Size *len)
Definition: xlogreader.c:2033
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:413
#define XLogRecGetDataLen(decoder)
Definition: xlogreader.h:416
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:410
#define XLogRecGetRmid(decoder)
Definition: xlogreader.h:411
#define XLogRecGetData(decoder)
Definition: xlogreader.h:415
#define XLogRecGetXid(decoder)
Definition: xlogreader.h:412
#define XLogRecGetTopXid(decoder)
Definition: xlogreader.h:414
#define XLR_INFO_MASK
Definition: xlogrecord.h:62