PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
logical.h File Reference
Include dependency graph for logical.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  LogicalDecodingContext
 

Typedefs

typedef void(* LogicalOutputPluginWriterWrite) (struct LogicalDecodingContext *lr, XLogRecPtr Ptr, TransactionId xid, bool last_write)
 
typedef LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite
 
typedef void(* LogicalOutputPluginWriterUpdateProgress) (struct LogicalDecodingContext *lr, XLogRecPtr Ptr, TransactionId xid, bool skipped_xact)
 
typedef struct LogicalDecodingContext LogicalDecodingContext
 

Functions

void CheckLogicalDecodingRequirements (void)
 
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)
 
void DecodingContextFindStartpoint (LogicalDecodingContext *ctx)
 
bool DecodingContextReady (LogicalDecodingContext *ctx)
 
void FreeDecodingContext (LogicalDecodingContext *ctx)
 
void LogicalIncreaseXminForSlot (XLogRecPtr current_lsn, TransactionId xmin)
 
void LogicalIncreaseRestartDecodingForSlot (XLogRecPtr current_lsn, XLogRecPtr restart_lsn)
 
void LogicalConfirmReceivedLocation (XLogRecPtr lsn)
 
bool filter_prepare_cb_wrapper (LogicalDecodingContext *ctx, TransactionId xid, const char *gid)
 
bool filter_by_origin_cb_wrapper (LogicalDecodingContext *ctx, RepOriginId origin_id)
 
void ResetLogicalStreamingState (void)
 
void UpdateDecodingStats (LogicalDecodingContext *ctx)
 
bool LogicalReplicationSlotHasPendingWal (XLogRecPtr end_of_wal)
 
XLogRecPtr LogicalSlotAdvanceAndCheckSnapState (XLogRecPtr moveto, bool *found_consistent_snapshot)
 

Typedef Documentation

◆ LogicalDecodingContext

◆ LogicalOutputPluginWriterPrepareWrite

◆ LogicalOutputPluginWriterUpdateProgress

typedef void(* LogicalOutputPluginWriterUpdateProgress) (struct LogicalDecodingContext *lr, XLogRecPtr Ptr, TransactionId xid, bool skipped_xact)

Definition at line 27 of file logical.h.

◆ LogicalOutputPluginWriterWrite

typedef void(* LogicalOutputPluginWriterWrite) (struct LogicalDecodingContext *lr, XLogRecPtr Ptr, TransactionId xid, bool last_write)

Definition at line 19 of file logical.h.

Function Documentation

◆ CheckLogicalDecodingRequirements()

void CheckLogicalDecodingRequirements ( void  )

Definition at line 109 of file logical.c.

110 {
112 
113  /*
114  * NB: Adding a new requirement likely means that RestoreSlotFromDisk()
115  * needs the same check.
116  */
117 
119  ereport(ERROR,
120  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
121  errmsg("logical decoding requires \"wal_level\" >= \"logical\"")));
122 
123  if (MyDatabaseId == InvalidOid)
124  ereport(ERROR,
125  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
126  errmsg("logical decoding requires a database connection")));
127 
128  if (RecoveryInProgress())
129  {
130  /*
131  * This check may have race conditions, but whenever
132  * XLOG_PARAMETER_CHANGE indicates that wal_level has changed, we
133  * verify that there are no existing logical replication slots. And to
134  * avoid races around creating a new slot,
135  * CheckLogicalDecodingRequirements() is called once before creating
136  * the slot, and once when logical decoding is initially starting up.
137  */
139  ereport(ERROR,
140  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
141  errmsg("logical decoding on standby requires \"wal_level\" >= \"logical\" on the primary")));
142  }
143 }
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
Oid MyDatabaseId
Definition: globals.c:93
#define InvalidOid
Definition: postgres_ext.h:36
void CheckSlotRequirements(void)
Definition: slot.c:1390
bool RecoveryInProgress(void)
Definition: xlog.c:6334
int wal_level
Definition: xlog.c:131
WalLevel GetActiveWalLevelOnStandby(void)
Definition: xlog.c:4859
@ WAL_LEVEL_LOGICAL
Definition: xlog.h:76

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

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

◆ 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 496 of file logical.c.

