PostgreSQL Source Code  git master
logical.c File Reference
#include "postgres.h"
#include "access/xact.h"
#include "access/xlog_internal.h"
#include "fmgr.h"
#include "miscadmin.h"
#include "replication/decode.h"
#include "replication/logical.h"
#include "replication/origin.h"
#include "replication/reorderbuffer.h"
#include "replication/snapbuild.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
Include dependency graph for logical.c:

Go to the source code of this file.

Data Structures

struct  LogicalErrorCallbackState
 

Typedefs

typedef struct LogicalErrorCallbackState LogicalErrorCallbackState
 

Functions

static void output_plugin_error_callback (void *arg)
 
static void startup_cb_wrapper (LogicalDecodingContext *ctx, OutputPluginOptions *opt, bool is_init)
 
static void shutdown_cb_wrapper (LogicalDecodingContext *ctx)
 
static void begin_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn)
 
static void commit_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
 
static void change_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
 
static void truncate_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
 
static void message_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size message_size, const char *message)
 
static void stream_start_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr first_lsn)
 
static void stream_stop_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr last_lsn)
 
static void stream_abort_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr abort_lsn)
 
static void stream_commit_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
 
static void stream_change_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
 
static void stream_message_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size message_size, const char *message)
 
static void stream_truncate_cb_wrapper (ReorderBuffer *cache, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
 
static void LoadOutputPlugin (OutputPluginCallbacks *callbacks, const char *plugin)
 
void CheckLogicalDecodingRequirements (void)
 
static LogicalDecodingContextStartupDecodingContext (List *output_plugin_options, XLogRecPtr start_lsn, TransactionId xmin_horizon, bool need_full_snapshot, bool fast_forward, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
 
LogicalDecodingContextCreateInitDecodingContext (const char *plugin, List *output_plugin_options, bool need_full_snapshot, XLogRecPtr restart_lsn, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
 
LogicalDecodingContextCreateDecodingContext (XLogRecPtr start_lsn, List *output_plugin_options, bool fast_forward, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
 
bool DecodingContextReady (LogicalDecodingContext *ctx)
 
void DecodingContextFindStartpoint (LogicalDecodingContext *ctx)
 
void FreeDecodingContext (LogicalDecodingContext *ctx)
 
void OutputPluginPrepareWrite (struct LogicalDecodingContext *ctx, bool last_write)
 
void OutputPluginWrite (struct LogicalDecodingContext *ctx, bool last_write)
 
void OutputPluginUpdateProgress (struct LogicalDecodingContext *ctx)
 
bool filter_by_origin_cb_wrapper (LogicalDecodingContext *ctx, RepOriginId origin_id)
 
void LogicalIncreaseXminForSlot (XLogRecPtr current_lsn, TransactionId xmin)
 
void LogicalIncreaseRestartDecodingForSlot (XLogRecPtr current_lsn, XLogRecPtr restart_lsn)
 
void LogicalConfirmReceivedLocation (XLogRecPtr lsn)
 
void ResetLogicalStreamingState (void)
 

Typedef Documentation

◆ LogicalErrorCallbackState

Function Documentation

◆ begin_cb_wrapper()

static void begin_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn 
)
static

Definition at line 723 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, OutputPluginCallbacks::begin_cb, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, error_context_stack, LogicalDecodingContext::fast_forward, ReorderBufferTXN::first_lsn, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

724 {
725  LogicalDecodingContext *ctx = cache->private_data;
727  ErrorContextCallback errcallback;
728 
729  Assert(!ctx->fast_forward);
730 
731  /* Push callback + info on the error context stack */
732  state.ctx = ctx;
733  state.callback_name = "begin";
734  state.report_location = txn->first_lsn;
736  errcallback.arg = (void *) &state;
737  errcallback.previous = error_context_stack;
738  error_context_stack = &errcallback;
739 
740  /* set output state */
741  ctx->accept_writes = true;
742  ctx->write_xid = txn->xid;
743  ctx->write_location = txn->first_lsn;
744 
745  /* do the actual work: call callback */
746  ctx->callbacks.begin_cb(ctx, txn);
747 
748  /* Pop the error context stack */
749  error_context_stack = errcallback.previous;
750 }
XLogRecPtr first_lsn
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
TransactionId xid
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodeBeginCB begin_cb
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ change_cb_wrapper()

static void change_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
Relation  relation,
ReorderBufferChange change 
)
static

Definition at line 784 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, OutputPluginCallbacks::change_cb, LogicalErrorCallbackState::ctx, error_context_stack, LogicalDecodingContext::fast_forward, ReorderBufferChange::lsn, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

786 {
787  LogicalDecodingContext *ctx = cache->private_data;
789  ErrorContextCallback errcallback;
790 
791  Assert(!ctx->fast_forward);
792 
793  /* Push callback + info on the error context stack */
794  state.ctx = ctx;
795  state.callback_name = "change";
796  state.report_location = change->lsn;
798  errcallback.arg = (void *) &state;
799  errcallback.previous = error_context_stack;
800  error_context_stack = &errcallback;
801 
802  /* set output state */
803  ctx->accept_writes = true;
804  ctx->write_xid = txn->xid;
805 
806  /*
807  * report this change's lsn so replies from clients can give an up2date
808  * answer. This won't ever be enough (and shouldn't be!) to confirm
809  * receipt of this transaction, but it might allow another transaction's
810  * commit to be confirmed with one message.
811  */
812  ctx->write_location = change->lsn;
813 
814  ctx->callbacks.change_cb(ctx, txn, relation, change);
815 
816  /* Pop the error context stack */
817  error_context_stack = errcallback.previous;
818 }
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
LogicalDecodeChangeCB change_cb
TransactionId xid
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ CheckLogicalDecodingRequirements()

void CheckLogicalDecodingRequirements ( void  )

Definition at line 93 of file logical.c.

References CheckSlotRequirements(), ereport, errcode(), errmsg(), ERROR, InvalidOid, MyDatabaseId, RecoveryInProgress(), wal_level, and WAL_LEVEL_LOGICAL.

Referenced by copy_replication_slot(), CreateReplicationSlot(), pg_create_logical_replication_slot(), pg_logical_slot_get_changes_guts(), and StartLogicalReplication().

94 {
96 
97  /*
98  * NB: Adding a new requirement likely means that RestoreSlotFromDisk()
99  * needs the same check.
100  */
101 
103  ereport(ERROR,
104  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
105  errmsg("logical decoding requires wal_level >= logical")));
106 
107  if (MyDatabaseId == InvalidOid)
108  ereport(ERROR,
109  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
110  errmsg("logical decoding requires a database connection")));
111 
112  /* ----
113  * TODO: We got to change that someday soon...
114  *
115  * There's basically three things missing to allow this:
116  * 1) We need to be able to correctly and quickly identify the timeline a
117  * LSN belongs to
118  * 2) We need to force hot_standby_feedback to be enabled at all times so
119  * the primary cannot remove rows we need.
120  * 3) support dropping replication slots referring to a database, in
121  * dbase_redo. There can't be any active ones due to HS recovery
122  * conflicts, so that should be relatively easy.
123  * ----
124  */
125  if (RecoveryInProgress())
126  ereport(ERROR,
127  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
128  errmsg("logical decoding cannot be used while in recovery")));
129 }
void CheckSlotRequirements(void)
Definition: slot.c:1031
int wal_level
Definition: xlog.c:106
int errcode(int sqlerrcode)
Definition: elog.c:610
bool RecoveryInProgress(void)
Definition: xlog.c:8069
#define ERROR
Definition: elog.h:43
Oid MyDatabaseId
Definition: globals.c:85
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ commit_cb_wrapper()

static void commit_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
XLogRecPtr  commit_lsn 
)
static

Definition at line 753 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, OutputPluginCallbacks::commit_cb, LogicalErrorCallbackState::ctx, ReorderBufferTXN::end_lsn, error_context_stack, LogicalDecodingContext::fast_forward, ReorderBufferTXN::final_lsn, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

755 {
756  LogicalDecodingContext *ctx = cache->private_data;
758  ErrorContextCallback errcallback;
759 
760  Assert(!ctx->fast_forward);
761 
762  /* Push callback + info on the error context stack */
763  state.ctx = ctx;
764  state.callback_name = "commit";
765  state.report_location = txn->final_lsn; /* beginning of commit record */
767  errcallback.arg = (void *) &state;
768  errcallback.previous = error_context_stack;
769  error_context_stack = &errcallback;
770 
771  /* set output state */
772  ctx->accept_writes = true;
773  ctx->write_xid = txn->xid;
774  ctx->write_location = txn->end_lsn; /* points to the end of the record */
775 
776  /* do the actual work: call callback */
777  ctx->callbacks.commit_cb(ctx, txn, commit_lsn);
778 
779  /* Pop the error context stack */
780  error_context_stack = errcallback.previous;
781 }
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
LogicalDecodeCommitCB commit_cb
XLogRecPtr final_lsn
TransactionId xid
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr end_lsn
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ CreateDecodingContext()

LogicalDecodingContext* CreateDecodingContext ( XLogRecPtr  start_lsn,
List output_plugin_options,
bool  fast_forward,
XLogReaderRoutine xl_routine,
LogicalOutputPluginWriterPrepareWrite  prepare_write,
LogicalOutputPluginWriterWrite  do_write,
LogicalOutputPluginWriterUpdateProgress  update_progress 
)

Definition at line 433 of file logical.c.

