PostgreSQL Source Code  git master
logical.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  * logical.c
3  * PostgreSQL logical decoding coordination
4  *
5  * Copyright (c) 2012-2021, PostgreSQL Global Development Group
6  *
7  * IDENTIFICATION
8  * src/backend/replication/logical/logical.c
9  *
10  * NOTES
11  * This file coordinates interaction between the various modules that
12  * together provide logical decoding, primarily by providing so
13  * called LogicalDecodingContexts. The goal is to encapsulate most of the
14  * internal complexity for consumers of logical decoding, so they can
15  * create and consume a changestream with a low amount of code. Builtin
16  * consumers are the walsender and SQL SRF interface, but it's possible to
17  * add further ones without changing core code, e.g. to consume changes in
18  * a bgworker.
19  *
20  * The idea is that a consumer provides three callbacks, one to read WAL,
21  * one to prepare a data write, and a final one for actually writing since
22  * their implementation depends on the type of consumer. Check
23  * logicalfuncs.c for an example implementation of a fairly simple consumer
24  * and an implementation of a WAL reading callback that's suitable for
25  * simple consumers.
26  *-------------------------------------------------------------------------
27  */
28 
29 #include "postgres.h"
30 
31 #include "access/xact.h"
32 #include "access/xlog_internal.h"
33 #include "fmgr.h"
34 #include "miscadmin.h"
35 #include "pgstat.h"
36 #include "replication/decode.h"
37 #include "replication/logical.h"
38 #include "replication/origin.h"
40 #include "replication/snapbuild.h"
41 #include "storage/proc.h"
42 #include "storage/procarray.h"
43 #include "utils/builtins.h"
44 #include "utils/memutils.h"
45 
46 /* data for errcontext callback */
48 {
50  const char *callback_name;
53 
54 /* wrappers around output plugin callbacks */
55 static void output_plugin_error_callback(void *arg);
57  bool is_init);
59 static void begin_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn);
60 static void commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
61  XLogRecPtr commit_lsn);
63 static void prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
64  XLogRecPtr prepare_lsn);
66  XLogRecPtr commit_lsn);
68  XLogRecPtr prepare_end_lsn, TimestampTz prepare_time);
69 static void change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
70  Relation relation, ReorderBufferChange *change);
71 static void truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
72  int nrelations, Relation relations[], ReorderBufferChange *change);
73 static void message_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
74  XLogRecPtr message_lsn, bool transactional,
75  const char *prefix, Size message_size, const char *message);
76 
77 /* streaming callbacks */
79  XLogRecPtr first_lsn);
81  XLogRecPtr last_lsn);
83  XLogRecPtr abort_lsn);
85  XLogRecPtr prepare_lsn);
87  XLogRecPtr commit_lsn);
89  Relation relation, ReorderBufferChange *change);
91  XLogRecPtr message_lsn, bool transactional,
92  const char *prefix, Size message_size, const char *message);
94  int nrelations, Relation relations[], ReorderBufferChange *change);
95 
96 static void LoadOutputPlugin(OutputPluginCallbacks *callbacks, const char *plugin);
97 
98 /*
99  * Make sure the current settings & environment are capable of doing logical
100  * decoding.
101  */
102 void
104 {
106 
107  /*
108  * NB: Adding a new requirement likely means that RestoreSlotFromDisk()
109  * needs the same check.
110  */
111 
113  ereport(ERROR,
114  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
115  errmsg("logical decoding requires wal_level >= logical")));
116 
117  if (MyDatabaseId == InvalidOid)
118  ereport(ERROR,
119  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
120  errmsg("logical decoding requires a database connection")));
121 
122  /* ----
123  * TODO: We got to change that someday soon...
124  *
125  * There's basically three things missing to allow this:
126  * 1) We need to be able to correctly and quickly identify the timeline a
127  * LSN belongs to
128  * 2) We need to force hot_standby_feedback to be enabled at all times so
129  * the primary cannot remove rows we need.
130  * 3) support dropping replication slots referring to a database, in
131  * dbase_redo. There can't be any active ones due to HS recovery
132  * conflicts, so that should be relatively easy.
133  * ----
134  */
135  if (RecoveryInProgress())
136  ereport(ERROR,
137  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
138  errmsg("logical decoding cannot be used while in recovery")));
139 }
140 
141 /*
142  * Helper function for CreateInitDecodingContext() and
143  * CreateDecodingContext() performing common tasks.
144  */
145 static LogicalDecodingContext *
146 StartupDecodingContext(List *output_plugin_options,
147  XLogRecPtr start_lsn,
148  TransactionId xmin_horizon,
149  bool need_full_snapshot,
150  bool fast_forward,
152  WALSegmentCleanupCB cleanup_cb,
156 {
157  ReplicationSlot *slot;
158  MemoryContext context,
159  old_context;
161 
162  /* shorter lines... */
163  slot = MyReplicationSlot;
164 
166  "Logical decoding context",
168  old_context = MemoryContextSwitchTo(context);
169  ctx = palloc0(sizeof(LogicalDecodingContext));
170 
171  ctx->context = context;
172 
173  /*
174  * (re-)load output plugins, so we detect a bad (removed) output plugin
175  * now.
176  */
177  if (!fast_forward)
179 
180  /*
181  * Now that the slot's xmin has been set, we can announce ourselves as a
182  * logical decoding backend which doesn't need to be checked individually
183  * when computing the xmin horizon because the xmin is enforced via
184  * replication slots.
185  *
186  * We can only do so if we're outside of a transaction (i.e. the case when
187  * streaming changes via walsender), otherwise an already setup
188  * snapshot/xid would end up being ignored. That's not a particularly
189  * bothersome restriction since the SQL interface can't be used for
190  * streaming anyway.
191  */
193  {
194  LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
197  LWLockRelease(ProcArrayLock);
198  }
199 
200  ctx->slot = slot;
201 
202  ctx->reader = XLogReaderAllocate(wal_segment_size, NULL, cleanup_cb);
203  if (!ctx->reader)
204  ereport(ERROR,
205  (errcode(ERRCODE_OUT_OF_MEMORY),
206  errmsg("out of memory")));
207  ctx->page_read = page_read;
208 
210  ctx->snapshot_builder =
211  AllocateSnapshotBuilder(ctx->reorder, xmin_horizon, start_lsn,
212  need_full_snapshot, slot->data.initial_consistent_point);
213 
214  ctx->reorder->private_data = ctx;
215 
216  /* wrap output plugin callbacks, so we can add error context information */
222 
223  /*
224  * To support streaming, we require start/stop/abort/commit/change
225  * callbacks. The message and truncate callbacks are optional, similar to
226  * regular output plugins. We however enable streaming when at least one
227  * of the methods is enabled so that we can easily identify missing
228  * methods.
229  *
230  * We decide it here, but only check it later in the wrappers.
231  */
232  ctx->streaming = (ctx->callbacks.stream_start_cb != NULL) ||
233  (ctx->callbacks.stream_stop_cb != NULL) ||
234  (ctx->callbacks.stream_abort_cb != NULL) ||
235  (ctx->callbacks.stream_commit_cb != NULL) ||
236  (ctx->callbacks.stream_change_cb != NULL) ||
237  (ctx->callbacks.stream_message_cb != NULL) ||
238  (ctx->callbacks.stream_truncate_cb != NULL);
239 
240  /*
241  * streaming callbacks
242  *
243  * stream_message and stream_truncate callbacks are optional, so we do not
244  * fail with ERROR when missing, but the wrappers simply do nothing. We
245  * must set the ReorderBuffer callbacks to something, otherwise the calls
246  * from there will crash (we don't want to move the checks there).
247  */
256 
257 
258  /*
259  * To support two-phase logical decoding, we require
260  * begin_prepare/prepare/commit-prepare/abort-prepare callbacks. The
261  * filter_prepare callback is optional. We however enable two-phase
262  * logical decoding when at least one of the methods is enabled so that we
263  * can easily identify missing methods.
264  *
265  * We decide it here, but only check it later in the wrappers.
266  */
267  ctx->twophase = (ctx->callbacks.begin_prepare_cb != NULL) ||
268  (ctx->callbacks.prepare_cb != NULL) ||
269  (ctx->callbacks.commit_prepared_cb != NULL) ||
270  (ctx->callbacks.rollback_prepared_cb != NULL) ||
271  (ctx->callbacks.stream_prepare_cb != NULL) ||
272  (ctx->callbacks.filter_prepare_cb != NULL);
273 
274  /*
275  * Callback to support decoding at prepare time.
276  */
281 
282  ctx->out = makeStringInfo();
283  ctx->prepare_write = prepare_write;
284  ctx->write = do_write;
285  ctx->update_progress = update_progress;
286 
287  ctx->output_plugin_options = output_plugin_options;
288 
289  ctx->fast_forward = fast_forward;
290 
291  MemoryContextSwitchTo(old_context);
292 
293  return ctx;
294 }
295 
296 /*
297  * Create a new decoding context, for a new logical slot.
298  *
299  * plugin -- contains the name of the output plugin
300  * output_plugin_options -- contains options passed to the output plugin
301  * need_full_snapshot -- if true, must obtain a snapshot able to read all
302  * tables; if false, one that can read only catalogs is acceptable.
303  * restart_lsn -- if given as invalid, it's this routine's responsibility to
304  * mark WAL as reserved by setting a convenient restart_lsn for the slot.
305  * Otherwise, we set for decoding to start from the given LSN without
306  * marking WAL reserved beforehand. In that scenario, it's up to the
307  * caller to guarantee that WAL remains available.
308  * xl_routine -- XLogReaderRoutine for underlying XLogReader
309  * prepare_write, do_write, update_progress --
310  * callbacks that perform the use-case dependent, actual, work.
311  *
312  * Needs to be called while in a memory context that's at least as long lived
313  * as the decoding context because further memory contexts will be created
314  * inside it.
315  *
316  * Returns an initialized decoding context after calling the output plugin's
317  * startup function.
318  */
321  List *output_plugin_options,
322  bool need_full_snapshot,
323  XLogRecPtr restart_lsn,
325  WALSegmentCleanupCB cleanup_cb,
329 {
330  TransactionId xmin_horizon = InvalidTransactionId;
331  ReplicationSlot *slot;
332  NameData plugin_name;
334  MemoryContext old_context;
335 
336  /* shorter lines... */
337  slot = MyReplicationSlot;
338 
339  /* first some sanity checks that are unlikely to be violated */
340  if (slot == NULL)
341  elog(ERROR, "cannot perform logical decoding without an acquired slot");
342 
343  if (plugin == NULL)
344  elog(ERROR, "cannot initialize logical decoding without a specified plugin");
345 
346  /* Make sure the passed slot is suitable. These are user facing errors. */
347  if (SlotIsPhysical(slot))
348  ereport(ERROR,
349  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
350  errmsg("cannot use physical replication slot for logical decoding")));
351 
352  if (slot->data.database != MyDatabaseId)
353  ereport(ERROR,
354  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
355  errmsg("replication slot \"%s\" was not created in this database",
356  NameStr(slot->data.name))));
357 
358  if (IsTransactionState() &&
360  ereport(ERROR,
361  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
362  errmsg("cannot create logical replication slot in transaction that has performed writes")));
363 
364  /*
365  * Register output plugin name with slot. We need the mutex to avoid
366  * concurrent reading of a partially copied string. But we don't want any
367  * complicated code while holding a spinlock, so do namestrcpy() outside.
368  */
369  namestrcpy(&plugin_name, plugin);
370  SpinLockAcquire(&slot->mutex);
371  slot->data.plugin = plugin_name;
372  SpinLockRelease(&slot->mutex);
373 
374  if (XLogRecPtrIsInvalid(restart_lsn))
376  else
377  {
378  SpinLockAcquire(&slot->mutex);
379  slot->data.restart_lsn = restart_lsn;
380  SpinLockRelease(&slot->mutex);
381  }
382 
383  /* ----
384  * This is a bit tricky: We need to determine a safe xmin horizon to start
385  * decoding from, to avoid starting from a running xacts record referring
386  * to xids whose rows have been vacuumed or pruned
387  * already. GetOldestSafeDecodingTransactionId() returns such a value, but
388  * without further interlock its return value might immediately be out of
389  * date.
390  *
391  * So we have to acquire the ProcArrayLock to prevent computation of new
392  * xmin horizons by other backends, get the safe decoding xid, and inform
393  * the slot machinery about the new limit. Once that's done the
394  * ProcArrayLock can be released as the slot machinery now is
395  * protecting against vacuum.
396  *
397  * Note that, temporarily, the data, not just the catalog, xmin has to be
398  * reserved if a data snapshot is to be exported. Otherwise the initial
399  * data snapshot created here is not guaranteed to be valid. After that
400  * the data xmin doesn't need to be managed anymore and the global xmin
401  * should be recomputed. As we are fine with losing the pegged data xmin
402  * after crash - no chance a snapshot would get exported anymore - we can
403  * get away with just setting the slot's
404  * effective_xmin. ReplicationSlotRelease will reset it again.
405  *
406  * ----
407  */
408  LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
409 
410  xmin_horizon = GetOldestSafeDecodingTransactionId(!need_full_snapshot);
411 
412  SpinLockAcquire(&slot->mutex);
413  slot->effective_catalog_xmin = xmin_horizon;
414  slot->data.catalog_xmin = xmin_horizon;
415  if (need_full_snapshot)
416  slot->effective_xmin = xmin_horizon;
417  SpinLockRelease(&slot->mutex);
418 
420 
421  LWLockRelease(ProcArrayLock);
422 
425 
426  ctx = StartupDecodingContext(NIL, restart_lsn, xmin_horizon,
427  need_full_snapshot, false,
428  page_read, cleanup_cb, prepare_write, do_write,
429  update_progress);
430 
431  /* call output plugin initialization callback */
432  old_context = MemoryContextSwitchTo(ctx->context);
433  if (ctx->callbacks.startup_cb != NULL)
434  startup_cb_wrapper(ctx, &ctx->options, true);
435  MemoryContextSwitchTo(old_context);
436 
437  /*
438  * We allow decoding of prepared transactions iff the two_phase option is
439  * enabled at the time of slot creation.
440  */
442 
444 
445  return ctx;
446 }
447 
448 /*
449  * Create a new decoding context, for a logical slot that has previously been
450  * used already.
451  *
452  * start_lsn
453  * The LSN at which to start decoding. If InvalidXLogRecPtr, restart
454  * from the slot's confirmed_flush; otherwise, start from the specified
455  * location (but move it forwards to confirmed_flush if it's older than
456  * that, see below).
457  *
458  * output_plugin_options
459  * options passed to the output plugin.
460  *
461  * fast_forward
462  * bypass the generation of logical changes.
463  *
464  * xl_routine
465  * XLogReaderRoutine used by underlying xlogreader
466  *
467  * prepare_write, do_write, update_progress
468  * callbacks that have to be filled to perform the use-case dependent,
469  * actual work.
470  *
471  * Needs to be called while in a memory context that's at least as long lived
472  * as the decoding context because further memory contexts will be created
473  * inside it.
474  *
475  * Returns an initialized decoding context after calling the output plugin's
476  * startup function.
477  */
480  List *output_plugin_options,
481  bool fast_forward,
483  WALSegmentCleanupCB cleanup_cb,
487 {
489  ReplicationSlot *slot;
490  MemoryContext old_context;
491 
492  /* shorter lines... */
493  slot = MyReplicationSlot;
494 
495  /* first some sanity checks that are unlikely to be violated */
496  if (slot == NULL)
497  elog(ERROR, "cannot perform logical decoding without an acquired slot");
498 
499  /* make sure the passed slot is suitable, these are user facing errors */
500  if (SlotIsPhysical(slot))
501  ereport(ERROR,
502  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
503  errmsg("cannot use physical replication slot for logical decoding")));
504 
505  if (slot->data.database != MyDatabaseId)
506  ereport(ERROR,
507  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
508  errmsg("replication slot \"%s\" was not created in this database",
509  NameStr(slot->data.name))));
510 
511  if (start_lsn == InvalidXLogRecPtr)
512  {
513  /* continue from last position */
514  start_lsn = slot->data.confirmed_flush;
515  }
516  else if (start_lsn < slot->data.confirmed_flush)
517  {
518  /*
519  * It might seem like we should error out in this case, but it's
520  * pretty common for a client to acknowledge a LSN it doesn't have to
521  * do anything for, and thus didn't store persistently, because the
522  * xlog records didn't result in anything relevant for logical
523  * decoding. Clients have to be able to do that to support synchronous
524  * replication.
525  */
526  elog(DEBUG1, "cannot stream from %X/%X, minimum is %X/%X, forwarding",
527  LSN_FORMAT_ARGS(start_lsn),
529 
530  start_lsn = slot->data.confirmed_flush;
531  }
532 
533  ctx = StartupDecodingContext(output_plugin_options,
534  start_lsn, InvalidTransactionId, false,
535  fast_forward, page_read, cleanup_cb,
536  prepare_write, do_write, update_progress);
537 
538  /* call output plugin initialization callback */
539  old_context = MemoryContextSwitchTo(ctx->context);
540  if (ctx->callbacks.startup_cb != NULL)
541  startup_cb_wrapper(ctx, &ctx->options, false);
542  MemoryContextSwitchTo(old_context);
543 
544  /*
545  * We allow decoding of prepared transactions iff the two_phase option is
546  * enabled at the time of slot creation.
547  */
549 
551 
552  ereport(LOG,
553  (errmsg("starting logical decoding for slot \"%s\"",
554  NameStr(slot->data.name)),
555  errdetail("Streaming transactions committing after %X/%X, reading WAL from %X/%X.",
557  LSN_FORMAT_ARGS(slot->data.restart_lsn))));
558 
559  return ctx;
560 }
561 
562 /*
563  * Returns true if a consistent initial decoding snapshot has been built.
564  */
565 bool
567 {
569 }
570 
571 /*
572  * Read from the decoding slot, until it is ready to start extracting changes.
573  */
574 void
576 {
577  ReplicationSlot *slot = ctx->slot;
578 
579  /* Initialize from where to start reading WAL. */
580  XLogBeginRead(ctx->reader, slot->data.restart_lsn);
581 
582  elog(DEBUG1, "searching for logical decoding starting point, starting at %X/%X",
584 
585  /* Wait for a consistent starting point */
586  for (;;)
587  {
588  XLogRecord *record;
589  char *err = NULL;
590 
591  /* the read_page callback waits for new WAL */
592  while (XLogReadRecord(ctx->reader, &record, &err) ==
594  {
595  if (!ctx->page_read(ctx->reader))
596  break;
597  }
598 
599  if (err)
600  elog(ERROR, "%s", err);
601  if (!record)
602  elog(ERROR, "no record found"); /* shouldn't happen */
603 
605 
606  /* only continue till we found a consistent spot */
607  if (DecodingContextReady(ctx))
608  break;
609 
611  }
612 
613  SpinLockAcquire(&slot->mutex);
614  slot->data.confirmed_flush = ctx->reader->EndRecPtr;
616  SpinLockRelease(&slot->mutex);
617 }
618 
619 /*
620  * Free a previously allocated decoding context, invoking the shutdown
621  * callback if necessary.
622  */
623 void
625 {
626  if (ctx->callbacks.shutdown_cb != NULL)
627  shutdown_cb_wrapper(ctx);
628 
631  XLogReaderFree(ctx->reader);
633 }
634 
635 /*
636  * Prepare a write using the context's output routine.
637  */
638 void
640 {
641  if (!ctx->accept_writes)
642  elog(ERROR, "writes are only accepted in commit, begin and change callbacks");
643 
644  ctx->prepare_write(ctx, ctx->write_location, ctx->write_xid, last_write);
645  ctx->prepared_write = true;
646 }
647 
648 /*
649  * Perform a write using the context's output routine.
650  */
651 void
653 {
654  if (!ctx->prepared_write)
655  elog(ERROR, "OutputPluginPrepareWrite needs to be called before OutputPluginWrite");
656 
657  ctx->write(ctx, ctx->write_location, ctx->write_xid, last_write);
658  ctx->prepared_write = false;
659 }
660 
661 /*
662  * Update progress tracking (if supported).
663  */
664 void
666 {
667  if (!ctx->update_progress)
668  return;
669 
670  ctx->update_progress(ctx, ctx->write_location, ctx->write_xid);
671 }
672 
673 /*
674  * Load the output plugin, lookup its output plugin init function, and check
675  * that it provides the required callbacks.
676  */
677 static void
679 {
680  LogicalOutputPluginInit plugin_init;
681 
682  plugin_init = (LogicalOutputPluginInit)
683  load_external_function(plugin, "_PG_output_plugin_init", false, NULL);
684 
685  if (plugin_init == NULL)
686  elog(ERROR, "output plugins have to declare the _PG_output_plugin_init symbol");
687 
688  /* ask the output plugin to fill the callback struct */
689  plugin_init(callbacks);
690 
691  if (callbacks->begin_cb == NULL)
692  elog(ERROR, "output plugins have to register a begin callback");
693  if (callbacks->change_cb == NULL)
694  elog(ERROR, "output plugins have to register a change callback");
695  if (callbacks->commit_cb == NULL)
696  elog(ERROR, "output plugins have to register a commit callback");
697 }
698 
699 static void
701 {
703 
704  /* not all callbacks have an associated LSN */
705  if (state->report_location != InvalidXLogRecPtr)
706  errcontext("slot \"%s\", output plugin \"%s\", in the %s callback, associated LSN %X/%X",
707  NameStr(state->ctx->slot->data.name),
708  NameStr(state->ctx->slot->data.plugin),
709  state->callback_name,
711  else
712  errcontext("slot \"%s\", output plugin \"%s\", in the %s callback",
713  NameStr(state->ctx->slot->data.name),
714  NameStr(state->ctx->slot->data.plugin),
715  state->callback_name);
716 }
717 
718 static void
720 {
722  ErrorContextCallback errcallback;
723 
724  Assert(!ctx->fast_forward);
725 
726  /* Push callback + info on the error context stack */
727  state.ctx = ctx;
728  state.callback_name = "startup";
731  errcallback.arg = (void *) &state;
732  errcallback.previous = error_context_stack;
733  error_context_stack = &errcallback;
734 
735  /* set output state */
736  ctx->accept_writes = false;
737 
738  /* do the actual work: call callback */
739  ctx->callbacks.startup_cb(ctx, opt, is_init);
740 
741  /* Pop the error context stack */
742  error_context_stack = errcallback.previous;
743 }
744 
745 static void
747 {
749  ErrorContextCallback errcallback;
750 
751  Assert(!ctx->fast_forward);
752 
753  /* Push callback + info on the error context stack */
754  state.ctx = ctx;
755  state.callback_name = "shutdown";
758  errcallback.arg = (void *) &state;
759  errcallback.previous = error_context_stack;
760  error_context_stack = &errcallback;
761 
762  /* set output state */
763  ctx->accept_writes = false;
764 
765  /* do the actual work: call callback */
766  ctx->callbacks.shutdown_cb(ctx);
767 
768  /* Pop the error context stack */
769  error_context_stack = errcallback.previous;
770 }
771 
772 
773 /*
774  * Callbacks for ReorderBuffer which add in some more information and then call
775  * output_plugin.h plugins.
776  */
777 static void
779 {
782  ErrorContextCallback errcallback;
783 
784  Assert(!ctx->fast_forward);
785 
786  /* Push callback + info on the error context stack */
787  state.ctx = ctx;
788  state.callback_name = "begin";
789  state.report_location = txn->first_lsn;
791  errcallback.arg = (void *) &state;
792  errcallback.previous = error_context_stack;
793  error_context_stack = &errcallback;
794 
795  /* set output state */
796  ctx->accept_writes = true;
797  ctx->write_xid = txn->xid;
798  ctx->write_location = txn->first_lsn;
799 
800  /* do the actual work: call callback */
801  ctx->callbacks.begin_cb(ctx, txn);
802 
803  /* Pop the error context stack */
804  error_context_stack = errcallback.previous;
805 }
806 
807 static void
809  XLogRecPtr commit_lsn)
810 {
813  ErrorContextCallback errcallback;
814 
815  Assert(!ctx->fast_forward);
816 
817  /* Push callback + info on the error context stack */
818  state.ctx = ctx;
819  state.callback_name = "commit";
820  state.report_location = txn->final_lsn; /* beginning of commit record */
822  errcallback.arg = (void *) &state;
823  errcallback.previous = error_context_stack;
824  error_context_stack = &errcallback;
825 
826  /* set output state */
827  ctx->accept_writes = true;
828  ctx->write_xid = txn->xid;
829  ctx->write_location = txn->end_lsn; /* points to the end of the record */
830 
831  /* do the actual work: call callback */
832  ctx->callbacks.commit_cb(ctx, txn, commit_lsn);
833 
834  /* Pop the error context stack */
835  error_context_stack = errcallback.previous;
836 }
837 
838 /*
839  * The functionality of begin_prepare is quite similar to begin with the
840  * exception that this will have gid (global transaction id) information which
841  * can be used by plugin. Now, we thought about extending the existing begin
842  * but that would break the replication protocol and additionally this looks
843  * cleaner.
844  */
845 static void
847 {
850  ErrorContextCallback errcallback;
851 
852  Assert(!ctx->fast_forward);
853 
854  /* We're only supposed to call this when two-phase commits are supported */
855  Assert(ctx->twophase);
856 
857  /* Push callback + info on the error context stack */
858  state.ctx = ctx;
859  state.callback_name = "begin_prepare";
860  state.report_location = txn->first_lsn;
862  errcallback.arg = (void *) &state;
863  errcallback.previous = error_context_stack;
864  error_context_stack = &errcallback;
865 
866  /* set output state */
867  ctx->accept_writes = true;
868  ctx->write_xid = txn->xid;
869  ctx->write_location = txn->first_lsn;
870 
871  /*
872  * If the plugin supports two-phase commits then begin prepare callback is
873  * mandatory
874  */
875  if (ctx->callbacks.begin_prepare_cb == NULL)
876  ereport(ERROR,
877  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
878  errmsg("logical replication at prepare time requires begin_prepare_cb callback")));
879 
880  /* do the actual work: call callback */
881  ctx->callbacks.begin_prepare_cb(ctx, txn);
882 
883  /* Pop the error context stack */
884  error_context_stack = errcallback.previous;
885 }
886 
887 static void
889  XLogRecPtr prepare_lsn)
890 {
893  ErrorContextCallback errcallback;
894 
895  Assert(!ctx->fast_forward);
896 
897  /* We're only supposed to call this when two-phase commits are supported */
898  Assert(ctx->twophase);
899 
900  /* Push callback + info on the error context stack */
901  state.ctx = ctx;
902  state.callback_name = "prepare";
903  state.report_location = txn->final_lsn; /* beginning of prepare record */
905  errcallback.arg = (void *) &state;
906  errcallback.previous = error_context_stack;
907  error_context_stack = &errcallback;
908 
909  /* set output state */
910  ctx->accept_writes = true;
911  ctx->write_xid = txn->xid;
912  ctx->write_location = txn->end_lsn; /* points to the end of the record */
913 
914  /*
915  * If the plugin supports two-phase commits then prepare callback is
916  * mandatory
917  */
918  if (ctx->callbacks.prepare_cb == NULL)
919  ereport(ERROR,
920  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
921  errmsg("logical replication at prepare time requires prepare_cb callback")));
922 
923  /* do the actual work: call callback */
924  ctx->callbacks.prepare_cb(ctx, txn, prepare_lsn);
925 
926  /* Pop the error context stack */
927  error_context_stack = errcallback.previous;
928 }
929 
930 static void
932  XLogRecPtr commit_lsn)
933 {
936  ErrorContextCallback errcallback;
937 
938  Assert(!ctx->fast_forward);
939 
940  /* We're only supposed to call this when two-phase commits are supported */
941  Assert(ctx->twophase);
942 
943  /* Push callback + info on the error context stack */
944  state.ctx = ctx;
945  state.callback_name = "commit_prepared";
946  state.report_location = txn->final_lsn; /* beginning of commit record */
948  errcallback.arg = (void *) &state;
949  errcallback.previous = error_context_stack;
950  error_context_stack = &errcallback;
951 
952  /* set output state */
953  ctx->accept_writes = true;
954  ctx->write_xid = txn->xid;
955  ctx->write_location = txn->end_lsn; /* points to the end of the record */
956 
957  /*
958  * If the plugin support two-phase commits then commit prepared callback
959  * is mandatory
960  */
961  if (ctx->callbacks.commit_prepared_cb == NULL)
962  ereport(ERROR,
963  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
964  errmsg("logical replication at prepare time requires commit_prepared_cb callback")));
965 
966  /* do the actual work: call callback */
967  ctx->callbacks.commit_prepared_cb(ctx, txn, commit_lsn);
968 
969  /* Pop the error context stack */
970  error_context_stack = errcallback.previous;
971 }
972 
973 static void
975  XLogRecPtr prepare_end_lsn,
976  TimestampTz prepare_time)
977 {
980  ErrorContextCallback errcallback;
981 
982  Assert(!ctx->fast_forward);
983 
984  /* We're only supposed to call this when two-phase commits are supported */
985  Assert(ctx->twophase);
986 
987  /* Push callback + info on the error context stack */
988  state.ctx = ctx;
989  state.callback_name = "rollback_prepared";
990  state.report_location = txn->final_lsn; /* beginning of commit record */
992  errcallback.arg = (void *) &state;
993  errcallback.previous = error_context_stack;
994  error_context_stack = &errcallback;
995 
996  /* set output state */
997  ctx->accept_writes = true;
998  ctx->write_xid = txn->xid;
999  ctx->write_location = txn->end_lsn; /* points to the end of the record */
1000 
1001  /*
1002  * If the plugin support two-phase commits then rollback prepared callback
1003  * is mandatory
1004  */
1005  if (ctx->callbacks.rollback_prepared_cb == NULL)
1006  ereport(ERROR,
1007  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1008  errmsg("logical replication at prepare time requires rollback_prepared_cb callback")));
1009 
1010  /* do the actual work: call callback */
1011  ctx->callbacks.rollback_prepared_cb(ctx, txn, prepare_end_lsn,
1012  prepare_time);
1013 
1014  /* Pop the error context stack */
1015  error_context_stack = errcallback.previous;
1016 }
1017 
1018 static void
1020  Relation relation, ReorderBufferChange *change)
1021 {
1024  ErrorContextCallback errcallback;
1025 
1026  Assert(!ctx->fast_forward);
1027 
1028  /* Push callback + info on the error context stack */
1029  state.ctx = ctx;
1030  state.callback_name = "change";
1031  state.report_location = change->lsn;
1032  errcallback.callback = output_plugin_error_callback;
1033  errcallback.arg = (void *) &state;
1034  errcallback.previous = error_context_stack;
1035  error_context_stack = &errcallback;
1036 
1037  /* set output state */
1038  ctx->accept_writes = true;
1039  ctx->write_xid = txn->xid;
1040 
1041  /*
1042  * report this change's lsn so replies from clients can give an up2date
1043  * answer. This won't ever be enough (and shouldn't be!) to confirm
1044  * receipt of this transaction, but it might allow another transaction's
1045  * commit to be confirmed with one message.
1046  */
1047  ctx->write_location = change->lsn;
1048 
1049  ctx->callbacks.change_cb(ctx, txn, relation, change);
1050 
1051  /* Pop the error context stack */
1052  error_context_stack = errcallback.previous;
1053 }
1054 
1055 static void
1057  int nrelations, Relation relations[], ReorderBufferChange *change)
1058 {
1061  ErrorContextCallback errcallback;
1062 
1063  Assert(!ctx->fast_forward);
1064 
1065  if (!ctx->callbacks.truncate_cb)
1066  return;
1067 
1068  /* Push callback + info on the error context stack */
1069  state.ctx = ctx;
1070  state.callback_name = "truncate";
1071  state.report_location = change->lsn;
1072  errcallback.callback = output_plugin_error_callback;
1073  errcallback.arg = (void *) &state;
1074  errcallback.previous = error_context_stack;
1075  error_context_stack = &errcallback;
1076 
1077  /* set output state */
1078  ctx->accept_writes = true;
1079  ctx->write_xid = txn->xid;
1080 
1081  /*
1082  * report this change's lsn so replies from clients can give an up2date
1083  * answer. This won't ever be enough (and shouldn't be!) to confirm
1084  * receipt of this transaction, but it might allow another transaction's
1085  * commit to be confirmed with one message.
1086  */
1087  ctx->write_location = change->lsn;
1088 
1089  ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change);
1090 
1091  /* Pop the error context stack */
1092  error_context_stack = errcallback.previous;
1093 }
1094 
1095 bool
1097  const char *gid)
1098 {
1100  ErrorContextCallback errcallback;
1101  bool ret;
1102 
1103  Assert(!ctx->fast_forward);
1104 
1105  /* Push callback + info on the error context stack */
1106  state.ctx = ctx;
1107  state.callback_name = "filter_prepare";
1109  errcallback.callback = output_plugin_error_callback;
1110  errcallback.arg = (void *) &state;
1111  errcallback.previous = error_context_stack;
1112  error_context_stack = &errcallback;
1113 
1114  /* set output state */
1115  ctx->accept_writes = false;
1116 
1117  /* do the actual work: call callback */
1118  ret = ctx->callbacks.filter_prepare_cb(ctx, xid, gid);
1119 
1120  /* Pop the error context stack */
1121  error_context_stack = errcallback.previous;
1122 
1123  return ret;
1124 }
1125 
1126 bool
1128 {
1130  ErrorContextCallback errcallback;
1131  bool ret;
1132 
1133  Assert(!ctx->fast_forward);
1134 
1135  /* Push callback + info on the error context stack */
1136  state.ctx = ctx;
1137  state.callback_name = "filter_by_origin";
1139  errcallback.callback = output_plugin_error_callback;
1140  errcallback.arg = (void *) &state;
1141  errcallback.previous = error_context_stack;
1142  error_context_stack = &errcallback;
1143 
1144  /* set output state */
1145  ctx->accept_writes = false;
1146 
1147  /* do the actual work: call callback */
1148  ret = ctx->callbacks.filter_by_origin_cb(ctx, origin_id);
1149 
1150  /* Pop the error context stack */
1151  error_context_stack = errcallback.previous;
1152 
1153  return ret;
1154 }
1155 
1156 static void
1158  XLogRecPtr message_lsn, bool transactional,
1159  const char *prefix, Size message_size, const char *message)
1160 {
1163  ErrorContextCallback errcallback;
1164 
1165  Assert(!ctx->fast_forward);
1166 
1167  if (ctx->callbacks.message_cb == NULL)
1168  return;
1169 
1170  /* Push callback + info on the error context stack */
1171  state.ctx = ctx;
1172  state.callback_name = "message";
1173  state.report_location = message_lsn;
1174  errcallback.callback = output_plugin_error_callback;
1175  errcallback.arg = (void *) &state;
1176  errcallback.previous = error_context_stack;
1177  error_context_stack = &errcallback;
1178 
1179  /* set output state */
1180  ctx->accept_writes = true;
1181  ctx->write_xid = txn != NULL ? txn->xid : InvalidTransactionId;
1182  ctx->write_location = message_lsn;
1183 
1184  /* do the actual work: call callback */
1185  ctx->callbacks.message_cb(ctx, txn, message_lsn, transactional, prefix,
1186  message_size, message);
1187 
1188  /* Pop the error context stack */
1189  error_context_stack = errcallback.previous;
1190 }
1191 
1192 static void
1194  XLogRecPtr first_lsn)
1195 {
1198  ErrorContextCallback errcallback;
1199 
1200  Assert(!ctx->fast_forward);
1201 
1202  /* We're only supposed to call this when streaming is supported. */
1203  Assert(ctx->streaming);
1204 
1205  /* Push callback + info on the error context stack */
1206  state.ctx = ctx;
1207  state.callback_name = "stream_start";
1208  state.report_location = first_lsn;
1209  errcallback.callback = output_plugin_error_callback;
1210  errcallback.arg = (void *) &state;
1211  errcallback.previous = error_context_stack;
1212  error_context_stack = &errcallback;
1213 
1214  /* set output state */
1215  ctx->accept_writes = true;
1216  ctx->write_xid = txn->xid;
1217 
1218  /*
1219  * report this message's lsn so replies from clients can give an up2date
1220  * answer. This won't ever be enough (and shouldn't be!) to confirm
1221  * receipt of this transaction, but it might allow another transaction's
1222  * commit to be confirmed with one message.
1223  */
1224  ctx->write_location = first_lsn;
1225 
1226  /* in streaming mode, stream_start_cb is required */
1227  if (ctx->callbacks.stream_start_cb == NULL)
1228  ereport(ERROR,
1229  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1230  errmsg("logical streaming requires a stream_start_cb callback")));
1231 
1232  ctx->callbacks.stream_start_cb(ctx, txn);
1233 
1234  /* Pop the error context stack */
1235  error_context_stack = errcallback.previous;
1236 }
1237 
1238 static void
1240  XLogRecPtr last_lsn)
1241 {
1244  ErrorContextCallback errcallback;
1245 
1246  Assert(!ctx->fast_forward);
1247 
1248  /* We're only supposed to call this when streaming is supported. */
1249  Assert(ctx->streaming);
1250 
1251  /* Push callback + info on the error context stack */
1252  state.ctx = ctx;
1253  state.callback_name = "stream_stop";
1254  state.report_location = last_lsn;
1255  errcallback.callback = output_plugin_error_callback;
1256  errcallback.arg = (void *) &state;
1257  errcallback.previous = error_context_stack;
1258  error_context_stack = &errcallback;
1259 
1260  /* set output state */
1261  ctx->accept_writes = true;
1262  ctx->write_xid = txn->xid;
1263 
1264  /*
1265  * report this message's lsn so replies from clients can give an up2date
1266  * answer. This won't ever be enough (and shouldn't be!) to confirm
1267  * receipt of this transaction, but it might allow another transaction's
1268  * commit to be confirmed with one message.
1269  */
1270  ctx->write_location = last_lsn;
1271 
1272  /* in streaming mode, stream_stop_cb is required */
1273  if (ctx->callbacks.stream_stop_cb == NULL)
1274  ereport(ERROR,
1275  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1276  errmsg("logical streaming requires a stream_stop_cb callback")));
1277 
1278  ctx->callbacks.stream_stop_cb(ctx, txn);
1279 
1280  /* Pop the error context stack */
1281  error_context_stack = errcallback.previous;
1282 }
1283 
1284 static void
1286  XLogRecPtr abort_lsn)
1287 {
1290  ErrorContextCallback errcallback;
1291 
1292  Assert(!ctx->fast_forward);
1293 
1294  /* We're only supposed to call this when streaming is supported. */
1295  Assert(ctx->streaming);
1296 
1297  /* Push callback + info on the error context stack */
1298  state.ctx = ctx;
1299  state.callback_name = "stream_abort";
1300  state.report_location = abort_lsn;
1301  errcallback.callback = output_plugin_error_callback;
1302  errcallback.arg = (void *) &state;
1303  errcallback.previous = error_context_stack;
1304  error_context_stack = &errcallback;
1305 
1306  /* set output state */
1307  ctx->accept_writes = true;
1308  ctx->write_xid = txn->xid;
1309  ctx->write_location = abort_lsn;
1310 
1311  /* in streaming mode, stream_abort_cb is required */
1312  if (ctx->callbacks.stream_abort_cb == NULL)
1313  ereport(ERROR,
1314  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1315  errmsg("logical streaming requires a stream_abort_cb callback")));
1316 
1317  ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn);
1318 
1319  /* Pop the error context stack */
1320  error_context_stack = errcallback.previous;
1321 }
1322 
1323 static void
1325  XLogRecPtr prepare_lsn)
1326 {
1329  ErrorContextCallback errcallback;
1330 
1331  Assert(!ctx->fast_forward);
1332 
1333  /*
1334  * We're only supposed to call this when streaming and two-phase commits
1335  * are supported.
1336  */
1337  Assert(ctx->streaming);
1338  Assert(ctx->twophase);
1339 
1340  /* Push callback + info on the error context stack */
1341  state.ctx = ctx;
1342  state.callback_name = "stream_prepare";
1343  state.report_location = txn->final_lsn;
1344  errcallback.callback = output_plugin_error_callback;
1345  errcallback.arg = (void *) &state;
1346  errcallback.previous = error_context_stack;
1347  error_context_stack = &errcallback;
1348 
1349  /* set output state */
1350  ctx->accept_writes = true;
1351  ctx->write_xid = txn->xid;
1352  ctx->write_location = txn->end_lsn;
1353 
1354  /* in streaming mode with two-phase commits, stream_prepare_cb is required */
1355  if (ctx->callbacks.stream_prepare_cb == NULL)
1356  ereport(ERROR,
1357  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1358  errmsg("logical streaming at prepare time requires a stream_prepare_cb callback")));
1359 
1360  ctx->callbacks.stream_prepare_cb(ctx, txn, prepare_lsn);
1361 
1362  /* Pop the error context stack */
1363  error_context_stack = errcallback.previous;
1364 }
1365 
1366 static void
1368  XLogRecPtr commit_lsn)
1369 {
1372  ErrorContextCallback errcallback;
1373 
1374  Assert(!ctx->fast_forward);
1375 
1376  /* We're only supposed to call this when streaming is supported. */
1377  Assert(ctx->streaming);
1378 
1379  /* Push callback + info on the error context stack */
1380  state.ctx = ctx;
1381  state.callback_name = "stream_commit";
1382  state.report_location = txn->final_lsn;
1383  errcallback.callback = output_plugin_error_callback;
1384  errcallback.arg = (void *) &state;
1385  errcallback.previous = error_context_stack;
1386  error_context_stack = &errcallback;
1387 
1388  /* set output state */
1389  ctx->accept_writes = true;
1390  ctx->write_xid = txn->xid;
1391  ctx->write_location = txn->end_lsn;
1392 
1393  /* in streaming mode, stream_commit_cb is required */
1394  if (ctx->callbacks.stream_commit_cb == NULL)
1395  ereport(ERROR,
1396  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1397  errmsg("logical streaming requires a stream_commit_cb callback")));
1398 
1399  ctx->callbacks.stream_commit_cb(ctx, txn, commit_lsn);
1400 
1401  /* Pop the error context stack */
1402  error_context_stack = errcallback.previous;
1403 }
1404 
1405 static void
1407  Relation relation, ReorderBufferChange *change)
1408 {
1411  ErrorContextCallback errcallback;
1412 
1413  Assert(!ctx->fast_forward);
1414 
1415  /* We're only supposed to call this when streaming is supported. */
1416  Assert(ctx->streaming);
1417 
1418  /* Push callback + info on the error context stack */
1419  state.ctx = ctx;
1420  state.callback_name = "stream_change";
1421  state.report_location = change->lsn;
1422  errcallback.callback = output_plugin_error_callback;
1423  errcallback.arg = (void *) &state;
1424  errcallback.previous = error_context_stack;
1425  error_context_stack = &errcallback;
1426 
1427  /* set output state */
1428  ctx->accept_writes = true;
1429  ctx->write_xid = txn->xid;
1430 
1431  /*
1432  * report this change's lsn so replies from clients can give an up2date
1433  * answer. This won't ever be enough (and shouldn't be!) to confirm
1434  * receipt of this transaction, but it might allow another transaction's
1435  * commit to be confirmed with one message.
1436  */
1437  ctx->write_location = change->lsn;
1438 
1439  /* in streaming mode, stream_change_cb is required */
1440  if (ctx->callbacks.stream_change_cb == NULL)
1441  ereport(ERROR,
1442  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1443  errmsg("logical streaming requires a stream_change_cb callback")));
1444 
1445  ctx->callbacks.stream_change_cb(ctx, txn, relation, change);
1446 
1447  /* Pop the error context stack */
1448  error_context_stack = errcallback.previous;
1449 }
1450 
1451 static void
1453  XLogRecPtr message_lsn, bool transactional,
1454  const char *prefix, Size message_size, const char *message)
1455 {
1458  ErrorContextCallback errcallback;
1459 
1460  Assert(!ctx->fast_forward);
1461 
1462  /* We're only supposed to call this when streaming is supported. */
1463  Assert(ctx->streaming);
1464 
1465  /* this callback is optional */
1466  if (ctx->callbacks.stream_message_cb == NULL)
1467  return;
1468 
1469  /* Push callback + info on the error context stack */
1470  state.ctx = ctx;
1471  state.callback_name = "stream_message";
1472  state.report_location = message_lsn;
1473  errcallback.callback = output_plugin_error_callback;
1474  errcallback.arg = (void *) &state;
1475  errcallback.previous = error_context_stack;
1476  error_context_stack = &errcallback;
1477 
1478  /* set output state */
1479  ctx->accept_writes = true;
1480  ctx->write_xid = txn != NULL ? txn->xid : InvalidTransactionId;
1481  ctx->write_location = message_lsn;
1482 
1483  /* do the actual work: call callback */
1484  ctx->callbacks.stream_message_cb(ctx, txn, message_lsn, transactional, prefix,
1485  message_size, message);
1486 
1487  /* Pop the error context stack */
1488  error_context_stack = errcallback.previous;
1489 }
1490 
1491 static void
1493  int nrelations, Relation relations[],
1494  ReorderBufferChange *change)
1495 {
1498  ErrorContextCallback errcallback;
1499 
1500  Assert(!ctx->fast_forward);
1501 
1502  /* We're only supposed to call this when streaming is supported. */
1503  Assert(ctx->streaming);
1504 
1505  /* this callback is optional */
1506  if (!ctx->callbacks.stream_truncate_cb)
1507  return;
1508 
1509  /* Push callback + info on the error context stack */
1510  state.ctx = ctx;
1511  state.callback_name = "stream_truncate";
1512  state.report_location = change->lsn;
1513  errcallback.callback = output_plugin_error_callback;
1514  errcallback.arg = (void *) &state;
1515  errcallback.previous = error_context_stack;
1516  error_context_stack = &errcallback;
1517 
1518  /* set output state */
1519  ctx->accept_writes = true;
1520  ctx->write_xid = txn->xid;
1521 
1522  /*
1523  * report this change's lsn so replies from clients can give an up2date
1524  * answer. This won't ever be enough (and shouldn't be!) to confirm
1525  * receipt of this transaction, but it might allow another transaction's
1526  * commit to be confirmed with one message.
1527  */
1528  ctx->write_location = change->lsn;
1529 
1530  ctx->callbacks.stream_truncate_cb(ctx, txn, nrelations, relations, change);
1531 
1532  /* Pop the error context stack */
1533  error_context_stack = errcallback.previous;
1534 }
1535 
1536 /*
1537  * Set the required catalog xmin horizon for historic snapshots in the current
1538  * replication slot.
1539  *
1540  * Note that in the most cases, we won't be able to immediately use the xmin
1541  * to increase the xmin horizon: we need to wait till the client has confirmed
1542  * receiving current_lsn with LogicalConfirmReceivedLocation().
1543  */
1544 void
1546 {
1547  bool updated_xmin = false;
1548  ReplicationSlot *slot;
1549 
1550  slot = MyReplicationSlot;
1551 
1552  Assert(slot != NULL);
1553 
1554  SpinLockAcquire(&slot->mutex);
1555 
1556  /*
1557  * don't overwrite if we already have a newer xmin. This can happen if we
1558  * restart decoding in a slot.
1559  */
1561  {
1562  }
1563 
1564  /*
1565  * If the client has already confirmed up to this lsn, we directly can
1566  * mark this as accepted. This can happen if we restart decoding in a
1567  * slot.
1568  */
1569  else if (current_lsn <= slot->data.confirmed_flush)
1570  {
1571  slot->candidate_catalog_xmin = xmin;
1572  slot->candidate_xmin_lsn = current_lsn;
1573 
1574  /* our candidate can directly be used */
1575  updated_xmin = true;
1576  }
1577 
1578  /*
1579  * Only increase if the previous values have been applied, otherwise we
1580  * might never end up updating if the receiver acks too slowly.
1581  */
1582  else if (slot->candidate_xmin_lsn == InvalidXLogRecPtr)
1583  {
1584  slot->candidate_catalog_xmin = xmin;
1585  slot->candidate_xmin_lsn = current_lsn;
1586  }
1587  SpinLockRelease(&slot->mutex);
1588 
1589  /* candidate already valid with the current flush position, apply */
1590  if (updated_xmin)
1592 }
1593 
1594 /*
1595  * Mark the minimal LSN (restart_lsn) we need to read to replay all
1596  * transactions that have not yet committed at current_lsn.
1597  *
1598  * Just like LogicalIncreaseXminForSlot this only takes effect when the
1599  * client has confirmed to have received current_lsn.
1600  */
1601 void
1603 {
1604  bool updated_lsn = false;
1605  ReplicationSlot *slot;
1606 
1607  slot = MyReplicationSlot;
1608 
1609  Assert(slot != NULL);
1610  Assert(restart_lsn != InvalidXLogRecPtr);
1611  Assert(current_lsn != InvalidXLogRecPtr);
1612 
1613  SpinLockAcquire(&slot->mutex);
1614 
1615  /* don't overwrite if have a newer restart lsn */
1616  if (restart_lsn <= slot->data.restart_lsn)
1617  {
1618  }
1619 
1620  /*
1621  * We might have already flushed far enough to directly accept this lsn,
1622  * in this case there is no need to check for existing candidate LSNs
1623  */
1624  else if (current_lsn <= slot->data.confirmed_flush)
1625  {
1626  slot->candidate_restart_valid = current_lsn;
1627  slot->candidate_restart_lsn = restart_lsn;
1628 
1629  /* our candidate can directly be used */
1630  updated_lsn = true;
1631  }
1632 
1633  /*
1634  * Only increase if the previous values have been applied, otherwise we
1635  * might never end up updating if the receiver acks too slowly. A missed
1636  * value here will just cause some extra effort after reconnecting.
1637  */
1639  {
1640  slot->candidate_restart_valid = current_lsn;
1641  slot->candidate_restart_lsn = restart_lsn;
1642  SpinLockRelease(&slot->mutex);
1643 
1644  elog(DEBUG1, "got new restart lsn %X/%X at %X/%X",
1645  LSN_FORMAT_ARGS(restart_lsn),
1646  LSN_FORMAT_ARGS(current_lsn));
1647  }
1648  else
1649  {
1650  XLogRecPtr candidate_restart_lsn;
1651  XLogRecPtr candidate_restart_valid;
1652  XLogRecPtr confirmed_flush;
1653 
1654  candidate_restart_lsn = slot->candidate_restart_lsn;
1655  candidate_restart_valid = slot->candidate_restart_valid;
1656  confirmed_flush = slot->data.confirmed_flush;
1657  SpinLockRelease(&slot->mutex);
1658 
1659  elog(DEBUG1, "failed to increase restart lsn: proposed %X/%X, after %X/%X, current candidate %X/%X, current after %X/%X, flushed up to %X/%X",
1660  LSN_FORMAT_ARGS(restart_lsn),
1661  LSN_FORMAT_ARGS(current_lsn),
1662  LSN_FORMAT_ARGS(candidate_restart_lsn),
1663  LSN_FORMAT_ARGS(candidate_restart_valid),
1664  LSN_FORMAT_ARGS(confirmed_flush));
1665  }
1666 
1667  /* candidates are already valid with the current flush position, apply */
1668  if (updated_lsn)
1670 }
1671 
1672 /*
1673  * Handle a consumer's confirmation having received all changes up to lsn.
1674  */
1675 void
1677 {
1678  Assert(lsn != InvalidXLogRecPtr);
1679 
1680  /* Do an unlocked check for candidate_lsn first. */
1683  {
1684  bool updated_xmin = false;
1685  bool updated_restart = false;
1686 
1688 
1690 
1691  /* if we're past the location required for bumping xmin, do so */
1694  {
1695  /*
1696  * We have to write the changed xmin to disk *before* we change
1697  * the in-memory value, otherwise after a crash we wouldn't know
1698  * that some catalog tuples might have been removed already.
1699  *
1700  * Ensure that by first writing to ->xmin and only update
1701  * ->effective_xmin once the new state is synced to disk. After a
1702  * crash ->effective_xmin is set to ->xmin.
1703  */
1706  {
1710  updated_xmin = true;
1711  }
1712  }
1713 
1716  {
1718 
1722  updated_restart = true;
1723  }
1724 
1726 
1727  /* first write new xmin to disk, so we know what's up after a crash */
1728  if (updated_xmin || updated_restart)
1729  {
1732  elog(DEBUG1, "updated xmin: %u restart: %u", updated_xmin, updated_restart);
1733  }
1734 
1735  /*
1736  * Now the new xmin is safely on disk, we can let the global value
1737  * advance. We do not take ProcArrayLock or similar since we only
1738  * advance xmin here and there's not much harm done by a concurrent
1739  * computation missing that.
1740  */
1741  if (updated_xmin)
1742  {
1746 
1749  }
1750  }
1751  else
1752  {
1756  }
1757 }
1758 
1759 /*
1760  * Clear logical streaming state during (sub)transaction abort.
1761  */
1762 void
1764 {
1766  bsysscan = false;
1767 }
1768 
1769 /*
1770  * Report stats for a slot.
1771  */
1772 void
1774 {
1775  ReorderBuffer *rb = ctx->reorder;
1776  PgStat_StatReplSlotEntry repSlotStat;
1777 
1778  /* Nothing to do if we don't have any replication stats to be sent. */
1779  if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0)
1780  return;
1781 
1782  elog(DEBUG2, "UpdateDecodingStats: updating stats %p %lld %lld %lld %lld %lld %lld %lld %lld",
1783  rb,
1784  (long long) rb->spillTxns,
1785  (long long) rb->spillCount,
1786  (long long) rb->spillBytes,
1787  (long long) rb->streamTxns,
1788  (long long) rb->streamCount,
1789  (long long) rb->streamBytes,
1790  (long long) rb->totalTxns,
1791  (long long) rb->totalBytes);
1792 
1793  namestrcpy(&repSlotStat.slotname, NameStr(ctx->slot->data.name));
1794  repSlotStat.spill_txns = rb->spillTxns;
1795  repSlotStat.spill_count = rb->spillCount;
1796  repSlotStat.spill_bytes = rb->spillBytes;
1797  repSlotStat.stream_txns = rb->streamTxns;
1798  repSlotStat.stream_count = rb->streamCount;
1799  repSlotStat.stream_bytes = rb->streamBytes;
1800  repSlotStat.total_txns = rb->totalTxns;
1801  repSlotStat.total_bytes = rb->totalBytes;
1802 
1803  pgstat_report_replslot(&repSlotStat);
1804 
1805  rb->spillTxns = 0;
1806  rb->spillCount = 0;
1807  rb->spillBytes = 0;
1808  rb->streamTxns = 0;
1809  rb->streamCount = 0;
1810  rb->streamBytes = 0;
1811  rb->totalTxns = 0;
1812  rb->totalBytes = 0;
1813 }
XLogRecPtr first_lsn
LogicalDecodeTruncateCB truncate_cb
#define NIL
Definition: pg_list.h:65
TransactionId write_xid
Definition: logical.h:101
static void stream_stop_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr last_lsn)
Definition: logical.c:1239
static const char * plugin
void CheckSlotRequirements(void)
Definition: slot.c:1068
TransactionId candidate_catalog_xmin
Definition: slot.h:171
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
static void stream_abort_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr abort_lsn)
Definition: logical.c:1285
TransactionId GetOldestSafeDecodingTransactionId(bool catalogOnly)
Definition: procarray.c:2881
ReorderBufferApplyChangeCB apply_change
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
#define AllocSetContextCreate
Definition: memutils.h:173
void * private_data
#define DEBUG1
Definition: elog.h:25
static void change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
Definition: logical.c:1019
struct ReorderBuffer * reorder
Definition: logical.h:45
bool filter_prepare_cb_wrapper(LogicalDecodingContext *ctx, TransactionId xid, const char *gid)
Definition: logical.c:1096
#define PROC_IN_LOGICAL_DECODING
Definition: proc.h:61
int wal_segment_size
Definition: xlog.c:121
PgStat_Counter spill_bytes
Definition: pgstat.h:926
uint32 TransactionId
Definition: c.h:587
XLogReaderState * XLogReaderAllocate(int wal_segment_size, const char *waldir, WALSegmentCleanupCB cleanup_cb)
Definition: xlogreader.c:82
LogicalDecodeStreamPrepareCB stream_prepare_cb
SnapBuildState SnapBuildCurrentState(SnapBuild *builder)
Definition: snapbuild.c:367
void namestrcpy(Name name, const char *str)
Definition: name.c:233
bool DecodingContextReady(LogicalDecodingContext *ctx)
Definition: logical.c:566
PGPROC * MyProc
Definition: proc.c:68
int64 TimestampTz
Definition: timestamp.h:39
struct LogicalErrorCallbackState LogicalErrorCallbackState
static void commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: logical.c:808
OutputPluginOptions options
Definition: logical.h:56
bool(* LogicalDecodingXLogPageReadCB)(XLogReaderState *ctx)
Definition: logical.h:32
void LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart_lsn)
Definition: logical.c:1602
static void stream_prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
Definition: logical.c:1324
ReorderBufferStreamAbortCB stream_abort
int wal_level
Definition: xlog.c:109
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
LogicalDecodingContext * CreateDecodingContext(XLogRecPtr start_lsn, List *output_plugin_options, bool fast_forward, LogicalDecodingXLogPageReadCB page_read, WALSegmentCleanupCB cleanup_cb, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
Definition: logical.c:479
LogicalDecodeMessageCB message_cb
OutputPluginCallbacks callbacks
Definition: logical.h:55
LogicalDecodeStreamMessageCB stream_message_cb
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void ReorderBufferFree(ReorderBuffer *rb)
uint16 RepOriginId
Definition: xlogdefs.h:65
int errcode(int sqlerrcode)
Definition: elog.c:698
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4701
PROC_HDR * ProcGlobal
Definition: proc.c:80
MemoryContext context
Definition: logical.h:37
void ReplicationSlotSave(void)
Definition: slot.c:734
uint8 statusFlags
Definition: proc.h:189
LogicalDecodeStreamAbortCB stream_abort_cb
List * output_plugin_options
Definition: logical.h:61
ReorderBufferCommitCB commit
ReplicationSlotPersistentData data
Definition: slot.h:156
#define LOG
Definition: elog.h:26
bool RecoveryInProgress(void)
Definition: xlog.c:8237
ReorderBufferStreamCommitCB stream_commit
XLogReadRecordResult XLogReadRecord(XLogReaderState *state, XLogRecord **record, char **errormsg)
Definition: xlogreader.c:346
void(* callback)(void *arg)
Definition: elog.h:247
static LogicalDecodingContext * StartupDecodingContext(List *output_plugin_options, XLogRecPtr start_lsn, TransactionId xmin_horizon, bool need_full_snapshot, bool fast_forward, LogicalDecodingXLogPageReadCB page_read, WALSegmentCleanupCB cleanup_cb, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
Definition: logical.c:146
struct ErrorContextCallback * previous
Definition: elog.h:246
#define SlotIsPhysical(slot)
Definition: slot.h:177
LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite
Definition: logical.h:25
void(* LogicalOutputPluginWriterUpdateProgress)(struct LogicalDecodingContext *lr, XLogRecPtr Ptr, TransactionId xid)
Definition: logical.h:27
const char * callback_name
Definition: logical.c:50
static void prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
Definition: logical.c:888
XLogRecPtr confirmed_flush
Definition: slot.h:92
XLogRecPtr write_location
Definition: logical.h:100
static void rollback_prepared_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr prepare_end_lsn, TimestampTz prepare_time)
Definition: logical.c:974
XLogRecPtr EndRecPtr
Definition: xlogreader.h:179
LogicalDecodeBeginPrepareCB begin_prepare_cb
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1816
ErrorContextCallback * error_context_stack
Definition: elog.c:93
#define SpinLockAcquire(lock)
Definition: spin.h:62
#define LSN_FORMAT_ARGS(lsn)
Definition: xlogdefs.h:43
ReorderBufferStreamMessageCB stream_message
void ReplicationSlotReserveWal(void)
Definition: slot.c:1093
void DecodingContextFindStartpoint(LogicalDecodingContext *ctx)
Definition: logical.c:575
void(* WALSegmentCleanupCB)(XLogReaderState *xlogreader)
Definition: xlogreader.h:63
void ReplicationSlotsComputeRequiredLSN(void)
Definition: slot.c:841
LogicalDecodePrepareCB prepare_cb
static void stream_commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: logical.c:1367
bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
Definition: transam.c:319
#define ERROR
Definition: elog.h:46
void LogicalDecodingProcessRecord(LogicalDecodingContext *ctx, XLogReaderState *record)
Definition: decode.c:106
static void startup_cb_wrapper(LogicalDecodingContext *ctx, OutputPluginOptions *opt, bool is_init)
Definition: logical.c:719
LogicalOutputPluginWriterPrepareWrite prepare_write
Definition: logical.h:66
bool bsysscan
Definition: xact.c:96
ReorderBufferStreamPrepareCB stream_prepare
void ResetLogicalStreamingState(void)
Definition: logical.c:1763
LogicalDecodeCommitCB commit_cb
TransactionId effective_xmin
Definition: slot.h:152
void(* LogicalOutputPluginInit)(struct OutputPluginCallbacks *cb)
Definition: output_plugin.h:36
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
static void shutdown_cb_wrapper(LogicalDecodingContext *ctx)
Definition: logical.c:746
Definition: c.h:675
#define DEBUG2
Definition: elog.h:24
XLogRecPtr candidate_restart_valid
Definition: slot.h:173
int errdetail(const char *fmt,...)
Definition: elog.c:1042
PgStat_Counter total_bytes
Definition: pgstat.h:931
TransactionId catalog_xmin
Definition: slot.h:78
#define InvalidTransactionId
Definition: transam.h:31
void XLogBeginRead(XLogReaderState *state, XLogRecPtr RecPtr)
Definition: xlogreader.c:252
LogicalOutputPluginWriterUpdateProgress update_progress
Definition: logical.h:68
XLogRecPtr final_lsn
LogicalDecodeRollbackPreparedCB rollback_prepared_cb
ReorderBufferBeginCB begin_prepare
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
bool filter_by_origin_cb_wrapper(LogicalDecodingContext *ctx, RepOriginId origin_id)
Definition: logical.c:1127
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:425
ReorderBufferMessageCB message
LogicalDecodeCommitPreparedCB commit_prepared_cb
static void commit_prepared_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: logical.c:931
ReorderBufferStreamChangeCB stream_change
ReorderBufferStreamTruncateCB stream_truncate
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:107
XLogRecPtr initial_consistent_point
Definition: slot.h:99
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29
static void stream_message_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size message_size, const char *message)
Definition: logical.c:1452
TransactionId CheckXidAlive
Definition: xact.c:95
void XLogReaderFree(XLogReaderState *state)
Definition: xlogreader.c:142
#define SpinLockRelease(lock)
Definition: spin.h:64
void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx)
Definition: logical.c:665
void UpdateDecodingStats(LogicalDecodingContext *ctx)
Definition: logical.c:1773
void * palloc0(Size size)
Definition: mcxt.c:1093
static void stream_start_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr first_lsn)
Definition: logical.c:1193
LogicalDecodeChangeCB change_cb
LogicalDecodeFilterPrepareCB filter_prepare_cb
TransactionId effective_catalog_xmin
Definition: slot.h:153
LogicalDecodeStreamTruncateCB stream_truncate_cb
TransactionId xid
Oid MyDatabaseId
Definition: globals.c:88
static void stream_truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
Definition: logical.c:1492
#define InvalidOid
Definition: postgres_ext.h:36
ReorderBufferStreamStartCB stream_start
PgStat_Counter stream_bytes
Definition: pgstat.h:929
#define ereport(elevel,...)
Definition: elog.h:157
PgStat_Counter spill_txns
Definition: pgstat.h:924
void FreeSnapshotBuilder(SnapBuild *builder)
Definition: snapbuild.c:323
static void begin_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn)
Definition: logical.c:778
void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write)
Definition: logical.c:639
struct SnapBuild * snapshot_builder
Definition: logical.h:46
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:804
Definition: regguts.h:317
void FreeDecodingContext(LogicalDecodingContext *ctx)
Definition: logical.c:624
void pgstat_report_replslot(const PgStat_StatReplSlotEntry *repSlotStat)
Definition: pgstat.c:1810
XLogRecPtr restart_lsn
Definition: slot.h:81
void LogicalIncreaseXminForSlot(XLogRecPtr current_lsn, TransactionId xmin)
Definition: logical.c:1545
XLogRecPtr end_lsn
ReorderBufferRollbackPreparedCB rollback_prepared
size_t Size
Definition: c.h:540
LogicalDecodeShutdownCB shutdown_cb
LogicalDecodeStreamCommitCB stream_commit_cb
static void begin_prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn)
Definition: logical.c:846
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1203
bool IsTransactionState(void)
Definition: xact.c:371
ReorderBuffer * ReorderBufferAllocate(void)
void(* LogicalOutputPluginWriterWrite)(struct LogicalDecodingContext *lr, XLogRecPtr Ptr, TransactionId xid, bool last_write)
Definition: logical.h:19
void LogicalConfirmReceivedLocation(XLogRecPtr lsn)
Definition: logical.c:1676
PgStat_Counter spill_count
Definition: pgstat.h:925
LogicalDecodeStartupCB startup_cb
XLogRecPtr candidate_xmin_lsn
Definition: slot.h:172
XLogRecPtr report_location
Definition: logical.c:51
LogicalDecodeStreamStartCB stream_start_cb
static void truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
Definition: logical.c:1056
int errmsg(const char *fmt,...)
Definition: elog.c:909
XLogReaderState * reader
Definition: logical.h:43
ReplicationSlot * slot
Definition: logical.h:40
ReorderBufferApplyTruncateCB apply_truncate
PgStat_Counter stream_count
Definition: pgstat.h:928
void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
Definition: logical.c:652
LogicalOutputPluginWriterWrite write
Definition: logical.h:67
#define elog(elevel,...)
Definition: elog.h:232
StringInfo out
Definition: logical.h:73
int pgxactoff
Definition: proc.h:148
#define errcontext
Definition: elog.h:204
#define NameStr(name)
Definition: c.h:681
LogicalDecodingXLogPageReadCB page_read
Definition: logical.h:44
void * arg
LogicalDecodeBeginCB begin_cb
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:102
PgStat_Counter total_txns
Definition: pgstat.h:930
static void message_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size message_size, const char *message)
Definition: logical.c:1157
LogicalDecodeStreamStopCB stream_stop_cb
uint8 * statusFlags
Definition: proc.h:333
slock_t mutex
Definition: slot.h:129
#define TransactionIdIsValid(xid)
Definition: transam.h:41
LogicalDecodingContext * CreateInitDecodingContext(const char *plugin, List *output_plugin_options, bool need_full_snapshot, XLogRecPtr restart_lsn, LogicalDecodingXLogPageReadCB page_read, WALSegmentCleanupCB cleanup_cb, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
Definition: logical.c:320
LogicalDecodingContext * ctx
Definition: logical.c:49
ReorderBufferBeginCB begin
static void output_plugin_error_callback(void *arg)
Definition: logical.c:700
static void LoadOutputPlugin(OutputPluginCallbacks *callbacks, const char *plugin)
Definition: logical.c:678
LogicalDecodeFilterByOriginCB filter_by_origin_cb
Definition: pg_list.h:50
void CheckLogicalDecodingRequirements(void)
Definition: logical.c:103
LogicalDecodeStreamChangeCB stream_change_cb
ReorderBufferCommitPreparedCB commit_prepared
SnapBuild * AllocateSnapshotBuilder(ReorderBuffer *reorder, TransactionId xmin_horizon, XLogRecPtr start_lsn, bool need_full_snapshot, XLogRecPtr initial_consistent_point)
Definition: snapbuild.c:280
void ReplicationSlotsComputeRequiredXmin(bool already_locked)
Definition: slot.c:791
XLogRecPtr candidate_restart_lsn
Definition: slot.h:174
void ReplicationSlotMarkDirty(void)
Definition: slot.c:752
static void stream_change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
Definition: logical.c:1406
ReorderBufferPrepareCB prepare
PgStat_Counter stream_txns
Definition: pgstat.h:927
ReorderBufferStreamStopCB stream_stop