503 {
505  ReplicationSlot *slot;
506  MemoryContext old_context;
507 
508  /* shorter lines... */
509  slot = MyReplicationSlot;
510 
511  /* first some sanity checks that are unlikely to be violated */
512  if (slot == NULL)
513  elog(ERROR, "cannot perform logical decoding without an acquired slot");
514 
515  /* make sure the passed slot is suitable, these are user facing errors */
516  if (SlotIsPhysical(slot))
517  ereport(ERROR,
518  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
519  errmsg("cannot use physical replication slot for logical decoding")));
520 
521  /*
522  * We need to access the system tables during decoding to build the
523  * logical changes unless we are in fast_forward mode where no changes are
524  * generated.
525  */
526  if (slot->data.database != MyDatabaseId && !fast_forward)
527  ereport(ERROR,
528  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
529  errmsg("replication slot \"%s\" was not created in this database",
530  NameStr(slot->data.name))));
531 
532  /*
533  * The slots being synced from the primary can't be used for decoding as
534  * they are used after failover. However, we do allow advancing the LSNs
535  * during the synchronization of slots. See update_local_synced_slot.
536  */
538  ereport(ERROR,
539  errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
540  errmsg("cannot use replication slot \"%s\" for logical decoding",
541  NameStr(slot->data.name)),
542  errdetail("This replication slot is being synchronized from the primary server."),
543  errhint("Specify another replication slot."));
544 
545  /*
546  * Check if slot has been invalidated due to max_slot_wal_keep_size. Avoid
547  * "cannot get changes" wording in this errmsg because that'd be
548  * confusingly ambiguous about no changes being available when called from
549  * pg_logical_slot_get_changes_guts().
550  */
552  ereport(ERROR,
553  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
554  errmsg("can no longer get changes from replication slot \"%s\"",
556  errdetail("This slot has been invalidated because it exceeded the maximum reserved size.")));
557 
559  ereport(ERROR,
560  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
561  errmsg("can no longer get changes from replication slot \"%s\"",
563  errdetail("This slot has been invalidated because it was conflicting with recovery.")));
564 
567 
568  if (start_lsn == InvalidXLogRecPtr)
569  {
570  /* continue from last position */
571  start_lsn = slot->data.confirmed_flush;
572  }
573  else if (start_lsn < slot->data.confirmed_flush)
574  {
575  /*
576  * It might seem like we should error out in this case, but it's
577  * pretty common for a client to acknowledge a LSN it doesn't have to
578  * do anything for, and thus didn't store persistently, because the
579  * xlog records didn't result in anything relevant for logical
580  * decoding. Clients have to be able to do that to support synchronous
581  * replication.
582  *
583  * Starting at a different LSN than requested might not catch certain
584  * kinds of client errors; so the client may wish to check that
585  * confirmed_flush_lsn matches its expectations.
586  */
587  elog(LOG, "%X/%X has been already streamed, forwarding to %X/%X",
588  LSN_FORMAT_ARGS(start_lsn),
590 
591  start_lsn = slot->data.confirmed_flush;
592  }
593 
594  ctx = StartupDecodingContext(output_plugin_options,
595  start_lsn, InvalidTransactionId, false,
596  fast_forward, false, xl_routine, prepare_write,
597  do_write, update_progress);
598 
599  /* call output plugin initialization callback */
600  old_context = MemoryContextSwitchTo(ctx->context);
601  if (ctx->callbacks.startup_cb != NULL)
602  startup_cb_wrapper(ctx, &ctx->options, false);
603  MemoryContextSwitchTo(old_context);
604 
605  /*
606  * We allow decoding of prepared transactions when the two_phase is
607  * enabled at the time of slot creation, or when the two_phase option is
608  * given at the streaming start, provided the plugin supports all the
609  * callbacks for two-phase.
610  */
611  ctx->twophase &= (slot->data.two_phase || ctx->twophase_opt_given);
612 
613  /* Mark slot to allow two_phase decoding if not already marked */
614  if (ctx->twophase && !slot->data.two_phase)
615  {
616  SpinLockAcquire(&slot->mutex);
617  slot->data.two_phase = true;
618  slot->data.two_phase_at = start_lsn;
619  SpinLockRelease(&slot->mutex);
622  SnapBuildSetTwoPhaseAt(ctx->snapshot_builder, start_lsn);
623  }
624 
626 
627  ereport(LOG,
628  (errmsg("starting logical decoding for slot \"%s\"",
629  NameStr(slot->data.name)),
630  errdetail("Streaming transactions committing after %X/%X, reading WAL from %X/%X.",
632  LSN_FORMAT_ARGS(slot->data.restart_lsn))));
633 
634  return ctx;
635 }
#define NameStr(name)
Definition: c.h:751
#define Assert(condition)
Definition: c.h:863
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errhint(const char *fmt,...)
Definition: elog.c:1317
#define LOG
Definition: elog.h:31
#define elog(elevel,...)
Definition: elog.h:225
static LogicalDecodingContext * StartupDecodingContext(List *output_plugin_options, XLogRecPtr start_lsn, TransactionId xmin_horizon, bool need_full_snapshot, bool fast_forward, bool in_create, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
Definition: logical.c:150
static void startup_cb_wrapper(LogicalDecodingContext *ctx, OutputPluginOptions *opt, bool is_init)
Definition: logical.c:791
const void * data
MemoryContextSwitchTo(old_ctx)
void ReplicationSlotMarkDirty(void)
Definition: slot.c:1038
ReplicationSlot * MyReplicationSlot
Definition: slot.c:138
void ReplicationSlotSave(void)
Definition: slot.c:1020
#define SlotIsPhysical(slot)
Definition: slot.h:216
@ RS_INVAL_WAL_REMOVED
Definition: slot.h:54
@ RS_INVAL_NONE
Definition: slot.h:52
bool IsSyncingReplicationSlots(void)
Definition: slotsync.c:1649
void SnapBuildSetTwoPhaseAt(SnapBuild *builder, XLogRecPtr ptr)
Definition: snapbuild.c:295
#define SpinLockRelease(lock)
Definition: spin.h:61
#define SpinLockAcquire(lock)
Definition: spin.h:59
OutputPluginOptions options
Definition: logical.h:54
MemoryContext context
Definition: logical.h:36
struct SnapBuild * snapshot_builder
Definition: logical.h:44
OutputPluginCallbacks callbacks
Definition: logical.h:53
struct ReorderBuffer * reorder
Definition: logical.h:43
LogicalDecodeStartupCB startup_cb
XLogRecPtr restart_lsn
Definition: slot.h:96
XLogRecPtr confirmed_flush
Definition: slot.h:107
ReplicationSlotInvalidationCause invalidated
Definition: slot.h:99
slock_t mutex
Definition: slot.h:154
ReplicationSlotPersistentData data
Definition: slot.h:181
#define InvalidTransactionId
Definition: transam.h:31
#define LSN_FORMAT_ARGS(lsn)
Definition: xlogdefs.h:43
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28

References Assert, LogicalDecodingContext::callbacks, ReplicationSlotPersistentData::confirmed_flush, LogicalDecodingContext::context, ReplicationSlot::data, data, ReplicationSlotPersistentData::database, elog, ereport, errcode(), errdetail(), errhint(), errmsg(), ERROR, ReplicationSlotPersistentData::invalidated, InvalidTransactionId, InvalidXLogRecPtr, IsSyncingReplicationSlots(), LOG, LSN_FORMAT_ARGS, MemoryContextSwitchTo(), ReplicationSlot::mutex, MyDatabaseId, MyReplicationSlot, ReplicationSlotPersistentData::name, NameStr, LogicalDecodingContext::options, ReorderBuffer::output_rewrites, OutputPluginOptions::receive_rewrites, RecoveryInProgress(), LogicalDecodingContext::reorder, ReplicationSlotMarkDirty(), ReplicationSlotSave(), ReplicationSlotPersistentData::restart_lsn, RS_INVAL_NONE, RS_INVAL_WAL_REMOVED, SlotIsPhysical, SnapBuildSetTwoPhaseAt(), LogicalDecodingContext::snapshot_builder, SpinLockAcquire, SpinLockRelease, OutputPluginCallbacks::startup_cb, startup_cb_wrapper(), StartupDecodingContext(), ReplicationSlotPersistentData::synced, ReplicationSlotPersistentData::two_phase, ReplicationSlotPersistentData::two_phase_at, LogicalDecodingContext::twophase, and LogicalDecodingContext::twophase_opt_given.

Referenced by LogicalReplicationSlotHasPendingWal(), LogicalSlotAdvanceAndCheckSnapState(), pg_logical_slot_get_changes_guts(), and StartLogicalReplication().

◆ 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 330 of file logical.c.

338 {
339  TransactionId xmin_horizon = InvalidTransactionId;
340  ReplicationSlot *slot;
341  NameData plugin_name;
343  MemoryContext old_context;
344 
345  /*
346  * On a standby, this check is also required while creating the slot.
347  * Check the comments in the function.
348  */
350 
351  /* shorter lines... */
352  slot = MyReplicationSlot;
353 
354  /* first some sanity checks that are unlikely to be violated */
355  if (slot == NULL)
356  elog(ERROR, "cannot perform logical decoding without an acquired slot");
357 
358  if (plugin == NULL)
359  elog(ERROR, "cannot initialize logical decoding without a specified plugin");
360 
361  /* Make sure the passed slot is suitable. These are user facing errors. */
362  if (SlotIsPhysical(slot))
363  ereport(ERROR,
364  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
365  errmsg("cannot use physical replication slot for logical decoding")));
366 
367  if (slot->data.database != MyDatabaseId)
368  ereport(ERROR,
369  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
370  errmsg("replication slot \"%s\" was not created in this database",
371  NameStr(slot->data.name))));
372 
373  if (IsTransactionState() &&
375  ereport(ERROR,
376  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
377  errmsg("cannot create logical replication slot in transaction that has performed writes")));
378 
379  /*
380  * Register output plugin name with slot. We need the mutex to avoid
381  * concurrent reading of a partially copied string. But we don't want any
382  * complicated code while holding a spinlock, so do namestrcpy() outside.
383  */
384  namestrcpy(&plugin_name, plugin);
385  SpinLockAcquire(&slot->mutex);
386  slot->data.plugin = plugin_name;
387  SpinLockRelease(&slot->mutex);
388 
389  if (XLogRecPtrIsInvalid(restart_lsn))
391  else
392  {
393  SpinLockAcquire(&slot->mutex);
394  slot->data.restart_lsn = restart_lsn;
395  SpinLockRelease(&slot->mutex);
396  }
397 
398  /* ----
399  * This is a bit tricky: We need to determine a safe xmin horizon to start
400  * decoding from, to avoid starting from a running xacts record referring
401  * to xids whose rows have been vacuumed or pruned
402  * already. GetOldestSafeDecodingTransactionId() returns such a value, but
403  * without further interlock its return value might immediately be out of
404  * date.
405  *
406  * So we have to acquire the ProcArrayLock to prevent computation of new
407  * xmin horizons by other backends, get the safe decoding xid, and inform
408  * the slot machinery about the new limit. Once that's done the
409  * ProcArrayLock can be released as the slot machinery now is
410  * protecting against vacuum.
411  *
412  * Note that, temporarily, the data, not just the catalog, xmin has to be
413  * reserved if a data snapshot is to be exported. Otherwise the initial
414  * data snapshot created here is not guaranteed to be valid. After that
415  * the data xmin doesn't need to be managed anymore and the global xmin
416  * should be recomputed. As we are fine with losing the pegged data xmin
417  * after crash - no chance a snapshot would get exported anymore - we can
418  * get away with just setting the slot's
419  * effective_xmin. ReplicationSlotRelease will reset it again.
420  *
421  * ----
422  */
423  LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
424 
425  xmin_horizon = GetOldestSafeDecodingTransactionId(!need_full_snapshot);
426 
427  SpinLockAcquire(&slot->mutex);
428  slot->effective_catalog_xmin = xmin_horizon;
429  slot->data.catalog_xmin = xmin_horizon;
430  if (need_full_snapshot)
431  slot->effective_xmin = xmin_horizon;
432  SpinLockRelease(&slot->mutex);
433 
435 
436  LWLockRelease(ProcArrayLock);
437 
440 
441  ctx = StartupDecodingContext(NIL, restart_lsn, xmin_horizon,
442  need_full_snapshot, false, true,
443  xl_routine, prepare_write, do_write,
444  update_progress);
445 
446  /* call output plugin initialization callback */
447  old_context = MemoryContextSwitchTo(ctx->context);
448  if (ctx->callbacks.startup_cb != NULL)
449  startup_cb_wrapper(ctx, &ctx->options, true);
450  MemoryContextSwitchTo(old_context);
451 
452  /*
453  * We allow decoding of prepared transactions when the two_phase is
454  * enabled at the time of slot creation, or when the two_phase option is
455  * given at the streaming start, provided the plugin supports all the
456  * callbacks for two-phase.
457  */
458  ctx->twophase &= slot->data.two_phase;
459 
461 
462  return ctx;
463 }
uint32 TransactionId
Definition: c.h:657
void CheckLogicalDecodingRequirements(void)
Definition: logical.c:109
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
@ LW_EXCLUSIVE
Definition: lwlock.h:114
void namestrcpy(Name name, const char *str)
Definition: name.c:233
#define NIL
Definition: pg_list.h:68
static const char * plugin
TransactionId GetOldestSafeDecodingTransactionId(bool catalogOnly)
Definition: procarray.c:2949
void ReplicationSlotReserveWal(void)
Definition: slot.c:1429
void ReplicationSlotsComputeRequiredXmin(bool already_locked)
Definition: slot.c:1077
TransactionId catalog_xmin
Definition: slot.h:93
TransactionId effective_catalog_xmin
Definition: slot.h:178
TransactionId effective_xmin
Definition: slot.h:177
Definition: c.h:746
bool IsTransactionState(void)
Definition: xact.c:386
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:440
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29