References LogicalDecodingContext::callbacks, ReplicationSlotPersistentData::confirmed_flush, LogicalDecodingContext::context, LogicalErrorCallbackState::ctx, ReplicationSlot::data, ReplicationSlotPersistentData::database, DEBUG1, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, InvalidTransactionId, InvalidXLogRecPtr, LOG, MemoryContextSwitchTo(), MyDatabaseId, MyReplicationSlot, ReplicationSlotPersistentData::name, NameStr, LogicalDecodingContext::options, ReorderBuffer::output_rewrites, OutputPluginOptions::receive_rewrites, LogicalDecodingContext::reorder, ReplicationSlotPersistentData::restart_lsn, SlotIsPhysical, OutputPluginCallbacks::startup_cb, startup_cb_wrapper(), and StartupDecodingContext().

Referenced by pg_logical_replication_slot_advance(), pg_logical_slot_get_changes_guts(), and StartLogicalReplication().

440 {
442  ReplicationSlot *slot;
443  MemoryContext old_context;
444 
445  /* shorter lines... */
446  slot = MyReplicationSlot;
447 
448  /* first some sanity checks that are unlikely to be violated */
449  if (slot == NULL)
450  elog(ERROR, "cannot perform logical decoding without an acquired slot");
451 
452  /* make sure the passed slot is suitable, these are user facing errors */
453  if (SlotIsPhysical(slot))
454  ereport(ERROR,
455  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
456  errmsg("cannot use physical replication slot for logical decoding")));
457 
458  if (slot->data.database != MyDatabaseId)
459  ereport(ERROR,
460  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
461  errmsg("replication slot \"%s\" was not created in this database",
462  NameStr(slot->data.name))));
463 
464  if (start_lsn == InvalidXLogRecPtr)
465  {
466  /* continue from last position */
467  start_lsn = slot->data.confirmed_flush;
468  }
469  else if (start_lsn < slot->data.confirmed_flush)
470  {
471  /*
472  * It might seem like we should error out in this case, but it's
473  * pretty common for a client to acknowledge a LSN it doesn't have to
474  * do anything for, and thus didn't store persistently, because the
475  * xlog records didn't result in anything relevant for logical
476  * decoding. Clients have to be able to do that to support synchronous
477  * replication.
478  */
479  elog(DEBUG1, "cannot stream from %X/%X, minimum is %X/%X, forwarding",
480  (uint32) (start_lsn >> 32), (uint32) start_lsn,
481  (uint32) (slot->data.confirmed_flush >> 32),
482  (uint32) slot->data.confirmed_flush);
483 
484  start_lsn = slot->data.confirmed_flush;
485  }
486 
487  ctx = StartupDecodingContext(output_plugin_options,
488  start_lsn, InvalidTransactionId, false,
489  fast_forward, xl_routine, prepare_write,
490  do_write, update_progress);
491 
492  /* call output plugin initialization callback */
493  old_context = MemoryContextSwitchTo(ctx->context);
494  if (ctx->callbacks.startup_cb != NULL)
495  startup_cb_wrapper(ctx, &ctx->options, false);
496  MemoryContextSwitchTo(old_context);
497 
499 
500  ereport(LOG,
501  (errmsg("starting logical decoding for slot \"%s\"",
502  NameStr(slot->data.name)),
503  errdetail("Streaming transactions committing after %X/%X, reading WAL from %X/%X.",
504  (uint32) (slot->data.confirmed_flush >> 32),
505  (uint32) slot->data.confirmed_flush,
506  (uint32) (slot->data.restart_lsn >> 32),
507  (uint32) slot->data.restart_lsn)));
508 
509  return ctx;
510 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define DEBUG1
Definition: elog.h:25
struct ReorderBuffer * reorder
Definition: logical.h:42
OutputPluginOptions options
Definition: logical.h:53
OutputPluginCallbacks callbacks
Definition: logical.h:52
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:610
MemoryContext context
Definition: logical.h:35
ReplicationSlotPersistentData data
Definition: slot.h:143
#define LOG
Definition: elog.h:26
#define SlotIsPhysical(slot)
Definition: slot.h:164
XLogRecPtr confirmed_flush
Definition: slot.h:91
#define ERROR
Definition: elog.h:43
static void startup_cb_wrapper(LogicalDecodingContext *ctx, OutputPluginOptions *opt, bool is_init)
Definition: logical.c:664
int errdetail(const char *fmt,...)
Definition: elog.c:957
#define InvalidTransactionId
Definition: transam.h:31
unsigned int uint32
Definition: c.h:374
Oid MyDatabaseId
Definition: globals.c:85
#define ereport(elevel,...)
Definition: elog.h:144
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
XLogRecPtr restart_lsn
Definition: slot.h:80
LogicalDecodeStartupCB startup_cb
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define NameStr(name)
Definition: c.h:622
static LogicalDecodingContext * StartupDecodingContext(List *output_plugin_options, XLogRecPtr start_lsn, TransactionId xmin_horizon, bool need_full_snapshot, bool fast_forward, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
Definition: logical.c:136

◆ CreateInitDecodingContext()

LogicalDecodingContext* CreateInitDecodingContext ( const char *  plugin,
List output_plugin_options,
bool  need_full_snapshot,
XLogRecPtr  restart_lsn,
XLogReaderRoutine xl_routine,
LogicalOutputPluginWriterPrepareWrite  prepare_write,
LogicalOutputPluginWriterWrite  do_write,
LogicalOutputPluginWriterUpdateProgress  update_progress 
)

Definition at line 281 of file logical.c.

References LogicalDecodingContext::callbacks, ReplicationSlotPersistentData::catalog_xmin, LogicalDecodingContext::context, LogicalErrorCallbackState::ctx, ReplicationSlot::data, ReplicationSlotPersistentData::database, ReplicationSlot::effective_catalog_xmin, ReplicationSlot::effective_xmin, elog, ereport, errcode(), errmsg(), ERROR, GetOldestSafeDecodingTransactionId(), GetTopTransactionIdIfAny(), InvalidTransactionId, IsTransactionState(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MemoryContextSwitchTo(), ReplicationSlot::mutex, MyDatabaseId, MyReplicationSlot, ReplicationSlotPersistentData::name, NameStr, namestrcpy(), NIL, LogicalDecodingContext::options, ReorderBuffer::output_rewrites, ReplicationSlotPersistentData::plugin, OutputPluginOptions::receive_rewrites, LogicalDecodingContext::reorder, ReplicationSlotMarkDirty(), ReplicationSlotReserveWal(), ReplicationSlotSave(), ReplicationSlotsComputeRequiredXmin(), ReplicationSlotPersistentData::restart_lsn, SlotIsPhysical, SpinLockAcquire, SpinLockRelease, OutputPluginCallbacks::startup_cb, startup_cb_wrapper(), StartupDecodingContext(), and XLogRecPtrIsInvalid.

Referenced by create_logical_replication_slot(), and CreateReplicationSlot().

289 {
290  TransactionId xmin_horizon = InvalidTransactionId;
291  ReplicationSlot *slot;
292  NameData plugin_name;
294  MemoryContext old_context;
295 
296  /* shorter lines... */
297  slot = MyReplicationSlot;
298 
299  /* first some sanity checks that are unlikely to be violated */
300  if (slot == NULL)
301  elog(ERROR, "cannot perform logical decoding without an acquired slot");
302 
303  if (plugin == NULL)
304  elog(ERROR, "cannot initialize logical decoding without a specified plugin");
305 
306  /* Make sure the passed slot is suitable. These are user facing errors. */
307  if (SlotIsPhysical(slot))
308  ereport(ERROR,
309  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
310  errmsg("cannot use physical replication slot for logical decoding")));
311 
312  if (slot->data.database != MyDatabaseId)
313  ereport(ERROR,
314  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
315  errmsg("replication slot \"%s\" was not created in this database",
316  NameStr(slot->data.name))));
317 
318  if (IsTransactionState() &&
320  ereport(ERROR,
321  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
322  errmsg("cannot create logical replication slot in transaction that has performed writes")));
323 
324  /*
325  * Register output plugin name with slot. We need the mutex to avoid
326  * concurrent reading of a partially copied string. But we don't want any
327  * complicated code while holding a spinlock, so do namestrcpy() outside.
328  */
329  namestrcpy(&plugin_name, plugin);
330  SpinLockAcquire(&slot->mutex);
331  slot->data.plugin = plugin_name;
332  SpinLockRelease(&slot->mutex);
333 
334  if (XLogRecPtrIsInvalid(restart_lsn))
336  else
337  {
338  SpinLockAcquire(&slot->mutex);
339  slot->data.restart_lsn = restart_lsn;
340  SpinLockRelease(&slot->mutex);
341  }
342 
343  /* ----
344  * This is a bit tricky: We need to determine a safe xmin horizon to start
345  * decoding from, to avoid starting from a running xacts record referring
346  * to xids whose rows have been vacuumed or pruned
347  * already. GetOldestSafeDecodingTransactionId() returns such a value, but
348  * without further interlock its return value might immediately be out of
349  * date.
350  *
351  * So we have to acquire the ProcArrayLock to prevent computation of new
352  * xmin horizons by other backends, get the safe decoding xid, and inform
353  * the slot machinery about the new limit. Once that's done the
354  * ProcArrayLock can be released as the slot machinery now is
355  * protecting against vacuum.
356  *
357  * Note that, temporarily, the data, not just the catalog, xmin has to be
358  * reserved if a data snapshot is to be exported. Otherwise the initial
359  * data snapshot created here is not guaranteed to be valid. After that
360  * the data xmin doesn't need to be managed anymore and the global xmin
361  * should be recomputed. As we are fine with losing the pegged data xmin
362  * after crash - no chance a snapshot would get exported anymore - we can
363  * get away with just setting the slot's
364  * effective_xmin. ReplicationSlotRelease will reset it again.
365  *
366  * ----
367  */
368  LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
369 
370  xmin_horizon = GetOldestSafeDecodingTransactionId(!need_full_snapshot);
371 
372  SpinLockAcquire(&slot->mutex);
373  slot->effective_catalog_xmin = xmin_horizon;
374  slot->data.catalog_xmin = xmin_horizon;
375  if (need_full_snapshot)
376  slot->effective_xmin = xmin_horizon;
377  SpinLockRelease(&slot->mutex);
378 
380 
381  LWLockRelease(ProcArrayLock);
382 
385 
386  ctx = StartupDecodingContext(NIL, restart_lsn, xmin_horizon,
387  need_full_snapshot, false,
388  xl_routine, prepare_write, do_write,
389  update_progress);
390 
391  /* call output plugin initialization callback */
392  old_context = MemoryContextSwitchTo(ctx->context);
393  if (ctx->callbacks.startup_cb != NULL)
394  startup_cb_wrapper(ctx, &ctx->options, true);
395  MemoryContextSwitchTo(old_context);
396 
398 
399  return ctx;
400 }
#define NIL
Definition: pg_list.h:65
static const char * plugin
TransactionId GetOldestSafeDecodingTransactionId(bool catalogOnly)
Definition: procarray.c:2176
struct ReorderBuffer * reorder
Definition: logical.h:42
uint32 TransactionId
Definition: c.h:520
void namestrcpy(Name name, const char *str)
Definition: name.c:233
OutputPluginOptions options
Definition: logical.h:53
OutputPluginCallbacks callbacks
Definition: logical.h:52
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:610
MemoryContext context
Definition: logical.h:35
void ReplicationSlotSave(void)
Definition: slot.c:697
ReplicationSlotPersistentData data
Definition: slot.h:143
#define SlotIsPhysical(slot)
Definition: slot.h:164
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1812
#define SpinLockAcquire(lock)
Definition: spin.h:62
void ReplicationSlotReserveWal(void)
Definition: slot.c:1056
#define ERROR
Definition: elog.h:43
static void startup_cb_wrapper(LogicalDecodingContext *ctx, OutputPluginOptions *opt, bool is_init)
Definition: logical.c:664
TransactionId effective_xmin
Definition: slot.h:139
Definition: c.h:616
TransactionId catalog_xmin
Definition: slot.h:77
#define InvalidTransactionId
Definition: transam.h:31
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:425
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29
#define SpinLockRelease(lock)
Definition: spin.h:64
TransactionId effective_catalog_xmin
Definition: slot.h:140
Oid MyDatabaseId
Definition: globals.c:85
#define ereport(elevel,...)
Definition: elog.h:144
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
XLogRecPtr restart_lsn
Definition: slot.h:80
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1208
bool IsTransactionState(void)
Definition: xact.c:371
LogicalDecodeStartupCB startup_cb
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define NameStr(name)
Definition: c.h:622
slock_t mutex
Definition: slot.h:116
void ReplicationSlotsComputeRequiredXmin(bool already_locked)
Definition: slot.c:754
void ReplicationSlotMarkDirty(void)
Definition: slot.c:715
static LogicalDecodingContext * StartupDecodingContext(List *output_plugin_options, XLogRecPtr start_lsn, TransactionId xmin_horizon, bool need_full_snapshot, bool fast_forward, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
Definition: logical.c:136

◆ DecodingContextFindStartpoint()

void DecodingContextFindStartpoint ( LogicalDecodingContext ctx)

Definition at line 525 of file logical.c.

References CHECK_FOR_INTERRUPTS, ReplicationSlotPersistentData::confirmed_flush, ReplicationSlot::data, DEBUG1, DecodingContextReady(), elog, XLogReaderState::EndRecPtr, ERROR, LogicalDecodingProcessRecord(), ReplicationSlot::mutex, LogicalDecodingContext::reader, ReplicationSlotPersistentData::restart_lsn, LogicalDecodingContext::slot, SpinLockAcquire, SpinLockRelease, XLogBeginRead(), and XLogReadRecord().

Referenced by create_logical_replication_slot(), and CreateReplicationSlot().

526 {
527  ReplicationSlot *slot = ctx->slot;
528 
529  /* Initialize from where to start reading WAL. */
530  XLogBeginRead(ctx->reader, slot->data.restart_lsn);
531 
532  elog(DEBUG1, "searching for logical decoding starting point, starting at %X/%X",
533  (uint32) (slot->data.restart_lsn >> 32),
534  (uint32) slot->data.restart_lsn);
535 
536  /* Wait for a consistent starting point */
537  for (;;)
538  {
539  XLogRecord *record;
540  char *err = NULL;
541 
542  /* the read_page callback waits for new WAL */
543  record = XLogReadRecord(ctx->reader, &err);
544  if (err)
545  elog(ERROR, "%s", err);
546  if (!record)
547  elog(ERROR, "no record found"); /* shouldn't happen */
548 
550 
551  /* only continue till we found a consistent spot */
552  if (DecodingContextReady(ctx))
553  break;
554 
556  }
557 
558  SpinLockAcquire(&slot->mutex);
559  slot->data.confirmed_flush = ctx->reader->EndRecPtr;
560  SpinLockRelease(&slot->mutex);
561 }
#define DEBUG1
Definition: elog.h:25
bool DecodingContextReady(LogicalDecodingContext *ctx)
Definition: logical.c:516
ReplicationSlotPersistentData data
Definition: slot.h:143
XLogRecPtr confirmed_flush
Definition: slot.h:91
XLogRecPtr EndRecPtr
Definition: xlogreader.h:176
#define SpinLockAcquire(lock)
Definition: spin.h:62
XLogRecord * XLogReadRecord(XLogReaderState *state, char **errormsg)
Definition: xlogreader.c:268
#define ERROR
Definition: elog.h:43
void LogicalDecodingProcessRecord(LogicalDecodingContext *ctx, XLogReaderState *record)
Definition: decode.c:94
void XLogBeginRead(XLogReaderState *state, XLogRecPtr RecPtr)
Definition: xlogreader.c:240
unsigned int uint32
Definition: c.h:374
#define SpinLockRelease(lock)
Definition: spin.h:64
XLogRecPtr restart_lsn
Definition: slot.h:80
XLogReaderState * reader
Definition: logical.h:41
ReplicationSlot * slot
Definition: logical.h:38
#define elog(elevel,...)
Definition: elog.h:214
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
slock_t mutex
Definition: slot.h:116

◆ DecodingContextReady()

bool DecodingContextReady ( LogicalDecodingContext ctx)

Definition at line 516 of file logical.c.

References SNAPBUILD_CONSISTENT, SnapBuildCurrentState(), and LogicalDecodingContext::snapshot_builder.

Referenced by DecodingContextFindStartpoint().

517 {
519 }
SnapBuildState SnapBuildCurrentState(SnapBuild *builder)
Definition: snapbuild.c:395
struct SnapBuild * snapshot_builder
Definition: logical.h:43

◆ filter_by_origin_cb_wrapper()

bool filter_by_origin_cb_wrapper ( LogicalDecodingContext ctx,
RepOriginId  origin_id 
)

Definition at line 861 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, error_context_stack, LogicalDecodingContext::fast_forward, OutputPluginCallbacks::filter_by_origin_cb, InvalidXLogRecPtr, output_plugin_error_callback(), ErrorContextCallback::previous, and LogicalErrorCallbackState::report_location.

Referenced by FilterByOrigin().

862 {
864  ErrorContextCallback errcallback;
865  bool ret;
866 
867  Assert(!ctx->fast_forward);
868 
869  /* Push callback + info on the error context stack */
870  state.ctx = ctx;
871  state.callback_name = "filter_by_origin";
874  errcallback.arg = (void *) &state;
875  errcallback.previous = error_context_stack;
876  error_context_stack = &errcallback;
877 
878  /* set output state */
879  ctx->accept_writes = false;
880 
881  /* do the actual work: call callback */
882  ret = ctx->callbacks.filter_by_origin_cb(ctx, origin_id);
883 
884  /* Pop the error context stack */
885  error_context_stack = errcallback.previous;
886 
887  return ret;
888 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
OutputPluginCallbacks callbacks
Definition: logical.h:52
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644
LogicalDecodeFilterByOriginCB filter_by_origin_cb

◆ FreeDecodingContext()

void FreeDecodingContext ( LogicalDecodingContext ctx)

Definition at line 568 of file logical.c.

References LogicalDecodingContext::callbacks, LogicalDecodingContext::context, FreeSnapshotBuilder(), MemoryContextDelete(), LogicalDecodingContext::reader, LogicalDecodingContext::reorder, ReorderBufferFree(), OutputPluginCallbacks::shutdown_cb, shutdown_cb_wrapper(), LogicalDecodingContext::snapshot_builder, and XLogReaderFree().

Referenced by create_logical_replication_slot(), CreateReplicationSlot(), pg_logical_replication_slot_advance(), pg_logical_slot_get_changes_guts(), and StartLogicalReplication().

569 {
570  if (ctx->callbacks.shutdown_cb != NULL)
571  shutdown_cb_wrapper(ctx);
572 
575  XLogReaderFree(ctx->reader);
577 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
struct ReorderBuffer * reorder
Definition: logical.h:42
OutputPluginCallbacks callbacks
Definition: logical.h:52
void ReorderBufferFree(ReorderBuffer *rb)
MemoryContext context
Definition: logical.h:35
static void shutdown_cb_wrapper(LogicalDecodingContext *ctx)
Definition: logical.c:691
void XLogReaderFree(XLogReaderState *state)
Definition: xlogreader.c:139
void FreeSnapshotBuilder(SnapBuild *builder)
Definition: snapbuild.c:351
struct SnapBuild * snapshot_builder
Definition: logical.h:43
LogicalDecodeShutdownCB shutdown_cb
XLogReaderState * reader
Definition: logical.h:41

◆ LoadOutputPlugin()

static void LoadOutputPlugin ( OutputPluginCallbacks callbacks,
const char *  plugin 
)
static

Definition at line 622 of file logical.c.

References OutputPluginCallbacks::begin_cb, OutputPluginCallbacks::change_cb, OutputPluginCallbacks::commit_cb, elog, ERROR, and load_external_function().

Referenced by StartupDecodingContext().

623 {
624  LogicalOutputPluginInit plugin_init;
625 
626  plugin_init = (LogicalOutputPluginInit)
627  load_external_function(plugin, "_PG_output_plugin_init", false, NULL);
628 
629  if (plugin_init == NULL)
630  elog(ERROR, "output plugins have to declare the _PG_output_plugin_init symbol");
631 
632  /* ask the output plugin to fill the callback struct */
633  plugin_init(callbacks);
634 
635  if (callbacks->begin_cb == NULL)
636  elog(ERROR, "output plugins have to register a begin callback");
637  if (callbacks->change_cb == NULL)
638  elog(ERROR, "output plugins have to register a change callback");
639  if (callbacks->commit_cb == NULL)
640  elog(ERROR, "output plugins have to register a commit callback");
641 }
static const char * plugin
#define ERROR
Definition: elog.h:43
LogicalDecodeCommitCB commit_cb
void(* LogicalOutputPluginInit)(struct OutputPluginCallbacks *cb)
Definition: output_plugin.h:36
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:107
LogicalDecodeChangeCB change_cb
#define elog(elevel,...)
Definition: elog.h:214
LogicalDecodeBeginCB begin_cb

◆ LogicalConfirmReceivedLocation()

void LogicalConfirmReceivedLocation ( XLogRecPtr  lsn)

Definition at line 1370 of file logical.c.

References Assert, ReplicationSlot::candidate_catalog_xmin, ReplicationSlot::candidate_restart_lsn, ReplicationSlot::candidate_restart_valid, ReplicationSlot::candidate_xmin_lsn, ReplicationSlotPersistentData::catalog_xmin, ReplicationSlotPersistentData::confirmed_flush, ReplicationSlot::data, DEBUG1, ReplicationSlot::effective_catalog_xmin, elog, InvalidTransactionId, InvalidXLogRecPtr, ReplicationSlot::mutex, MyReplicationSlot, ReplicationSlotMarkDirty(), ReplicationSlotSave(), ReplicationSlotsComputeRequiredLSN(), ReplicationSlotsComputeRequiredXmin(), ReplicationSlotPersistentData::restart_lsn, SpinLockAcquire, SpinLockRelease, and TransactionIdIsValid.

Referenced by LogicalIncreaseRestartDecodingForSlot(), LogicalIncreaseXminForSlot(), pg_logical_replication_slot_advance(), pg_logical_slot_get_changes_guts(), and ProcessStandbyReplyMessage().

1371 {
1372  Assert(lsn != InvalidXLogRecPtr);
1373 
1374  /* Do an unlocked check for candidate_lsn first. */
1377  {
1378  bool updated_xmin = false;
1379  bool updated_restart = false;
1380 
1382 
1384 
1385  /* if we're past the location required for bumping xmin, do so */
1388  {
1389  /*
1390  * We have to write the changed xmin to disk *before* we change
1391  * the in-memory value, otherwise after a crash we wouldn't know
1392  * that some catalog tuples might have been removed already.
1393  *
1394  * Ensure that by first writing to ->xmin and only update
1395  * ->effective_xmin once the new state is synced to disk. After a
1396  * crash ->effective_xmin is set to ->xmin.
1397  */
1400  {
1404  updated_xmin = true;
1405  }
1406  }
1407 
1410  {
1412 
1416  updated_restart = true;
1417  }
1418 
1420 
1421  /* first write new xmin to disk, so we know what's up after a crash */
1422  if (updated_xmin || updated_restart)
1423  {
1426  elog(DEBUG1, "updated xmin: %u restart: %u", updated_xmin, updated_restart);
1427  }
1428 
1429  /*
1430  * Now the new xmin is safely on disk, we can let the global value
1431  * advance. We do not take ProcArrayLock or similar since we only
1432  * advance xmin here and there's not much harm done by a concurrent
1433  * computation missing that.
1434  */
1435  if (updated_xmin)
1436  {
1440 
1443  }
1444  }
1445  else
1446  {
1450  }
1451 }
TransactionId candidate_catalog_xmin
Definition: slot.h:158
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define DEBUG1
Definition: elog.h:25
void ReplicationSlotSave(void)
Definition: slot.c:697
ReplicationSlotPersistentData data
Definition: slot.h:143
XLogRecPtr confirmed_flush
Definition: slot.h:91
#define SpinLockAcquire(lock)
Definition: spin.h:62
void ReplicationSlotsComputeRequiredLSN(void)
Definition: slot.c:804
XLogRecPtr candidate_restart_valid
Definition: slot.h:160
TransactionId catalog_xmin
Definition: slot.h:77
#define InvalidTransactionId
Definition: transam.h:31
#define SpinLockRelease(lock)
Definition: spin.h:64
TransactionId effective_catalog_xmin
Definition: slot.h:140
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
#define Assert(condition)
Definition: c.h:745
XLogRecPtr restart_lsn
Definition: slot.h:80
XLogRecPtr candidate_xmin_lsn
Definition: slot.h:159
#define elog(elevel,...)
Definition: elog.h:214
slock_t mutex
Definition: slot.h:116
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void ReplicationSlotsComputeRequiredXmin(bool already_locked)
Definition: slot.c:754
XLogRecPtr candidate_restart_lsn
Definition: slot.h:161
void ReplicationSlotMarkDirty(void)
Definition: slot.c:715

◆ LogicalIncreaseRestartDecodingForSlot()

void LogicalIncreaseRestartDecodingForSlot ( XLogRecPtr  current_lsn,
XLogRecPtr  restart_lsn 
)

Definition at line 1293 of file logical.c.

References Assert, ReplicationSlot::candidate_restart_lsn, ReplicationSlot::candidate_restart_valid, ReplicationSlotPersistentData::confirmed_flush, ReplicationSlot::data, DEBUG1, elog, InvalidXLogRecPtr, LogicalConfirmReceivedLocation(), ReplicationSlot::mutex, MyReplicationSlot, SpinLockAcquire, and SpinLockRelease.

Referenced by SnapBuildProcessRunningXacts().

1294 {
1295  bool updated_lsn = false;
1296  ReplicationSlot *slot;
1297 
1298  slot = MyReplicationSlot;
1299 
1300  Assert(slot != NULL);
1301  Assert(restart_lsn != InvalidXLogRecPtr);
1302  Assert(current_lsn != InvalidXLogRecPtr);
1303 
1304  SpinLockAcquire(&slot->mutex);
1305 
1306  /* don't overwrite if have a newer restart lsn */
1307  if (restart_lsn <= slot->data.restart_lsn)
1308  {
1309  }
1310 
1311  /*
1312  * We might have already flushed far enough to directly accept this lsn,
1313  * in this case there is no need to check for existing candidate LSNs
1314  */
1315  else if (current_lsn <= slot->data.confirmed_flush)
1316  {
1317  slot->candidate_restart_valid = current_lsn;
1318  slot->candidate_restart_lsn = restart_lsn;
1319 
1320  /* our candidate can directly be used */
1321  updated_lsn = true;
1322  }
1323 
1324  /*
1325  * Only increase if the previous values have been applied, otherwise we
1326  * might never end up updating if the receiver acks too slowly. A missed
1327  * value here will just cause some extra effort after reconnecting.
1328  */
1330  {
1331  slot->candidate_restart_valid = current_lsn;
1332  slot->candidate_restart_lsn = restart_lsn;
1333  SpinLockRelease(&slot->mutex);
1334 
1335  elog(DEBUG1, "got new restart lsn %X/%X at %X/%X",
1336  (uint32) (restart_lsn >> 32), (uint32) restart_lsn,
1337  (uint32) (current_lsn >> 32), (uint32) current_lsn);
1338  }
1339  else
1340  {
1341  XLogRecPtr candidate_restart_lsn;
1342  XLogRecPtr candidate_restart_valid;
1343  XLogRecPtr confirmed_flush;
1344 
1345  candidate_restart_lsn = slot->candidate_restart_lsn;
1346  candidate_restart_valid = slot->candidate_restart_valid;
1347  confirmed_flush = slot->data.confirmed_flush;
1348  SpinLockRelease(&slot->mutex);
1349 
1350  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",
1351  (uint32) (restart_lsn >> 32), (uint32) restart_lsn,
1352  (uint32) (current_lsn >> 32), (uint32) current_lsn,
1353  (uint32) (candidate_restart_lsn >> 32),
1354  (uint32) candidate_restart_lsn,
1355  (uint32) (candidate_restart_valid >> 32),
1356  (uint32) candidate_restart_valid,
1357  (uint32) (confirmed_flush >> 32),
1358  (uint32) confirmed_flush);
1359  }
1360 
1361  /* candidates are already valid with the current flush position, apply */
1362  if (updated_lsn)
1364 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define DEBUG1
Definition: elog.h:25
ReplicationSlotPersistentData data
Definition: slot.h:143
XLogRecPtr confirmed_flush
Definition: slot.h:91
#define SpinLockAcquire(lock)
Definition: spin.h:62
XLogRecPtr candidate_restart_valid
Definition: slot.h:160
unsigned int uint32
Definition: c.h:374
#define SpinLockRelease(lock)
Definition: spin.h:64
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:745
void LogicalConfirmReceivedLocation(XLogRecPtr lsn)
Definition: logical.c:1370
#define elog(elevel,...)
Definition: elog.h:214
slock_t mutex
Definition: slot.h:116
XLogRecPtr candidate_restart_lsn
Definition: slot.h:161

◆ LogicalIncreaseXminForSlot()

void LogicalIncreaseXminForSlot ( XLogRecPtr  current_lsn,
TransactionId  xmin 
)

Definition at line 1236 of file logical.c.

References Assert, ReplicationSlot::candidate_catalog_xmin, ReplicationSlot::candidate_xmin_lsn, ReplicationSlotPersistentData::catalog_xmin, ReplicationSlotPersistentData::confirmed_flush, ReplicationSlot::data, InvalidXLogRecPtr, LogicalConfirmReceivedLocation(), ReplicationSlot::mutex, MyReplicationSlot, SpinLockAcquire, SpinLockRelease, and TransactionIdPrecedesOrEquals().

Referenced by SnapBuildProcessRunningXacts().

1237 {
1238  bool updated_xmin = false;
1239  ReplicationSlot *slot;
1240 
1241  slot = MyReplicationSlot;
1242 
1243  Assert(slot != NULL);
1244 
1245  SpinLockAcquire(&slot->mutex);
1246 
1247  /*
1248  * don't overwrite if we already have a newer xmin. This can happen if we
1249  * restart decoding in a slot.
1250  */
1252  {
1253  }
1254 
1255  /*
1256  * If the client has already confirmed up to this lsn, we directly can
1257  * mark this as accepted. This can happen if we restart decoding in a
1258  * slot.
1259  */
1260  else if (current_lsn <= slot->data.confirmed_flush)
1261  {
1262  slot->candidate_catalog_xmin = xmin;
1263  slot->candidate_xmin_lsn = current_lsn;
1264 
1265  /* our candidate can directly be used */
1266  updated_xmin = true;
1267  }
1268 
1269  /*
1270  * Only increase if the previous values have been applied, otherwise we
1271  * might never end up updating if the receiver acks too slowly.
1272  */
1273  else if (slot->candidate_xmin_lsn == InvalidXLogRecPtr)
1274  {
1275  slot->candidate_catalog_xmin = xmin;
1276  slot->candidate_xmin_lsn = current_lsn;
1277  }
1278  SpinLockRelease(&slot->mutex);
1279 
1280  /* candidate already valid with the current flush position, apply */
1281  if (updated_xmin)
1283 }
TransactionId candidate_catalog_xmin
Definition: slot.h:158
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
ReplicationSlotPersistentData data
Definition: slot.h:143
XLogRecPtr confirmed_flush
Definition: slot.h:91
#define SpinLockAcquire(lock)
Definition: spin.h:62
bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
Definition: transam.c:319
TransactionId catalog_xmin
Definition: slot.h:77
#define SpinLockRelease(lock)
Definition: spin.h:64
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
#define Assert(condition)
Definition: c.h:745
void LogicalConfirmReceivedLocation(XLogRecPtr lsn)
Definition: logical.c:1370
XLogRecPtr candidate_xmin_lsn
Definition: slot.h:159
slock_t mutex
Definition: slot.h:116

◆ message_cb_wrapper()

static void message_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
XLogRecPtr  message_lsn,
bool  transactional,
const char *  prefix,
Size  message_size,
const char *  message 
)
static

Definition at line 891 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, error_context_stack, LogicalDecodingContext::fast_forward, InvalidTransactionId, OutputPluginCallbacks::message_cb, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

894 {
895  LogicalDecodingContext *ctx = cache->private_data;
897  ErrorContextCallback errcallback;
898 
899  Assert(!ctx->fast_forward);
900 
901  if (ctx->callbacks.message_cb == NULL)
902  return;
903 
904  /* Push callback + info on the error context stack */
905  state.ctx = ctx;
906  state.callback_name = "message";
907  state.report_location = message_lsn;
909  errcallback.arg = (void *) &state;
910  errcallback.previous = error_context_stack;
911  error_context_stack = &errcallback;
912 
913  /* set output state */
914  ctx->accept_writes = true;
915  ctx->write_xid = txn != NULL ? txn->xid : InvalidTransactionId;
916  ctx->write_location = message_lsn;
917 
918  /* do the actual work: call callback */
919  ctx->callbacks.message_cb(ctx, txn, message_lsn, transactional, prefix,
920  message_size, message);
921 
922  /* Pop the error context stack */
923  error_context_stack = errcallback.previous;
924 }
TransactionId write_xid
Definition: logical.h:93
void * private_data
LogicalDecodeMessageCB message_cb
OutputPluginCallbacks callbacks
Definition: logical.h:52
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define InvalidTransactionId
Definition: transam.h:31
TransactionId xid
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ output_plugin_error_callback()

static void output_plugin_error_callback ( void *  arg)
static

Definition at line 644 of file logical.c.

References LogicalErrorCallbackState::callback_name, LogicalErrorCallbackState::ctx, ReplicationSlot::data, errcontext, InvalidXLogRecPtr, ReplicationSlotPersistentData::name, NameStr, ReplicationSlotPersistentData::plugin, LogicalErrorCallbackState::report_location, and LogicalDecodingContext::slot.

Referenced by begin_cb_wrapper(), change_cb_wrapper(), commit_cb_wrapper(), filter_by_origin_cb_wrapper(), message_cb_wrapper(), shutdown_cb_wrapper(), startup_cb_wrapper(), stream_abort_cb_wrapper(), stream_change_cb_wrapper(), stream_commit_cb_wrapper(), stream_message_cb_wrapper(), stream_start_cb_wrapper(), stream_stop_cb_wrapper(), stream_truncate_cb_wrapper(), and truncate_cb_wrapper().

645 {
647 
648  /* not all callbacks have an associated LSN */
649  if (state->report_location != InvalidXLogRecPtr)
650  errcontext("slot \"%s\", output plugin \"%s\", in the %s callback, associated LSN %X/%X",
651  NameStr(state->ctx->slot->data.name),
652  NameStr(state->ctx->slot->data.plugin),
653  state->callback_name,
654  (uint32) (state->report_location >> 32),
655  (uint32) state->report_location);
656  else
657  errcontext("slot \"%s\", output plugin \"%s\", in the %s callback",
658  NameStr(state->ctx->slot->data.name),
659  NameStr(state->ctx->slot->data.plugin),
660  state->callback_name);
661 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
ReplicationSlotPersistentData data
Definition: slot.h:143
const char * callback_name
Definition: logical.c:49
unsigned int uint32
Definition: c.h:374
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
ReplicationSlot * slot
Definition: logical.h:38
#define NameStr(name)
Definition: c.h:622
#define errcontext
Definition: elog.h:185
void * arg
LogicalDecodingContext * ctx
Definition: logical.c:48

◆ OutputPluginPrepareWrite()

void OutputPluginPrepareWrite ( struct LogicalDecodingContext ctx,
bool  last_write 
)

◆ OutputPluginUpdateProgress()

void OutputPluginUpdateProgress ( struct LogicalDecodingContext ctx)

Definition at line 609 of file logical.c.

References LogicalDecodingContext::update_progress, LogicalDecodingContext::write_location, and LogicalDecodingContext::write_xid.

Referenced by pgoutput_commit_txn().

610 {
611  if (!ctx->update_progress)
612  return;
613 
614  ctx->update_progress(ctx, ctx->write_location, ctx->write_xid);
615 }
TransactionId write_xid
Definition: logical.h:93
XLogRecPtr write_location
Definition: logical.h:92
LogicalOutputPluginWriterUpdateProgress update_progress
Definition: logical.h:65

◆ OutputPluginWrite()

void OutputPluginWrite ( struct LogicalDecodingContext ctx,
bool  last_write 
)

◆ ResetLogicalStreamingState()

void ResetLogicalStreamingState ( void  )

Definition at line 1457 of file logical.c.

References bsysscan, CheckXidAlive, and InvalidTransactionId.

Referenced by AbortSubTransaction(), and AbortTransaction().

1458 {
1460  bsysscan = false;
1461 }
bool bsysscan
Definition: xact.c:96
#define InvalidTransactionId
Definition: transam.h:31
TransactionId CheckXidAlive
Definition: xact.c:95

◆ shutdown_cb_wrapper()

static void shutdown_cb_wrapper ( LogicalDecodingContext ctx)
static

Definition at line 691 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, error_context_stack, LogicalDecodingContext::fast_forward, InvalidXLogRecPtr, output_plugin_error_callback(), ErrorContextCallback::previous, LogicalErrorCallbackState::report_location, and OutputPluginCallbacks::shutdown_cb.

Referenced by FreeDecodingContext().

692 {
694  ErrorContextCallback errcallback;
695 
696  Assert(!ctx->fast_forward);
697 
698  /* Push callback + info on the error context stack */
699  state.ctx = ctx;
700  state.callback_name = "shutdown";
703  errcallback.arg = (void *) &state;
704  errcallback.previous = error_context_stack;
705  error_context_stack = &errcallback;
706 
707  /* set output state */
708  ctx->accept_writes = false;
709 
710  /* do the actual work: call callback */
711  ctx->callbacks.shutdown_cb(ctx);
712 
713  /* Pop the error context stack */
714  error_context_stack = errcallback.previous;
715 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
OutputPluginCallbacks callbacks
Definition: logical.h:52
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
LogicalDecodeShutdownCB shutdown_cb
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ startup_cb_wrapper()

static void startup_cb_wrapper ( LogicalDecodingContext ctx,
OutputPluginOptions opt,
bool  is_init 
)
static

Definition at line 664 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, error_context_stack, LogicalDecodingContext::fast_forward, InvalidXLogRecPtr, output_plugin_error_callback(), ErrorContextCallback::previous, LogicalErrorCallbackState::report_location, and OutputPluginCallbacks::startup_cb.

Referenced by CreateDecodingContext(), and CreateInitDecodingContext().

665 {
667  ErrorContextCallback errcallback;
668 
669  Assert(!ctx->fast_forward);
670 
671  /* Push callback + info on the error context stack */
672  state.ctx = ctx;
673  state.callback_name = "startup";
676  errcallback.arg = (void *) &state;
677  errcallback.previous = error_context_stack;
678  error_context_stack = &errcallback;
679 
680  /* set output state */
681  ctx->accept_writes = false;
682 
683  /* do the actual work: call callback */
684  ctx->callbacks.startup_cb(ctx, opt, is_init);
685 
686  /* Pop the error context stack */
687  error_context_stack = errcallback.previous;
688 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
OutputPluginCallbacks callbacks
Definition: logical.h:52
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
LogicalDecodeStartupCB startup_cb
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ StartupDecodingContext()

static LogicalDecodingContext* StartupDecodingContext ( List output_plugin_options,
XLogRecPtr  start_lsn,
TransactionId  xmin_horizon,
bool  need_full_snapshot,
bool  fast_forward,
XLogReaderRoutine xl_routine,
LogicalOutputPluginWriterPrepareWrite  prepare_write,
LogicalOutputPluginWriterWrite  do_write,
LogicalOutputPluginWriterUpdateProgress  update_progress 
)
static

Definition at line 136 of file logical.c.

References AllocateSnapshotBuilder(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, ReorderBuffer::apply_change, ReorderBuffer::apply_truncate, ReorderBuffer::begin, begin_cb_wrapper(), LogicalDecodingContext::callbacks, change_cb_wrapper(), ReorderBuffer::commit, commit_cb_wrapper(), LogicalDecodingContext::context, LogicalErrorCallbackState::ctx, CurrentMemoryContext, ReplicationSlot::data, ereport, errcode(), errmsg(), ERROR, LogicalDecodingContext::fast_forward, IsTransactionOrTransactionBlock(), LoadOutputPlugin(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), makeStringInfo(), MemoryContextSwitchTo(), ReorderBuffer::message, message_cb_wrapper(), MyPgXact, MyReplicationSlot, NameStr, LogicalDecodingContext::out, LogicalDecodingContext::output_plugin_options, palloc0(), ReplicationSlotPersistentData::plugin, LogicalDecodingContext::prepare_write, ReorderBuffer::private_data, PROC_IN_LOGICAL_DECODING, LogicalDecodingContext::reader, LogicalDecodingContext::reorder, ReorderBufferAllocate(), LogicalDecodingContext::slot, LogicalDecodingContext::snapshot_builder, ReorderBuffer::stream_abort, OutputPluginCallbacks::stream_abort_cb, stream_abort_cb_wrapper(), ReorderBuffer::stream_change, OutputPluginCallbacks::stream_change_cb, stream_change_cb_wrapper(), ReorderBuffer::stream_commit, OutputPluginCallbacks::stream_commit_cb, stream_commit_cb_wrapper(), ReorderBuffer::stream_message, OutputPluginCallbacks::stream_message_cb, stream_message_cb_wrapper(), ReorderBuffer::stream_start, OutputPluginCallbacks::stream_start_cb, stream_start_cb_wrapper(), ReorderBuffer::stream_stop, OutputPluginCallbacks::stream_stop_cb, stream_stop_cb_wrapper(), ReorderBuffer::stream_truncate, OutputPluginCallbacks::stream_truncate_cb, stream_truncate_cb_wrapper(), LogicalDecodingContext::streaming, truncate_cb_wrapper(), LogicalDecodingContext::update_progress, PGXACT::vacuumFlags, wal_segment_size, LogicalDecodingContext::write, and XLogReaderAllocate().

Referenced by CreateDecodingContext(), and CreateInitDecodingContext().

145 {
146  ReplicationSlot *slot;
147  MemoryContext context,
148  old_context;
150 
151  /* shorter lines... */
152  slot = MyReplicationSlot;
153 
155  "Logical decoding context",
157  old_context = MemoryContextSwitchTo(context);
158  ctx = palloc0(sizeof(LogicalDecodingContext));
159 
160  ctx->context = context;
161 
162  /*
163  * (re-)load output plugins, so we detect a bad (removed) output plugin
164  * now.
165  */
166  if (!fast_forward)
168 
169  /*
170  * Now that the slot's xmin has been set, we can announce ourselves as a
171  * logical decoding backend which doesn't need to be checked individually
172  * when computing the xmin horizon because the xmin is enforced via
173  * replication slots.
174  *
175  * We can only do so if we're outside of a transaction (i.e. the case when
176  * streaming changes via walsender), otherwise an already setup
177  * snapshot/xid would end up being ignored. That's not a particularly
178  * bothersome restriction since the SQL interface can't be used for
179  * streaming anyway.
180  */
182  {
183  LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
185  LWLockRelease(ProcArrayLock);
186  }
187 
188  ctx->slot = slot;
189 
190  ctx->reader = XLogReaderAllocate(wal_segment_size, NULL, xl_routine, ctx);
191  if (!ctx->reader)
192  ereport(ERROR,
193  (errcode(ERRCODE_OUT_OF_MEMORY),
194  errmsg("out of memory")));
195 
197  ctx->snapshot_builder =
198  AllocateSnapshotBuilder(ctx->reorder, xmin_horizon, start_lsn,
199  need_full_snapshot);
200 
201  ctx->reorder->private_data = ctx;
202 
203  /* wrap output plugin callbacks, so we can add error context information */
209 
210  /*
211  * To support streaming, we require start/stop/abort/commit/change
212  * callbacks. The message and truncate callbacks are optional, similar to
213  * regular output plugins. We however enable streaming when at least one
214  * of the methods is enabled so that we can easily identify missing
215  * methods.
216  *
217  * We decide it here, but only check it later in the wrappers.
218  */
219  ctx->streaming = (ctx->callbacks.stream_start_cb != NULL) ||
220  (ctx->callbacks.stream_stop_cb != NULL) ||
221  (ctx->callbacks.stream_abort_cb != NULL) ||
222  (ctx->callbacks.stream_commit_cb != NULL) ||
223  (ctx->callbacks.stream_change_cb != NULL) ||
224  (ctx->callbacks.stream_message_cb != NULL) ||
225  (ctx->callbacks.stream_truncate_cb != NULL);
226 
227  /*
228  * streaming callbacks
229  *
230  * stream_message and stream_truncate callbacks are optional, so we do not
231  * fail with ERROR when missing, but the wrappers simply do nothing. We
232  * must set the ReorderBuffer callbacks to something, otherwise the calls
233  * from there will crash (we don't want to move the checks there).
234  */
242 
243  ctx->out = makeStringInfo();
244  ctx->prepare_write = prepare_write;
245  ctx->write = do_write;
246  ctx->update_progress = update_progress;
247 
248  ctx->output_plugin_options = output_plugin_options;
249 
250  ctx->fast_forward = fast_forward;
251 
252  MemoryContextSwitchTo(old_context);
253 
254  return ctx;
255 }
static void stream_stop_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr last_lsn)
Definition: logical.c:973
static void stream_abort_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr abort_lsn)
Definition: logical.c:1019
ReorderBufferApplyChangeCB apply_change
#define AllocSetContextCreate
Definition: memutils.h:170
void * private_data
static void change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
Definition: logical.c:784
struct ReorderBuffer * reorder
Definition: logical.h:42
#define PROC_IN_LOGICAL_DECODING
Definition: proc.h:56
int wal_segment_size
Definition: xlog.c:116
static void commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: logical.c:753
ReorderBufferStreamAbortCB stream_abort
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
OutputPluginCallbacks callbacks
Definition: logical.h:52
LogicalDecodeStreamMessageCB stream_message_cb
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errcode(int sqlerrcode)
Definition: elog.c:610
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4702
MemoryContext context
Definition: logical.h:35
LogicalDecodeStreamAbortCB stream_abort_cb
List * output_plugin_options
Definition: logical.h:58
ReorderBufferCommitCB commit
ReplicationSlotPersistentData data
Definition: slot.h:143
ReorderBufferStreamCommitCB stream_commit
PGXACT * MyPgXact
Definition: proc.c:68
uint8 vacuumFlags
Definition: proc.h:239
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1812
ReorderBufferStreamMessageCB stream_message
static void stream_commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: logical.c:1058
#define ERROR
Definition: elog.h:43
LogicalOutputPluginWriterPrepareWrite prepare_write
Definition: logical.h:63
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
LogicalOutputPluginWriterUpdateProgress update_progress
Definition: logical.h:65
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
XLogReaderState * XLogReaderAllocate(int wal_segment_size, const char *waldir, XLogReaderRoutine *routine, void *private_data)
Definition: xlogreader.c:75
ReorderBufferMessageCB message
ReorderBufferStreamChangeCB stream_change
ReorderBufferStreamTruncateCB stream_truncate
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:1143
void * palloc0(Size size)
Definition: mcxt.c:980
static void stream_start_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, XLogRecPtr first_lsn)
Definition: logical.c:927
LogicalDecodeStreamTruncateCB stream_truncate_cb
static void stream_truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
Definition: logical.c:1183
ReorderBufferStreamStartCB stream_start
#define ereport(elevel,...)
Definition: elog.h:144
static void begin_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn)
Definition: logical.c:723
struct SnapBuild * snapshot_builder
Definition: logical.h:43
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
LogicalDecodeStreamCommitCB stream_commit_cb
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1208
ReorderBuffer * ReorderBufferAllocate(void)
LogicalDecodeStreamStartCB stream_start_cb
static void truncate_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
Definition: logical.c:821
int errmsg(const char *fmt,...)
Definition: elog.c:824
XLogReaderState * reader
Definition: logical.h:41
ReplicationSlot * slot
Definition: logical.h:38
ReorderBufferApplyTruncateCB apply_truncate
LogicalOutputPluginWriterWrite write
Definition: logical.h:64
StringInfo out
Definition: logical.h:70
#define NameStr(name)
Definition: c.h:622
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:891
LogicalDecodeStreamStopCB stream_stop_cb
ReorderBufferBeginCB begin
static void LoadOutputPlugin(OutputPluginCallbacks *callbacks, const char *plugin)
Definition: logical.c:622
LogicalDecodeStreamChangeCB stream_change_cb
SnapBuild * AllocateSnapshotBuilder(ReorderBuffer *reorder, TransactionId xmin_horizon, XLogRecPtr start_lsn, bool need_full_snapshot)
Definition: snapbuild.c:310
static void stream_change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
Definition: logical.c:1097
ReorderBufferStreamStopCB stream_stop

◆ stream_abort_cb_wrapper()

static void stream_abort_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
XLogRecPtr  abort_lsn 
)
static

Definition at line 1019 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, ereport, errcode(), errmsg(), ERROR, error_context_stack, LogicalDecodingContext::fast_forward, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, OutputPluginCallbacks::stream_abort_cb, LogicalDecodingContext::streaming, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

1021 {
1022  LogicalDecodingContext *ctx = cache->private_data;
1024  ErrorContextCallback errcallback;
1025 
1026  Assert(!ctx->fast_forward);
1027 
1028  /* We're only supposed to call this when streaming is supported. */
1029  Assert(ctx->streaming);
1030 
1031  /* Push callback + info on the error context stack */
1032  state.ctx = ctx;
1033  state.callback_name = "stream_abort";
1034  state.report_location = abort_lsn;
1035  errcallback.callback = output_plugin_error_callback;
1036  errcallback.arg = (void *) &state;
1037  errcallback.previous = error_context_stack;
1038  error_context_stack = &errcallback;
1039 
1040  /* set output state */
1041  ctx->accept_writes = true;
1042  ctx->write_xid = txn->xid;
1043  ctx->write_location = abort_lsn;
1044 
1045  /* in streaming mode, stream_abort_cb is required */
1046  if (ctx->callbacks.stream_abort_cb == NULL)
1047  ereport(ERROR,
1048  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1049  errmsg("logical streaming requires a stream_abort_cb callback")));
1050 
1051  ctx->callbacks.stream_abort_cb(ctx, txn, abort_lsn);
1052 
1053  /* Pop the error context stack */
1054  error_context_stack = errcallback.previous;
1055 }
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
int errcode(int sqlerrcode)
Definition: elog.c:610
LogicalDecodeStreamAbortCB stream_abort_cb
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define ERROR
Definition: elog.h:43
TransactionId xid
#define ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
int errmsg(const char *fmt,...)
Definition: elog.c:824
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ stream_change_cb_wrapper()

