PostgreSQL Source Code  git master
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:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
Oid MyDatabaseId
Definition: globals.c:91
#define InvalidOid
Definition: postgres_ext.h:36
void CheckSlotRequirements(void)
Definition: slot.c:1358
bool RecoveryInProgress(void)
Definition: xlog.c:6290
int wal_level
Definition: xlog.c:131
WalLevel GetActiveWalLevelOnStandby(void)
Definition: xlog.c:4826
@ WAL_LEVEL_LOGICAL
Definition: xlog.h:74

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

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

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

650 {
651  ReplicationSlot *slot = ctx->slot;
652 
653  /* Initialize from where to start reading WAL. */
654  XLogBeginRead(ctx->reader, slot->data.restart_lsn);
655 
656  elog(DEBUG1, "searching for logical decoding starting point, starting at %X/%X",
658 
659  /* Wait for a consistent starting point */
660  for (;;)
661  {
662  XLogRecord *record;
663  char *err = NULL;
664 
665  /* the read_page callback waits for new WAL */
666  record = XLogReadRecord(ctx->reader, &err);
667  if (err)
668  elog(ERROR, "could not find logical decoding starting point: %s", err);
669  if (!record)
670  elog(ERROR, "could not find logical decoding starting point");
671 
673 
674  /* only continue till we found a consistent spot */
675  if (DecodingContextReady(ctx))
676  break;
677 
679  }
680 
681  SpinLockAcquire(&slot->mutex);
682  slot->data.confirmed_flush = ctx->reader->EndRecPtr;
683  if (slot->data.two_phase)
684  slot->data.two_phase_at = ctx->reader->EndRecPtr;
685  SpinLockRelease(&slot->mutex);
686 }
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:640
#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 640 of file logical.c.

641 {
643 }
SnapBuildState SnapBuildCurrentState(SnapBuild *builder)
Definition: snapbuild.c:406
@ SNAPBUILD_CONSISTENT
Definition: snapbuild.h:46

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

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

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

1835 {
1836  Assert(lsn != InvalidXLogRecPtr);
1837 
1838  /* Do an unlocked check for candidate_lsn first. */
1841  {
1842  bool updated_xmin = false;
1843  bool updated_restart = false;
1844 
1846 
1848 
1849  /* if we're past the location required for bumping xmin, do so */
1852  {
1853  /*
1854  * We have to write the changed xmin to disk *before* we change
1855  * the in-memory value, otherwise after a crash we wouldn't know
1856  * that some catalog tuples might have been removed already.
1857  *
1858  * Ensure that by first writing to ->xmin and only update
1859  * ->effective_xmin once the new state is synced to disk. After a
1860  * crash ->effective_xmin is set to ->xmin.
1861  */
1864  {
1868  updated_xmin = true;
1869  }
1870  }
1871 
1874  {
1876 
1880  updated_restart = true;
1881  }
1882 
1884 
1885  /* first write new xmin to disk, so we know what's up after a crash */
1886  if (updated_xmin || updated_restart)
1887  {
1890  elog(DEBUG1, "updated xmin: %u restart: %u", updated_xmin, updated_restart);
1891  }
1892 
1893  /*
1894  * Now the new xmin is safely on disk, we can let the global value
1895  * advance. We do not take ProcArrayLock or similar since we only
1896  * advance xmin here and there's not much harm done by a concurrent
1897  * computation missing that.
1898  */
1899  if (updated_xmin)
1900  {
1904 
1907  }
1908  }
1909  else
1910  {
1914  }
1915 }
void ReplicationSlotsComputeRequiredLSN(void)
Definition: slot.c:1101
XLogRecPtr candidate_xmin_lsn
Definition: slot.h:194
XLogRecPtr candidate_restart_valid
Definition: slot.h:195
XLogRecPtr candidate_restart_lsn
Definition: slot.h:196
TransactionId candidate_catalog_xmin
Definition: slot.h:193
#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 1760 of file logical.c.

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

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

1979 {
1980  bool has_pending_wal = false;
1981 
1983 
1984  PG_TRY();
1985  {
1987 
1988  /*
1989  * Create our decoding context in fast_forward mode, passing start_lsn
1990  * as InvalidXLogRecPtr, so that we start processing from the slot's
1991  * confirmed_flush.
1992  */
1994  NIL,
1995  true, /* fast_forward */
1996  XL_ROUTINE(.page_read = read_local_xlog_page,
1997  .segment_open = wal_segment_open,
1998  .segment_close = wal_segment_close),
1999  NULL, NULL, NULL);
2000 
2001  /*
2002  * Start reading at the slot's restart_lsn, which we know points to a
2003  * valid record.
2004  */
2006 
2007  /* Invalidate non-timetravel entries */
2009 
2010  /* Loop until the end of WAL or some changes are processed */
2011  while (!has_pending_wal && ctx->reader->EndRecPtr < end_of_wal)
2012  {
2013  XLogRecord *record;
2014  char *errm = NULL;
2015 
2016  record = XLogReadRecord(ctx->reader, &errm);
2017 
2018  if (errm)
2019  elog(ERROR, "could not find record for logical decoding: %s", errm);
2020 
2021  if (record != NULL)
2023 
2024  has_pending_wal = ctx->processing_required;
2025 
2027  }
2028 
2029  /* Clean up */
2030  FreeDecodingContext(ctx);
2032  }
2033  PG_CATCH();
2034  {
2035  /* clear all timetravel entries */
2037 
2038  PG_RE_THROW();
2039  }
2040  PG_END_TRY();
2041 
2042  return has_pending_wal;
2043 }
#define PG_RE_THROW()
Definition: elog.h:411
#define PG_TRY(...)
Definition: elog.h:370
#define PG_END_TRY(...)
Definition: elog.h:395
#define PG_CATCH(...)
Definition: elog.h:380
void InvalidateSystemCaches(void)
Definition: inval.c:792
void FreeDecodingContext(LogicalDecodingContext *ctx)
Definition: logical.c:693
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:495
#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 2060 of file logical.c.

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

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

1922 {
1924  bsysscan = false;
1925 }
bool bsysscan
Definition: xact.c:98
TransactionId CheckXidAlive
Definition: xact.c:97

References bsysscan, CheckXidAlive, and InvalidTransactionId.

Referenced by AbortSubTransaction(), and AbortTransaction().

◆ UpdateDecodingStats()

void UpdateDecodingStats ( LogicalDecodingContext ctx)

Definition at line 1931 of file logical.c.

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

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().