References LogicalDecodingContext::callbacks, ReplicationSlotPersistentData::catalog_xmin, CheckLogicalDecodingRequirements(), LogicalDecodingContext::context, 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, plugin, ReplicationSlotPersistentData::plugin, OutputPluginOptions::receive_rewrites, LogicalDecodingContext::reorder, ReplicationSlotMarkDirty(), ReplicationSlotReserveWal(), ReplicationSlotSave(), ReplicationSlotsComputeRequiredXmin(), ReplicationSlotPersistentData::restart_lsn, SlotIsPhysical, SpinLockAcquire, SpinLockRelease, OutputPluginCallbacks::startup_cb, startup_cb_wrapper(), StartupDecodingContext(), ReplicationSlotPersistentData::two_phase, LogicalDecodingContext::twophase, and XLogRecPtrIsInvalid.

Referenced by create_logical_replication_slot(), and CreateReplicationSlot().

◆ DecodingContextFindStartpoint()

void DecodingContextFindStartpoint ( LogicalDecodingContext ctx)

Definition at line 650 of file logical.c.

651 {
652  ReplicationSlot *slot = ctx->slot;
653 
654  /* Initialize from where to start reading WAL. */
655  XLogBeginRead(ctx->reader, slot->data.restart_lsn);
656 
657  elog(DEBUG1, "searching for logical decoding starting point, starting at %X/%X",
659 
660  /* Wait for a consistent starting point */
661  for (;;)
662  {
663  XLogRecord *record;
664  char *err = NULL;
665 
666  /* the read_page callback waits for new WAL */
667  record = XLogReadRecord(ctx->reader, &err);
668  if (err)
669  elog(ERROR, "could not find logical decoding starting point: %s", err);
670  if (!record)
671  elog(ERROR, "could not find logical decoding starting point");
672 
674 
675  /* only continue till we found a consistent spot */
676  if (DecodingContextReady(ctx))
677  break;
678 
680  }
681 
682  SpinLockAcquire(&slot->mutex);
683  slot->data.confirmed_flush = ctx->reader->EndRecPtr;
684  if (slot->data.two_phase)
685  slot->data.two_phase_at = ctx->reader->EndRecPtr;
686  SpinLockRelease(&slot->mutex);
687 }
void LogicalDecodingProcessRecord(LogicalDecodingContext *ctx, XLogReaderState *record)
Definition: decode.c:88
#define DEBUG1
Definition: elog.h:30
void err(int eval, const char *fmt,...)
Definition: err.c:43
bool DecodingContextReady(LogicalDecodingContext *ctx)
Definition: logical.c:641
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
XLogReaderState * reader
Definition: logical.h:42
ReplicationSlot * slot
Definition: logical.h:39
XLogRecPtr EndRecPtr
Definition: xlogreader.h:207
XLogRecord * XLogReadRecord(XLogReaderState *state, char **errormsg)
Definition: xlogreader.c:389
void XLogBeginRead(XLogReaderState *state, XLogRecPtr RecPtr)
Definition: xlogreader.c:231

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

Referenced by create_logical_replication_slot(), and CreateReplicationSlot().

◆ DecodingContextReady()

bool DecodingContextReady ( LogicalDecodingContext ctx)

Definition at line 641 of file logical.c.

642 {
644 }
SnapBuildState SnapBuildCurrentState(SnapBuild *builder)
Definition: snapbuild.c:277
@ SNAPBUILD_CONSISTENT
Definition: snapbuild.h:50

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

Referenced by DecodingContextFindStartpoint(), and LogicalSlotAdvanceAndCheckSnapState().

◆ filter_by_origin_cb_wrapper()

bool filter_by_origin_cb_wrapper ( LogicalDecodingContext ctx,
RepOriginId  origin_id 
)

Definition at line 1216 of file logical.c.

1217 {
1219  ErrorContextCallback errcallback;
1220  bool ret;
1221 
1222  Assert(!ctx->fast_forward);
1223 
1224  /* Push callback + info on the error context stack */
1225  state.ctx = ctx;
1226  state.callback_name = "filter_by_origin";
1227  state.report_location = InvalidXLogRecPtr;
1228  errcallback.callback = output_plugin_error_callback;
1229  errcallback.arg = (void *) &state;
1230  errcallback.previous = error_context_stack;
1231  error_context_stack = &errcallback;
1232 
1233  /* set output state */
1234  ctx->accept_writes = false;
1235  ctx->end_xact = false;
1236 
1237  /* do the actual work: call callback */
1238  ret = ctx->callbacks.filter_by_origin_cb(ctx, origin_id);
1239 
1240  /* Pop the error context stack */
1241  error_context_stack = errcallback.previous;
1242 
1243  return ret;
1244 }
ErrorContextCallback * error_context_stack
Definition: elog.c:94
static void output_plugin_error_callback(void *arg)
Definition: logical.c:772
struct ErrorContextCallback * previous
Definition: elog.h:296
void(* callback)(void *arg)
Definition: elog.h:297
LogicalDecodeFilterByOriginCB filter_by_origin_cb
Definition: regguts.h:323

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

Referenced by FilterByOrigin().

◆ filter_prepare_cb_wrapper()

bool filter_prepare_cb_wrapper ( LogicalDecodingContext ctx,
TransactionId  xid,
const char *  gid 
)

Definition at line 1184 of file logical.c.

1186 {
1188  ErrorContextCallback errcallback;
1189  bool ret;
1190 
1191  Assert(!ctx->fast_forward);
1192 
1193  /* Push callback + info on the error context stack */
1194  state.ctx = ctx;
1195  state.callback_name = "filter_prepare";
1196  state.report_location = InvalidXLogRecPtr;
1197  errcallback.callback = output_plugin_error_callback;
1198  errcallback.arg = (void *) &state;
1199  errcallback.previous = error_context_stack;
1200  error_context_stack = &errcallback;
1201 
1202  /* set output state */
1203  ctx->accept_writes = false;
1204  ctx->end_xact = false;
1205 
1206  /* do the actual work: call callback */
1207  ret = ctx->callbacks.filter_prepare_cb(ctx, xid, gid);
1208 
1209  /* Pop the error context stack */
1210  error_context_stack = errcallback.previous;
1211 
1212  return ret;
1213 }
LogicalDecodeFilterPrepareCB filter_prepare_cb

References LogicalDecodingContext::accept_writes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, LogicalDecodingContext::callbacks, LogicalDecodingContext::end_xact, error_context_stack, LogicalDecodingContext::fast_forward, OutputPluginCallbacks::filter_prepare_cb, InvalidXLogRecPtr, output_plugin_error_callback(), and ErrorContextCallback::previous.

Referenced by FilterPrepare().

◆ FreeDecodingContext()

void FreeDecodingContext ( LogicalDecodingContext ctx)

◆ LogicalConfirmReceivedLocation()

void LogicalConfirmReceivedLocation ( XLogRecPtr  lsn)

Definition at line 1837 of file logical.c.

1838 {
1839  Assert(lsn != InvalidXLogRecPtr);
1840 
1841  /* Do an unlocked check for candidate_lsn first. */
1844  {
1845  bool updated_xmin = false;
1846  bool updated_restart = false;
1847 
1849 
1851 
1852  /* if we're past the location required for bumping xmin, do so */
1855  {
1856  /*
1857  * We have to write the changed xmin to disk *before* we change
1858  * the in-memory value, otherwise after a crash we wouldn't know
1859  * that some catalog tuples might have been removed already.
1860  *
1861  * Ensure that by first writing to ->xmin and only update
1862  * ->effective_xmin once the new state is synced to disk. After a
1863  * crash ->effective_xmin is set to ->xmin.
1864  */
1867  {
1871  updated_xmin = true;
1872  }
1873  }
1874 
1877  {
1879 
1883  updated_restart = true;
1884  }
1885 
1887 
1888  /* first write new xmin to disk, so we know what's up after a crash */
1889  if (updated_xmin || updated_restart)
1890  {
1893  elog(DEBUG1, "updated xmin: %u restart: %u", updated_xmin, updated_restart);
1894  }
1895 
1896  /*
1897  * Now the new xmin is safely on disk, we can let the global value
1898  * advance. We do not take ProcArrayLock or similar since we only
1899  * advance xmin here and there's not much harm done by a concurrent
1900  * computation missing that.
1901  */
1902  if (updated_xmin)
1903  {
1907 
1910  }
1911  }
1912  else
1913  {
1917  }
1918 }
void ReplicationSlotsComputeRequiredLSN(void)
Definition: slot.c:1133
XLogRecPtr candidate_xmin_lsn
Definition: slot.h:197
XLogRecPtr candidate_restart_valid
Definition: slot.h:198
XLogRecPtr candidate_restart_lsn
Definition: slot.h:199
TransactionId candidate_catalog_xmin
Definition: slot.h:196
#define TransactionIdIsValid(xid)
Definition: transam.h:41

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(), LogicalSlotAdvanceAndCheckSnapState(), pg_logical_slot_get_changes_guts(), and ProcessStandbyReplyMessage().

◆ LogicalIncreaseRestartDecodingForSlot()

void LogicalIncreaseRestartDecodingForSlot ( XLogRecPtr  current_lsn,
XLogRecPtr  restart_lsn 
)

Definition at line 1761 of file logical.c.

1762 {
1763  bool updated_lsn = false;
1764  ReplicationSlot *slot;
1765 
1766  slot = MyReplicationSlot;
1767 
1768  Assert(slot != NULL);
1769  Assert(restart_lsn != InvalidXLogRecPtr);
1770  Assert(current_lsn != InvalidXLogRecPtr);
1771 
1772  SpinLockAcquire(&slot->mutex);
1773 
1774  /* don't overwrite if have a newer restart lsn */
1775  if (restart_lsn <= slot->data.restart_lsn)
1776  {
1777  SpinLockRelease(&slot->mutex);
1778  }
1779 
1780  /*
1781  * We might have already flushed far enough to directly accept this lsn,
1782  * in this case there is no need to check for existing candidate LSNs
1783  */
1784  else if (current_lsn <= slot->data.confirmed_flush)
1785  {
1786  slot->candidate_restart_valid = current_lsn;
1787  slot->candidate_restart_lsn = restart_lsn;
1788  SpinLockRelease(&slot->mutex);
1789 
1790  /* our candidate can directly be used */
1791  updated_lsn = true;
1792  }
1793 
1794  /*
1795  * Only increase if the previous values have been applied, otherwise we
1796  * might never end up updating if the receiver acks too slowly. A missed
1797  * value here will just cause some extra effort after reconnecting.
1798  */
1799  else if (slot->candidate_restart_valid == InvalidXLogRecPtr)
1800  {
1801  slot->candidate_restart_valid = current_lsn;
1802  slot->candidate_restart_lsn = restart_lsn;
1803  SpinLockRelease(&slot->mutex);
1804 
1805  elog(DEBUG1, "got new restart lsn %X/%X at %X/%X",
1806  LSN_FORMAT_ARGS(restart_lsn),
1807  LSN_FORMAT_ARGS(current_lsn));
1808  }
1809  else
1810  {
1811  XLogRecPtr candidate_restart_lsn;
1812  XLogRecPtr candidate_restart_valid;
1813  XLogRecPtr confirmed_flush;
1814 
1815  candidate_restart_lsn = slot->candidate_restart_lsn;
1816  candidate_restart_valid = slot->candidate_restart_valid;
1817  confirmed_flush = slot->data.confirmed_flush;
1818  SpinLockRelease(&slot->mutex);
1819 
1820  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",
1821  LSN_FORMAT_ARGS(restart_lsn),
1822  LSN_FORMAT_ARGS(current_lsn),
1823  LSN_FORMAT_ARGS(candidate_restart_lsn),
1824  LSN_FORMAT_ARGS(candidate_restart_valid),
1825  LSN_FORMAT_ARGS(confirmed_flush));
1826  }
1827 
1828  /* candidates are already valid with the current flush position, apply */
1829  if (updated_lsn)
1831 }
void LogicalConfirmReceivedLocation(XLogRecPtr lsn)
Definition: logical.c:1837
uint64 XLogRecPtr
Definition: xlogdefs.h:21

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