static void stream_change_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
Relation  relation,
ReorderBufferChange change 
)
static

Definition at line 1097 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, ereport, errcode(), errmsg(), ERROR, error_context_stack, LogicalDecodingContext::fast_forward, ReorderBufferChange::lsn, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, OutputPluginCallbacks::stream_change_cb, LogicalDecodingContext::streaming, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

1099 {
1100  LogicalDecodingContext *ctx = cache->private_data;
1102  ErrorContextCallback errcallback;
1103 
1104  Assert(!ctx->fast_forward);
1105 
1106  /* We're only supposed to call this when streaming is supported. */
1107  Assert(ctx->streaming);
1108 
1109  /* Push callback + info on the error context stack */
1110  state.ctx = ctx;
1111  state.callback_name = "stream_change";
1112  state.report_location = change->lsn;
1113  errcallback.callback = output_plugin_error_callback;
1114  errcallback.arg = (void *) &state;
1115  errcallback.previous = error_context_stack;
1116  error_context_stack = &errcallback;
1117 
1118  /* set output state */
1119  ctx->accept_writes = true;
1120  ctx->write_xid = txn->xid;
1121 
1122  /*
1123  * report this change's lsn so replies from clients can give an up2date
1124  * answer. This won't ever be enough (and shouldn't be!) to confirm
1125  * receipt of this transaction, but it might allow another transaction's
1126  * commit to be confirmed with one message.
1127  */
1128  ctx->write_location = change->lsn;
1129 
1130  /* in streaming mode, stream_change_cb is required */
1131  if (ctx->callbacks.stream_change_cb == NULL)
1132  ereport(ERROR,
1133  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1134  errmsg("logical streaming requires a stream_change_cb callback")));
1135 
1136  ctx->callbacks.stream_change_cb(ctx, txn, relation, change);
1137 
1138  /* Pop the error context stack */
1139  error_context_stack = errcallback.previous;
1140 }
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
int errcode(int sqlerrcode)
Definition: elog.c:610
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define ERROR
Definition: elog.h:43
TransactionId xid
#define ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
int errmsg(const char *fmt,...)
Definition: elog.c:824
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644
LogicalDecodeStreamChangeCB stream_change_cb