Referenced by SnapBuildProcessRunningXacts().

◆ LogicalIncreaseXminForSlot()

void LogicalIncreaseXminForSlot ( XLogRecPtr  current_lsn,
TransactionId  xmin 
)

Definition at line 1693 of file logical.c.

1694 {
1695  bool updated_xmin = false;
1696  ReplicationSlot *slot;
1697  bool got_new_xmin = false;
1698 
1699  slot = MyReplicationSlot;
1700 
1701  Assert(slot != NULL);
1702 
1703  SpinLockAcquire(&slot->mutex);
1704 
1705  /*
1706  * don't overwrite if we already have a newer xmin. This can happen if we
1707  * restart decoding in a slot.
1708  */
1710  {
1711  }
1712 
1713  /*
1714  * If the client has already confirmed up to this lsn, we directly can
1715  * mark this as accepted. This can happen if we restart decoding in a
1716  * slot.
1717  */
1718  else if (current_lsn <= slot->data.confirmed_flush)
1719  {
1720  slot->candidate_catalog_xmin = xmin;
1721  slot->candidate_xmin_lsn = current_lsn;
1722 
1723  /* our candidate can directly be used */
1724  updated_xmin = true;
1725  }
1726 
1727  /*
1728  * Only increase if the previous values have been applied, otherwise we
1729  * might never end up updating if the receiver acks too slowly.
1730  */
1731  else if (slot->candidate_xmin_lsn == InvalidXLogRecPtr)
1732  {
1733  slot->candidate_catalog_xmin = xmin;
1734  slot->candidate_xmin_lsn = current_lsn;
1735 
1736  /*
1737  * Log new xmin at an appropriate log level after releasing the
1738  * spinlock.
1739  */
1740  got_new_xmin = true;
1741  }
1742  SpinLockRelease(&slot->mutex);
1743 
1744  if (got_new_xmin)
1745  elog(DEBUG1, "got new catalog xmin %u at %X/%X", xmin,
1746  LSN_FORMAT_ARGS(current_lsn));
1747 
1748  /* candidate already valid with the current flush position, apply */
1749  if (updated_xmin)
1751 }
bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
Definition: transam.c:299

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