◆ stream_commit_cb_wrapper()

static void stream_commit_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
XLogRecPtr  commit_lsn 
)
static

Definition at line 1058 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, ReorderBufferTXN::end_lsn, ereport, errcode(), errmsg(), ERROR, error_context_stack, LogicalDecodingContext::fast_forward, ReorderBufferTXN::final_lsn, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, OutputPluginCallbacks::stream_commit_cb, LogicalDecodingContext::streaming, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

1060 {
1061  LogicalDecodingContext *ctx = cache->private_data;
1063  ErrorContextCallback errcallback;
1064 
1065  Assert(!ctx->fast_forward);
1066 
1067  /* We're only supposed to call this when streaming is supported. */
1068  Assert(ctx->streaming);
1069 
1070  /* Push callback + info on the error context stack */
1071  state.ctx = ctx;
1072  state.callback_name = "stream_commit";
1073  state.report_location = txn->final_lsn;
1074  errcallback.callback = output_plugin_error_callback;
1075  errcallback.arg = (void *) &state;
1076  errcallback.previous = error_context_stack;
1077  error_context_stack = &errcallback;
1078 
1079  /* set output state */
1080  ctx->accept_writes = true;
1081  ctx->write_xid = txn->xid;
1082  ctx->write_location = txn->end_lsn;
1083 
1084  /* in streaming mode, stream_abort_cb is required */
1085  if (ctx->callbacks.stream_commit_cb == NULL)
1086  ereport(ERROR,
1087  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1088  errmsg("logical streaming requires a stream_commit_cb callback")));
1089 
1090  ctx->callbacks.stream_commit_cb(ctx, txn, commit_lsn);
1091 
1092  /* Pop the error context stack */
1093  error_context_stack = errcallback.previous;
1094 }
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
int errcode(int sqlerrcode)
Definition: elog.c:610
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define ERROR
Definition: elog.h:43
XLogRecPtr final_lsn
TransactionId xid
#define ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr end_lsn
LogicalDecodeStreamCommitCB stream_commit_cb
XLogRecPtr report_location
Definition: logical.c:50
int errmsg(const char *fmt,...)
Definition: elog.c:824
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ stream_message_cb_wrapper()