Referenced by SnapBuildProcessRunningXacts().

◆ LogicalReplicationSlotHasPendingWal()

bool LogicalReplicationSlotHasPendingWal ( XLogRecPtr  end_of_wal)

Definition at line 1981 of file logical.c.

1982 {
1983  bool has_pending_wal = false;
1984 
1986 
1987  PG_TRY();
1988  {
1990 
1991  /*
1992  * Create our decoding context in fast_forward mode, passing start_lsn
1993  * as InvalidXLogRecPtr, so that we start processing from the slot's
1994  * confirmed_flush.
1995  */
1997  NIL,
1998  true, /* fast_forward */
1999  XL_ROUTINE(.page_read = read_local_xlog_page,
2000  .segment_open = wal_segment_open,
2001  .segment_close = wal_segment_close),
2002  NULL, NULL, NULL);
2003 
2004  /*
2005  * Start reading at the slot's restart_lsn, which we know points to a
2006  * valid record.
2007  */
2009 
2010  /* Invalidate non-timetravel entries */
2012 
2013  /* Loop until the end of WAL or some changes are processed */
2014  while (!has_pending_wal && ctx->reader->EndRecPtr < end_of_wal)
2015  {
2016  XLogRecord *record;
2017  char *errm = NULL;
2018 
2019  record = XLogReadRecord(ctx->reader, &errm);
2020 
2021  if (errm)
2022  elog(ERROR, "could not find record for logical decoding: %s", errm);
2023 
2024  if (record != NULL)
2026 
2027  has_pending_wal = ctx->processing_required;
2028 
2030  }
2031 
2032  /* Clean up */
2033  FreeDecodingContext(ctx);
2035  }
2036  PG_CATCH();
2037  {
2038  /* clear all timetravel entries */
2040 
2041  PG_RE_THROW();
2042  }
2043  PG_END_TRY();
2044 
2045  return has_pending_wal;
2046 }
#define PG_RE_THROW()
Definition: elog.h:412
#define PG_TRY(...)
Definition: elog.h:371
#define PG_END_TRY(...)
Definition: elog.h:396
#define PG_CATCH(...)
Definition: elog.h:381
void InvalidateSystemCaches(void)
Definition: inval.c:849
void FreeDecodingContext(LogicalDecodingContext *ctx)
Definition: logical.c:694
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: logical.c:496
#define XL_ROUTINE(...)
Definition: xlogreader.h:117
void wal_segment_close(XLogReaderState *state)
Definition: xlogutils.c:842
void wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, TimeLineID *tli_p)
Definition: xlogutils.c:817
int read_local_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, char *cur_page)
Definition: xlogutils.c:861