static void stream_message_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
XLogRecPtr  message_lsn,
bool  transactional,
const char *  prefix,
Size  message_size,
const char *  message 
)
static

Definition at line 1143 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, error_context_stack, LogicalDecodingContext::fast_forward, InvalidTransactionId, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, OutputPluginCallbacks::stream_message_cb, LogicalDecodingContext::streaming, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

1146 {
1147  LogicalDecodingContext *ctx = cache->private_data;
1149  ErrorContextCallback errcallback;
1150 
1151  Assert(!ctx->fast_forward);
1152 
1153  /* We're only supposed to call this when streaming is supported. */
1154  Assert(ctx->streaming);
1155 
1156  /* this callback is optional */
1157  if (ctx->callbacks.stream_message_cb == NULL)
1158  return;
1159 
1160  /* Push callback + info on the error context stack */
1161  state.ctx = ctx;
1162  state.callback_name = "stream_message";
1163  state.report_location = message_lsn;
1164  errcallback.callback = output_plugin_error_callback;
1165  errcallback.arg = (void *) &state;
1166  errcallback.previous = error_context_stack;
1167  error_context_stack = &errcallback;
1168 
1169  /* set output state */
1170  ctx->accept_writes = true;
1171  ctx->write_xid = txn != NULL ? txn->xid : InvalidTransactionId;
1172  ctx->write_location = message_lsn;
1173 
1174  /* do the actual work: call callback */
1175  ctx->callbacks.stream_message_cb(ctx, txn, message_lsn, transactional, prefix,
1176  message_size, message);
1177 
1178  /* Pop the error context stack */
1179  error_context_stack = errcallback.previous;
1180 }
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
LogicalDecodeStreamMessageCB stream_message_cb
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define InvalidTransactionId
Definition: transam.h:31
TransactionId xid
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ stream_start_cb_wrapper()