References Assert, CHECK_FOR_INTERRUPTS, CreateDecodingContext(), ReplicationSlot::data, elog, XLogReaderState::EndRecPtr, ERROR, FreeDecodingContext(), InvalidateSystemCaches(), InvalidXLogRecPtr, LogicalDecodingProcessRecord(), MyReplicationSlot, NIL, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, LogicalDecodingContext::processing_required, read_local_xlog_page(), LogicalDecodingContext::reader, ReplicationSlotPersistentData::restart_lsn, wal_segment_close(), wal_segment_open(), XL_ROUTINE, XLogBeginRead(), and XLogReadRecord().

Referenced by binary_upgrade_logical_slot_has_caught_up().

◆ LogicalSlotAdvanceAndCheckSnapState()

XLogRecPtr LogicalSlotAdvanceAndCheckSnapState ( XLogRecPtr  moveto,
bool found_consistent_snapshot 
)

Definition at line 2063 of file logical.c.

2065 {
2067  ResourceOwner old_resowner = CurrentResourceOwner;
2068  XLogRecPtr retlsn;
2069 
2070  Assert(moveto != InvalidXLogRecPtr);
2071 
2072  if (found_consistent_snapshot)
2073  *found_consistent_snapshot = false;
2074 
2075  PG_TRY();
2076  {
2077  /*
2078  * Create our decoding context in fast_forward mode, passing start_lsn
2079  * as InvalidXLogRecPtr, so that we start processing from my slot's
2080  * confirmed_flush.
2081  */
2083  NIL,
2084  true, /* fast_forward */
2085  XL_ROUTINE(.page_read = read_local_xlog_page,
2086  .segment_open = wal_segment_open,
2087  .segment_close = wal_segment_close),
2088  NULL, NULL, NULL);
2089 
2090  /*
2091  * Wait for specified streaming replication standby servers (if any)
2092  * to confirm receipt of WAL up to moveto lsn.
2093  */
2095 
2096  /*
2097  * Start reading at the slot's restart_lsn, which we know to point to
2098  * a valid record.
2099  */
2101 
2102  /* invalidate non-timetravel entries */
2104 
2105  /* Decode records until we reach the requested target */
2106  while (ctx->reader->EndRecPtr < moveto)
2107  {
2108  char *errm = NULL;
2109  XLogRecord *record;
2110 
2111  /*
2112  * Read records. No changes are generated in fast_forward mode,
2113  * but snapbuilder/slot statuses are updated properly.
2114  */
2115  record = XLogReadRecord(ctx->reader, &errm);
2116  if (errm)
2117  elog(ERROR, "could not find record while advancing replication slot: %s",
2118  errm);
2119 
2120  /*
2121  * Process the record. Storage-level changes are ignored in
2122  * fast_forward mode, but other modules (such as snapbuilder)
2123  * might still have critical updates to do.
2124  */
2125  if (record)
2127 
2129  }
2130 
2131  if (found_consistent_snapshot && DecodingContextReady(ctx))
2132  *found_consistent_snapshot = true;
2133 
2134  /*
2135  * Logical decoding could have clobbered CurrentResourceOwner during
2136  * transaction management, so restore the executor's value. (This is
2137  * a kluge, but it's not worth cleaning up right now.)
2138  */
2139  CurrentResourceOwner = old_resowner;
2140 
2141  if (ctx->reader->EndRecPtr != InvalidXLogRecPtr)
2142  {
2144 
2145  /*
2146  * If only the confirmed_flush LSN has changed the slot won't get
2147  * marked as dirty by the above. Callers on the walsender
2148  * interface are expected to keep track of their own progress and
2149  * don't need it written out. But SQL-interface users cannot
2150  * specify their own start positions and it's harder for them to
2151  * keep track of their progress, so we should make more of an
2152  * effort to save it for them.
2153  *
2154  * Dirty the slot so it is written out at the next checkpoint. The
2155  * LSN position advanced to may still be lost on a crash but this
2156  * makes the data consistent after a clean shutdown.
2157  */
2159  }
2160 
2162 
2163  /* free context, call shutdown callback */
2164  FreeDecodingContext(ctx);
2165 
2167  }
2168  PG_CATCH();
2169  {
2170  /* clear all timetravel entries */
2172 
2173  PG_RE_THROW();
2174  }
2175  PG_END_TRY();
2176 
2177  return retlsn;
2178 }
ResourceOwner CurrentResourceOwner
Definition: resowner.c:165
void WaitForStandbyConfirmation(XLogRecPtr wait_for_lsn)
Definition: slot.c:2769