static void stream_start_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
XLogRecPtr  first_lsn 
)
static

Definition at line 927 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, ereport, errcode(), errmsg(), ERROR, error_context_stack, LogicalDecodingContext::fast_forward, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, OutputPluginCallbacks::stream_start_cb, LogicalDecodingContext::streaming, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

929 {
930  LogicalDecodingContext *ctx = cache->private_data;
932  ErrorContextCallback errcallback;
933 
934  Assert(!ctx->fast_forward);
935 
936  /* We're only supposed to call this when streaming is supported. */
937  Assert(ctx->streaming);
938 
939  /* Push callback + info on the error context stack */
940  state.ctx = ctx;
941  state.callback_name = "stream_start";
942  state.report_location = first_lsn;
944  errcallback.arg = (void *) &state;
945  errcallback.previous = error_context_stack;
946  error_context_stack = &errcallback;
947 
948  /* set output state */
949  ctx->accept_writes = true;
950  ctx->write_xid = txn->xid;
951 
952  /*
953  * report this message's lsn so replies from clients can give an up2date
954  * answer. This won't ever be enough (and shouldn't be!) to confirm
955  * receipt of this transaction, but it might allow another transaction's
956  * commit to be confirmed with one message.
957  */
958  ctx->write_location = first_lsn;
959 
960  /* in streaming mode, stream_start_cb is required */
961  if (ctx->callbacks.stream_start_cb == NULL)
962  ereport(ERROR,
963  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
964  errmsg("logical streaming requires a stream_start_cb callback")));
965 
966  ctx->callbacks.stream_start_cb(ctx, txn);
967 
968  /* Pop the error context stack */
969  error_context_stack = errcallback.previous;
970 }
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
int errcode(int sqlerrcode)
Definition: elog.c:610
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define ERROR
Definition: elog.h:43
TransactionId xid
#define ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodeStreamStartCB stream_start_cb
int errmsg(const char *fmt,...)
Definition: elog.c:824
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ stream_stop_cb_wrapper()

static void stream_stop_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
XLogRecPtr  last_lsn 
)
static

Definition at line 973 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, ereport, errcode(), errmsg(), ERROR, error_context_stack, LogicalDecodingContext::fast_forward, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, OutputPluginCallbacks::stream_stop_cb, LogicalDecodingContext::streaming, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

975 {
976  LogicalDecodingContext *ctx = cache->private_data;
978  ErrorContextCallback errcallback;
979 
980  Assert(!ctx->fast_forward);
981 
982  /* We're only supposed to call this when streaming is supported. */
983  Assert(ctx->streaming);
984 
985  /* Push callback + info on the error context stack */
986  state.ctx = ctx;
987  state.callback_name = "stream_stop";
988  state.report_location = last_lsn;
990  errcallback.arg = (void *) &state;
991  errcallback.previous = error_context_stack;
992  error_context_stack = &errcallback;
993 
994  /* set output state */
995  ctx->accept_writes = true;
996  ctx->write_xid = txn->xid;
997 
998  /*
999  * report this message's lsn so replies from clients can give an up2date
1000  * answer. This won't ever be enough (and shouldn't be!) to confirm
1001  * receipt of this transaction, but it might allow another transaction's
1002  * commit to be confirmed with one message.
1003  */
1004  ctx->write_location = last_lsn;
1005 
1006  /* in streaming mode, stream_stop_cb is required */
1007  if (ctx->callbacks.stream_stop_cb == NULL)
1008  ereport(ERROR,
1009  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1010  errmsg("logical streaming requires a stream_stop_cb callback")));
1011 
1012  ctx->callbacks.stream_stop_cb(ctx, txn);
1013 
1014  /* Pop the error context stack */
1015  error_context_stack = errcallback.previous;
1016 }
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
int errcode(int sqlerrcode)
Definition: elog.c:610
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
#define ERROR
Definition: elog.h:43
TransactionId xid
#define ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
int errmsg(const char *fmt,...)
Definition: elog.c:824
LogicalDecodeStreamStopCB stream_stop_cb
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ stream_truncate_cb_wrapper()