References Assert, CHECK_FOR_INTERRUPTS, ReplicationSlotPersistentData::confirmed_flush, CreateDecodingContext(), CurrentResourceOwner, ReplicationSlot::data, DecodingContextReady(), elog, XLogReaderState::EndRecPtr, ERROR, FreeDecodingContext(), InvalidateSystemCaches(), InvalidXLogRecPtr, LogicalConfirmReceivedLocation(), LogicalDecodingProcessRecord(), MyReplicationSlot, NIL, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, read_local_xlog_page(), LogicalDecodingContext::reader, ReplicationSlotMarkDirty(), ReplicationSlotPersistentData::restart_lsn, WaitForStandbyConfirmation(), wal_segment_close(), wal_segment_open(), XL_ROUTINE, XLogBeginRead(), and XLogReadRecord().

Referenced by pg_logical_replication_slot_advance(), and update_local_synced_slot().

◆ ResetLogicalStreamingState()

void ResetLogicalStreamingState ( void  )

Definition at line 1924 of file logical.c.

1925 {
1927  bsysscan = false;
1928 }
bool bsysscan
Definition: xact.c:99
TransactionId CheckXidAlive
Definition: xact.c:98

References bsysscan, CheckXidAlive, and InvalidTransactionId.

Referenced by AbortSubTransaction(), and AbortTransaction().

◆ UpdateDecodingStats()

void UpdateDecodingStats ( LogicalDecodingContext ctx)

Definition at line 1934 of file logical.c.

1935 {
1936  ReorderBuffer *rb = ctx->reorder;
1937  PgStat_StatReplSlotEntry repSlotStat;
1938 
1939  /* Nothing to do if we don't have any replication stats to be sent. */
1940  if (rb->spillBytes <= 0 && rb->streamBytes <= 0 && rb->totalBytes <= 0)
1941  return;
1942 
1943  elog(DEBUG2, "UpdateDecodingStats: updating stats %p %lld %lld %lld %lld %lld %lld %lld %lld",
1944  rb,
1945  (long long) rb->spillTxns,
1946  (long long) rb->spillCount,
1947  (long long) rb->spillBytes,
1948  (long long) rb->streamTxns,
1949  (long long) rb->streamCount,
1950  (long long) rb->streamBytes,
1951  (long long) rb->totalTxns,
1952  (long long) rb->totalBytes);
1953 
1954  repSlotStat.spill_txns = rb->spillTxns;
1955  repSlotStat.spill_count = rb->spillCount;
1956  repSlotStat.spill_bytes = rb->spillBytes;
1957  repSlotStat.stream_txns = rb->streamTxns;
1958  repSlotStat.stream_count = rb->streamCount;
1959  repSlotStat.stream_bytes = rb->streamBytes;
1960  repSlotStat.total_txns = rb->totalTxns;
1961  repSlotStat.total_bytes = rb->totalBytes;
1962 
1963  pgstat_report_replslot(ctx->slot, &repSlotStat);
1964 
1965  rb->spillTxns = 0;
1966  rb->spillCount = 0;
1967  rb->spillBytes = 0;
1968  rb->streamTxns = 0;
1969  rb->streamCount = 0;
1970  rb->streamBytes = 0;
1971  rb->totalTxns = 0;
1972  rb->totalBytes = 0;
1973 }
#define DEBUG2
Definition: elog.h:29
void pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
PgStat_Counter stream_count
Definition: pgstat.h:409
PgStat_Counter total_txns
Definition: pgstat.h:411
PgStat_Counter total_bytes
Definition: pgstat.h:412
PgStat_Counter spill_txns
Definition: pgstat.h:405
PgStat_Counter stream_txns
Definition: pgstat.h:408
PgStat_Counter spill_count
Definition: pgstat.h:406
PgStat_Counter stream_bytes
Definition: pgstat.h:410
PgStat_Counter spill_bytes
Definition: pgstat.h:407

References DEBUG2, elog, pgstat_report_replslot(), LogicalDecodingContext::reorder, LogicalDecodingContext::slot, PgStat_StatReplSlotEntry::spill_bytes, PgStat_StatReplSlotEntry::spill_count, PgStat_StatReplSlotEntry::spill_txns, ReorderBuffer::spillBytes, ReorderBuffer::spillCount, ReorderBuffer::spillTxns, PgStat_StatReplSlotEntry::stream_bytes, PgStat_StatReplSlotEntry::stream_count, PgStat_StatReplSlotEntry::stream_txns, ReorderBuffer::streamBytes, ReorderBuffer::streamCount, ReorderBuffer::streamTxns, PgStat_StatReplSlotEntry::total_bytes, PgStat_StatReplSlotEntry::total_txns, ReorderBuffer::totalBytes, and ReorderBuffer::totalTxns.

Referenced by DecodeAbort(), DecodeCommit(), DecodePrepare(), ReorderBufferSerializeTXN(), and ReorderBufferStreamTXN().