static void stream_truncate_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
int  nrelations,
Relation  relations[],
ReorderBufferChange change 
)
static

Definition at line 1183 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, error_context_stack, LogicalDecodingContext::fast_forward, ReorderBufferChange::lsn, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, OutputPluginCallbacks::stream_truncate_cb, LogicalDecodingContext::streaming, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

1186 {
1187  LogicalDecodingContext *ctx = cache->private_data;
1189  ErrorContextCallback errcallback;
1190 
1191  Assert(!ctx->fast_forward);
1192 
1193  /* We're only supposed to call this when streaming is supported. */
1194  Assert(ctx->streaming);
1195 
1196  /* this callback is optional */
1197  if (!ctx->callbacks.stream_truncate_cb)
1198  return;
1199 
1200  /* Push callback + info on the error context stack */
1201  state.ctx = ctx;
1202  state.callback_name = "stream_truncate";
1203  state.report_location = change->lsn;
1204  errcallback.callback = output_plugin_error_callback;
1205  errcallback.arg = (void *) &state;
1206  errcallback.previous = error_context_stack;
1207  error_context_stack = &errcallback;
1208 
1209  /* set output state */
1210  ctx->accept_writes = true;
1211  ctx->write_xid = txn->xid;
1212 
1213  /*
1214  * report this change's lsn so replies from clients can give an up2date
1215  * answer. This won't ever be enough (and shouldn't be!) to confirm
1216  * receipt of this transaction, but it might allow another transaction's
1217  * commit to be confirmed with one message.
1218  */
1219  ctx->write_location = change->lsn;
1220 
1221  ctx->callbacks.stream_truncate_cb(ctx, txn, nrelations, relations, change);
1222 
1223  /* Pop the error context stack */
1224  error_context_stack = errcallback.previous;
1225 }
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
LogicalDecodeStreamTruncateCB stream_truncate_cb
TransactionId xid
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644

◆ truncate_cb_wrapper()

static void truncate_cb_wrapper ( ReorderBuffer cache,
ReorderBufferTXN txn,
int  nrelations,
Relation  relations[],
ReorderBufferChange change 
)
static

Definition at line 821 of file logical.c.

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalErrorCallbackState::callback_name, LogicalDecodingContext::callbacks, LogicalErrorCallbackState::ctx, error_context_stack, LogicalDecodingContext::fast_forward, ReorderBufferChange::lsn, output_plugin_error_callback(), ErrorContextCallback::previous, ReorderBuffer::private_data, LogicalErrorCallbackState::report_location, OutputPluginCallbacks::truncate_cb, LogicalDecodingContext::write_location, LogicalDecodingContext::write_xid, and ReorderBufferTXN::xid.

Referenced by StartupDecodingContext().

823 {
824  LogicalDecodingContext *ctx = cache->private_data;
826  ErrorContextCallback errcallback;
827 
828  Assert(!ctx->fast_forward);
829 
830  if (!ctx->callbacks.truncate_cb)
831  return;
832 
833  /* Push callback + info on the error context stack */
834  state.ctx = ctx;
835  state.callback_name = "truncate";
836  state.report_location = change->lsn;
838  errcallback.arg = (void *) &state;
839  errcallback.previous = error_context_stack;
840  error_context_stack = &errcallback;
841 
842  /* set output state */
843  ctx->accept_writes = true;
844  ctx->write_xid = txn->xid;
845 
846  /*
847  * report this change's lsn so replies from clients can give an up2date
848  * answer. This won't ever be enough (and shouldn't be!) to confirm
849  * receipt of this transaction, but it might allow another transaction's
850  * commit to be confirmed with one message.
851  */
852  ctx->write_location = change->lsn;
853 
854  ctx->callbacks.truncate_cb(ctx, txn, nrelations, relations, change);
855 
856  /* Pop the error context stack */
857  error_context_stack = errcallback.previous;
858 }
LogicalDecodeTruncateCB truncate_cb
TransactionId write_xid
Definition: logical.h:93
void * private_data
OutputPluginCallbacks callbacks
Definition: logical.h:52
void(* callback)(void *arg)
Definition: elog.h:229
struct ErrorContextCallback * previous
Definition: elog.h:228
const char * callback_name
Definition: logical.c:49
XLogRecPtr write_location
Definition: logical.h:92
ErrorContextCallback * error_context_stack
Definition: elog.c:92
TransactionId xid
#define Assert(condition)
Definition: c.h:745
Definition: regguts.h:298
XLogRecPtr report_location
Definition: logical.c:50
LogicalDecodingContext * ctx
Definition: logical.c:48
static void output_plugin_error_callback(void *arg)
Definition: logical.c:644