PostgreSQL Source Code  git master
reorderbuffer.h File Reference
#include "access/htup_details.h"
#include "lib/ilist.h"
#include "lib/pairingheap.h"
#include "storage/sinval.h"
#include "utils/hsearch.h"
#include "utils/relcache.h"
#include "utils/snapshot.h"
#include "utils/timestamp.h"
Include dependency graph for reorderbuffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ReorderBufferChange
 
struct  ReorderBufferTXN
 
struct  ReorderBuffer
 

Macros

#define RBTXN_HAS_CATALOG_CHANGES   0x0001
 
#define RBTXN_IS_SUBXACT   0x0002
 
#define RBTXN_IS_SERIALIZED   0x0004
 
#define RBTXN_IS_SERIALIZED_CLEAR   0x0008
 
#define RBTXN_IS_STREAMED   0x0010
 
#define RBTXN_HAS_PARTIAL_CHANGE   0x0020
 
#define RBTXN_PREPARE   0x0040
 
#define RBTXN_SKIPPED_PREPARE   0x0080
 
#define RBTXN_HAS_STREAMABLE_CHANGE   0x0100
 
#define rbtxn_has_catalog_changes(txn)
 
#define rbtxn_is_known_subxact(txn)
 
#define rbtxn_is_serialized(txn)
 
#define rbtxn_is_serialized_clear(txn)
 
#define rbtxn_has_partial_change(txn)
 
#define rbtxn_has_streamable_change(txn)
 
#define rbtxn_is_streamed(txn)
 
#define rbtxn_prepared(txn)
 
#define rbtxn_skip_prepared(txn)
 
#define rbtxn_is_toptxn(txn)
 
#define rbtxn_is_subtxn(txn)
 
#define rbtxn_get_toptxn(txn)
 

Typedefs

typedef enum ReorderBufferChangeType ReorderBufferChangeType
 
typedef struct ReorderBufferChange ReorderBufferChange
 
typedef struct ReorderBufferTXN ReorderBufferTXN
 
typedef struct ReorderBuffer ReorderBuffer
 
typedef void(* ReorderBufferApplyChangeCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
 
typedef void(* ReorderBufferApplyTruncateCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
 
typedef void(* ReorderBufferBeginCB) (ReorderBuffer *rb, ReorderBufferTXN *txn)
 
typedef void(* ReorderBufferCommitCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
 
typedef void(* ReorderBufferMessageCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size sz, const char *message)
 
typedef void(* ReorderBufferBeginPrepareCB) (ReorderBuffer *rb, ReorderBufferTXN *txn)
 
typedef void(* ReorderBufferPrepareCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
 
typedef void(* ReorderBufferCommitPreparedCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
 
typedef void(* ReorderBufferRollbackPreparedCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr prepare_end_lsn, TimestampTz prepare_time)
 
typedef void(* ReorderBufferStreamStartCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr first_lsn)
 
typedef void(* ReorderBufferStreamStopCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr last_lsn)
 
typedef void(* ReorderBufferStreamAbortCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr abort_lsn)
 
typedef void(* ReorderBufferStreamPrepareCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
 
typedef void(* ReorderBufferStreamCommitCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
 
typedef void(* ReorderBufferStreamChangeCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
 
typedef void(* ReorderBufferStreamMessageCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size sz, const char *message)
 
typedef void(* ReorderBufferStreamTruncateCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
 
typedef void(* ReorderBufferUpdateProgressTxnCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr lsn)
 

Enumerations

enum  DebugLogicalRepStreamingMode { DEBUG_LOGICAL_REP_STREAMING_BUFFERED , DEBUG_LOGICAL_REP_STREAMING_IMMEDIATE }
 
enum  ReorderBufferChangeType {
  REORDER_BUFFER_CHANGE_INSERT , REORDER_BUFFER_CHANGE_UPDATE , REORDER_BUFFER_CHANGE_DELETE , REORDER_BUFFER_CHANGE_MESSAGE ,
  REORDER_BUFFER_CHANGE_INVALIDATION , REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT , REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID , REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID ,
  REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT , REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM , REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT , REORDER_BUFFER_CHANGE_TRUNCATE
}
 

Functions

ReorderBufferReorderBufferAllocate (void)
 
void ReorderBufferFree (ReorderBuffer *rb)
 
HeapTuple ReorderBufferGetTupleBuf (ReorderBuffer *rb, Size tuple_len)
 
void ReorderBufferReturnTupleBuf (HeapTuple tuple)
 
ReorderBufferChangeReorderBufferGetChange (ReorderBuffer *rb)
 
void ReorderBufferReturnChange (ReorderBuffer *rb, ReorderBufferChange *change, bool upd_mem)
 
OidReorderBufferGetRelids (ReorderBuffer *rb, int nrelids)
 
void ReorderBufferReturnRelids (ReorderBuffer *rb, Oid *relids)
 
void ReorderBufferQueueChange (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, ReorderBufferChange *change, bool toast_insert)
 
void ReorderBufferQueueMessage (ReorderBuffer *rb, TransactionId xid, Snapshot snap, XLogRecPtr lsn, bool transactional, const char *prefix, Size message_size, const char *message)
 
void ReorderBufferCommit (ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn)
 
void ReorderBufferFinishPrepared (ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, XLogRecPtr two_phase_at, TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn, char *gid, bool is_commit)
 
void ReorderBufferAssignChild (ReorderBuffer *rb, TransactionId xid, TransactionId subxid, XLogRecPtr lsn)
 
void ReorderBufferCommitChild (ReorderBuffer *rb, TransactionId xid, TransactionId subxid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn)
 
void ReorderBufferAbort (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, TimestampTz abort_time)
 
void ReorderBufferAbortOld (ReorderBuffer *rb, TransactionId oldestRunningXid)
 
void ReorderBufferForget (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
 
void ReorderBufferInvalidate (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
 
void ReorderBufferSetBaseSnapshot (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, Snapshot snap)
 
void ReorderBufferAddSnapshot (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, Snapshot snap)
 
void ReorderBufferAddNewCommandId (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, CommandId cid)
 
void ReorderBufferAddNewTupleCids (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, RelFileLocator locator, ItemPointerData tid, CommandId cmin, CommandId cmax, CommandId combocid)
 
void ReorderBufferAddInvalidations (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, Size nmsgs, SharedInvalidationMessage *msgs)
 
void ReorderBufferImmediateInvalidation (ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations)
 
void ReorderBufferProcessXid (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
 
void ReorderBufferXidSetCatalogChanges (ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
 
bool ReorderBufferXidHasCatalogChanges (ReorderBuffer *rb, TransactionId xid)
 
bool ReorderBufferXidHasBaseSnapshot (ReorderBuffer *rb, TransactionId xid)
 
bool ReorderBufferRememberPrepareInfo (ReorderBuffer *rb, TransactionId xid, XLogRecPtr prepare_lsn, XLogRecPtr end_lsn, TimestampTz prepare_time, RepOriginId origin_id, XLogRecPtr origin_lsn)
 
void ReorderBufferSkipPrepare (ReorderBuffer *rb, TransactionId xid)
 
void ReorderBufferPrepare (ReorderBuffer *rb, TransactionId xid, char *gid)
 
ReorderBufferTXNReorderBufferGetOldestTXN (ReorderBuffer *rb)
 
TransactionId ReorderBufferGetOldestXmin (ReorderBuffer *rb)
 
TransactionIdReorderBufferGetCatalogChangesXacts (ReorderBuffer *rb)
 
void ReorderBufferSetRestartPoint (ReorderBuffer *rb, XLogRecPtr ptr)
 
void StartupReorderBuffer (void)
 

Variables

PGDLLIMPORT int logical_decoding_work_mem
 
PGDLLIMPORT int debug_logical_replication_streaming
 

Macro Definition Documentation

◆ rbtxn_get_toptxn

#define rbtxn_get_toptxn (   txn)
Value:
( \
rbtxn_is_subtxn(txn) ? (txn)->toptxn : (txn) \
)

Definition at line 247 of file reorderbuffer.h.

◆ RBTXN_HAS_CATALOG_CHANGES

#define RBTXN_HAS_CATALOG_CHANGES   0x0001

Definition at line 162 of file reorderbuffer.h.

◆ rbtxn_has_catalog_changes

#define rbtxn_has_catalog_changes (   txn)
Value:
( \
((txn)->txn_flags & RBTXN_HAS_CATALOG_CHANGES) != 0 \
)
#define RBTXN_HAS_CATALOG_CHANGES

Definition at line 173 of file reorderbuffer.h.

◆ RBTXN_HAS_PARTIAL_CHANGE

#define RBTXN_HAS_PARTIAL_CHANGE   0x0020

Definition at line 167 of file reorderbuffer.h.

◆ rbtxn_has_partial_change

#define rbtxn_has_partial_change (   txn)
Value:
( \
((txn)->txn_flags & RBTXN_HAS_PARTIAL_CHANGE) != 0 \
)
#define RBTXN_HAS_PARTIAL_CHANGE

Definition at line 197 of file reorderbuffer.h.

◆ RBTXN_HAS_STREAMABLE_CHANGE

#define RBTXN_HAS_STREAMABLE_CHANGE   0x0100

Definition at line 170 of file reorderbuffer.h.

◆ rbtxn_has_streamable_change

#define rbtxn_has_streamable_change (   txn)
Value:
( \
((txn)->txn_flags & RBTXN_HAS_STREAMABLE_CHANGE) != 0 \
)
#define RBTXN_HAS_STREAMABLE_CHANGE

Definition at line 203 of file reorderbuffer.h.

◆ rbtxn_is_known_subxact

#define rbtxn_is_known_subxact (   txn)
Value:
( \
((txn)->txn_flags & RBTXN_IS_SUBXACT) != 0 \
)
#define RBTXN_IS_SUBXACT

Definition at line 179 of file reorderbuffer.h.

◆ RBTXN_IS_SERIALIZED

#define RBTXN_IS_SERIALIZED   0x0004

Definition at line 164 of file reorderbuffer.h.

◆ rbtxn_is_serialized

#define rbtxn_is_serialized (   txn)
Value:
( \
((txn)->txn_flags & RBTXN_IS_SERIALIZED) != 0 \
)
#define RBTXN_IS_SERIALIZED

Definition at line 185 of file reorderbuffer.h.

◆ RBTXN_IS_SERIALIZED_CLEAR

#define RBTXN_IS_SERIALIZED_CLEAR   0x0008

Definition at line 165 of file reorderbuffer.h.

◆ rbtxn_is_serialized_clear

#define rbtxn_is_serialized_clear (   txn)
Value:
( \
((txn)->txn_flags & RBTXN_IS_SERIALIZED_CLEAR) != 0 \
)
#define RBTXN_IS_SERIALIZED_CLEAR

Definition at line 191 of file reorderbuffer.h.

◆ RBTXN_IS_STREAMED

#define RBTXN_IS_STREAMED   0x0010

Definition at line 166 of file reorderbuffer.h.

◆ rbtxn_is_streamed

#define rbtxn_is_streamed (   txn)
Value:
( \
((txn)->txn_flags & RBTXN_IS_STREAMED) != 0 \
)
#define RBTXN_IS_STREAMED

Definition at line 217 of file reorderbuffer.h.

◆ rbtxn_is_subtxn

#define rbtxn_is_subtxn (   txn)
Value:
( \
(txn)->toptxn != NULL \
)

Definition at line 241 of file reorderbuffer.h.

◆ RBTXN_IS_SUBXACT

#define RBTXN_IS_SUBXACT   0x0002

Definition at line 163 of file reorderbuffer.h.

◆ rbtxn_is_toptxn

#define rbtxn_is_toptxn (   txn)
Value:
( \
(txn)->toptxn == NULL \
)

Definition at line 235 of file reorderbuffer.h.

◆ RBTXN_PREPARE

#define RBTXN_PREPARE   0x0040

Definition at line 168 of file reorderbuffer.h.

◆ rbtxn_prepared

#define rbtxn_prepared (   txn)
Value:
( \
((txn)->txn_flags & RBTXN_PREPARE) != 0 \
)
#define RBTXN_PREPARE

Definition at line 223 of file reorderbuffer.h.

◆ rbtxn_skip_prepared

#define rbtxn_skip_prepared (   txn)
Value:
( \
((txn)->txn_flags & RBTXN_SKIPPED_PREPARE) != 0 \
)
#define RBTXN_SKIPPED_PREPARE

Definition at line 229 of file reorderbuffer.h.

◆ RBTXN_SKIPPED_PREPARE

#define RBTXN_SKIPPED_PREPARE   0x0080

Definition at line 169 of file reorderbuffer.h.

Typedef Documentation

◆ ReorderBuffer

typedef struct ReorderBuffer ReorderBuffer

Definition at line 23 of file reorderbuffer.h.

◆ ReorderBufferApplyChangeCB

typedef void(* ReorderBufferApplyChangeCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)

Definition at line 431 of file reorderbuffer.h.

◆ ReorderBufferApplyTruncateCB

typedef void(* ReorderBufferApplyTruncateCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)

Definition at line 437 of file reorderbuffer.h.

◆ ReorderBufferBeginCB

typedef void(* ReorderBufferBeginCB) (ReorderBuffer *rb, ReorderBufferTXN *txn)

Definition at line 444 of file reorderbuffer.h.

◆ ReorderBufferBeginPrepareCB

typedef void(* ReorderBufferBeginPrepareCB) (ReorderBuffer *rb, ReorderBufferTXN *txn)

Definition at line 461 of file reorderbuffer.h.

◆ ReorderBufferChange

◆ ReorderBufferChangeType

◆ ReorderBufferCommitCB

typedef void(* ReorderBufferCommitCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)

Definition at line 448 of file reorderbuffer.h.

◆ ReorderBufferCommitPreparedCB

typedef void(* ReorderBufferCommitPreparedCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)

Definition at line 470 of file reorderbuffer.h.

◆ ReorderBufferMessageCB

typedef void(* ReorderBufferMessageCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size sz, const char *message)

Definition at line 453 of file reorderbuffer.h.

◆ ReorderBufferPrepareCB

typedef void(* ReorderBufferPrepareCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)

Definition at line 465 of file reorderbuffer.h.

◆ ReorderBufferRollbackPreparedCB

typedef void(* ReorderBufferRollbackPreparedCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr prepare_end_lsn, TimestampTz prepare_time)

Definition at line 475 of file reorderbuffer.h.

◆ ReorderBufferStreamAbortCB

typedef void(* ReorderBufferStreamAbortCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr abort_lsn)

Definition at line 493 of file reorderbuffer.h.

◆ ReorderBufferStreamChangeCB

typedef void(* ReorderBufferStreamChangeCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)

Definition at line 511 of file reorderbuffer.h.

◆ ReorderBufferStreamCommitCB

typedef void(* ReorderBufferStreamCommitCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)

Definition at line 505 of file reorderbuffer.h.

◆ ReorderBufferStreamMessageCB

typedef void(* ReorderBufferStreamMessageCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size sz, const char *message)

Definition at line 518 of file reorderbuffer.h.

◆ ReorderBufferStreamPrepareCB

typedef void(* ReorderBufferStreamPrepareCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)

Definition at line 499 of file reorderbuffer.h.

◆ ReorderBufferStreamStartCB

typedef void(* ReorderBufferStreamStartCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr first_lsn)

Definition at line 481 of file reorderbuffer.h.

◆ ReorderBufferStreamStopCB

typedef void(* ReorderBufferStreamStopCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr last_lsn)

Definition at line 487 of file reorderbuffer.h.

◆ ReorderBufferStreamTruncateCB

typedef void(* ReorderBufferStreamTruncateCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)

Definition at line 527 of file reorderbuffer.h.

◆ ReorderBufferTXN

◆ ReorderBufferUpdateProgressTxnCB

typedef void(* ReorderBufferUpdateProgressTxnCB) (ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr lsn)

Definition at line 535 of file reorderbuffer.h.

Enumeration Type Documentation

◆ DebugLogicalRepStreamingMode

Enumerator
DEBUG_LOGICAL_REP_STREAMING_BUFFERED 
DEBUG_LOGICAL_REP_STREAMING_IMMEDIATE 

Definition at line 26 of file reorderbuffer.h.

27 {
DebugLogicalRepStreamingMode
Definition: reorderbuffer.h:27
@ DEBUG_LOGICAL_REP_STREAMING_IMMEDIATE
Definition: reorderbuffer.h:29
@ DEBUG_LOGICAL_REP_STREAMING_BUFFERED
Definition: reorderbuffer.h:28

◆ ReorderBufferChangeType

Enumerator
REORDER_BUFFER_CHANGE_INSERT 
REORDER_BUFFER_CHANGE_UPDATE 
REORDER_BUFFER_CHANGE_DELETE 
REORDER_BUFFER_CHANGE_MESSAGE 
REORDER_BUFFER_CHANGE_INVALIDATION 
REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT 
REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID 
REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID 
REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT 
REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM 
REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT 
REORDER_BUFFER_CHANGE_TRUNCATE 

Definition at line 45 of file reorderbuffer.h.

46 {
ReorderBufferChangeType
Definition: reorderbuffer.h:46
@ REORDER_BUFFER_CHANGE_INVALIDATION
Definition: reorderbuffer.h:51
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM
Definition: reorderbuffer.h:56
@ REORDER_BUFFER_CHANGE_INSERT
Definition: reorderbuffer.h:47
@ REORDER_BUFFER_CHANGE_MESSAGE
Definition: reorderbuffer.h:50
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT
Definition: reorderbuffer.h:57
@ REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID
Definition: reorderbuffer.h:53
@ REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID
Definition: reorderbuffer.h:54
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT
Definition: reorderbuffer.h:55
@ REORDER_BUFFER_CHANGE_TRUNCATE
Definition: reorderbuffer.h:58
@ REORDER_BUFFER_CHANGE_DELETE
Definition: reorderbuffer.h:49
@ REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT
Definition: reorderbuffer.h:52
@ REORDER_BUFFER_CHANGE_UPDATE
Definition: reorderbuffer.h:48

Function Documentation

◆ ReorderBufferAbort()

void ReorderBufferAbort ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn,
TimestampTz  abort_time 
)

Definition at line 2902 of file reorderbuffer.c.

2904 {
2905  ReorderBufferTXN *txn;
2906 
2907  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2908  false);
2909 
2910  /* unknown, nothing to remove */
2911  if (txn == NULL)
2912  return;
2913 
2914  txn->xact_time.abort_time = abort_time;
2915 
2916  /* For streamed transactions notify the remote node about the abort. */
2917  if (rbtxn_is_streamed(txn))
2918  {
2919  rb->stream_abort(rb, txn, lsn);
2920 
2921  /*
2922  * We might have decoded changes for this transaction that could load
2923  * the cache as per the current transaction's view (consider DDL's
2924  * happened in this transaction). We don't want the decoding of future
2925  * transactions to use those cache entries so execute invalidations.
2926  */
2927  if (txn->ninvalidations > 0)
2929  txn->invalidations);
2930  }
2931 
2932  /* cosmetic... */
2933  txn->final_lsn = lsn;
2934 
2935  /* remove potential on-disk data, and deallocate */
2936  ReorderBufferCleanupTXN(rb, txn);
2937 }
static void ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
void ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations)
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
#define rbtxn_is_streamed(txn)
SharedInvalidationMessage * invalidations
TimestampTz abort_time
XLogRecPtr final_lsn
union ReorderBufferTXN::@111 xact_time
ReorderBufferStreamAbortCB stream_abort
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28

References ReorderBufferTXN::abort_time, ReorderBufferTXN::final_lsn, ReorderBufferTXN::invalidations, InvalidXLogRecPtr, ReorderBufferTXN::ninvalidations, rbtxn_is_streamed, ReorderBufferCleanupTXN(), ReorderBufferImmediateInvalidation(), ReorderBufferTXNByXid(), ReorderBuffer::stream_abort, and ReorderBufferTXN::xact_time.

Referenced by DecodeAbort().

◆ ReorderBufferAbortOld()

void ReorderBufferAbortOld ( ReorderBuffer rb,
TransactionId  oldestRunningXid 
)

Definition at line 2947 of file reorderbuffer.c.

2948 {
2949  dlist_mutable_iter it;
2950 
2951  /*
2952  * Iterate through all (potential) toplevel TXNs and abort all that are
2953  * older than what possibly can be running. Once we've found the first
2954  * that is alive we stop, there might be some that acquired an xid earlier
2955  * but started writing later, but it's unlikely and they will be cleaned
2956  * up in a later call to this function.
2957  */
2959  {
2960  ReorderBufferTXN *txn;
2961 
2962  txn = dlist_container(ReorderBufferTXN, node, it.cur);
2963 
2964  if (TransactionIdPrecedes(txn->xid, oldestRunningXid))
2965  {
2966  elog(DEBUG2, "aborting old transaction %u", txn->xid);
2967 
2968  /* Notify the remote node about the crash/immediate restart. */
2969  if (rbtxn_is_streamed(txn))
2970  rb->stream_abort(rb, txn, InvalidXLogRecPtr);
2971 
2972  /* remove potential on-disk data, and deallocate this tx */
2973  ReorderBufferCleanupTXN(rb, txn);
2974  }
2975  else
2976  return;
2977  }
2978 }
#define DEBUG2
Definition: elog.h:29
#define elog(elevel,...)
Definition: elog.h:224
#define dlist_foreach_modify(iter, lhead)
Definition: ilist.h:640
#define dlist_container(type, membername, ptr)
Definition: ilist.h:593
TransactionId xid
dlist_head toplevel_by_lsn
dlist_node * cur
Definition: ilist.h:200
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280

References dlist_mutable_iter::cur, DEBUG2, dlist_container, dlist_foreach_modify, elog, InvalidXLogRecPtr, rbtxn_is_streamed, ReorderBufferCleanupTXN(), ReorderBuffer::stream_abort, ReorderBuffer::toplevel_by_lsn, TransactionIdPrecedes(), and ReorderBufferTXN::xid.

Referenced by standby_decode().

◆ ReorderBufferAddInvalidations()

void ReorderBufferAddInvalidations ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn,
Size  nmsgs,
SharedInvalidationMessage msgs 
)

Definition at line 3300 of file reorderbuffer.c.

3303 {
3304  ReorderBufferTXN *txn;
3305  MemoryContext oldcontext;
3306  ReorderBufferChange *change;
3307 
3308  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3309 
3310  oldcontext = MemoryContextSwitchTo(rb->context);
3311 
3312  /*
3313  * Collect all the invalidations under the top transaction, if available,
3314  * so that we can execute them all together. See comments atop this
3315  * function.
3316  */
3317  txn = rbtxn_get_toptxn(txn);
3318 
3319  Assert(nmsgs > 0);
3320 
3321  /* Accumulate invalidations. */
3322  if (txn->ninvalidations == 0)
3323  {
3324  txn->ninvalidations = nmsgs;
3326  palloc(sizeof(SharedInvalidationMessage) * nmsgs);
3327  memcpy(txn->invalidations, msgs,
3328  sizeof(SharedInvalidationMessage) * nmsgs);
3329  }
3330  else
3331  {
3334  (txn->ninvalidations + nmsgs));
3335 
3336  memcpy(txn->invalidations + txn->ninvalidations, msgs,
3337  nmsgs * sizeof(SharedInvalidationMessage));
3338  txn->ninvalidations += nmsgs;
3339  }
3340 
3341  change = ReorderBufferGetChange(rb);
3343  change->data.inval.ninvalidations = nmsgs;
3344  change->data.inval.invalidations = (SharedInvalidationMessage *)
3345  palloc(sizeof(SharedInvalidationMessage) * nmsgs);
3346  memcpy(change->data.inval.invalidations, msgs,
3347  sizeof(SharedInvalidationMessage) * nmsgs);
3348 
3349  ReorderBufferQueueChange(rb, xid, lsn, change, false);
3350 
3351  MemoryContextSwitchTo(oldcontext);
3352 }
#define Assert(condition)
Definition: c.h:858
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1540
void * palloc(Size size)
Definition: mcxt.c:1316
MemoryContextSwitchTo(old_ctx)
void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, ReorderBufferChange *change, bool toast_insert)
ReorderBufferChange * ReorderBufferGetChange(ReorderBuffer *rb)
#define rbtxn_get_toptxn(txn)
ReorderBufferChangeType action
Definition: reorderbuffer.h:76
union ReorderBufferChange::@105 data
struct ReorderBufferChange::@105::@110 inval
MemoryContext context

References ReorderBufferChange::action, Assert, ReorderBuffer::context, ReorderBufferChange::data, ReorderBufferChange::inval, ReorderBufferTXN::invalidations, MemoryContextSwitchTo(), ReorderBufferTXN::ninvalidations, palloc(), rbtxn_get_toptxn, REORDER_BUFFER_CHANGE_INVALIDATION, ReorderBufferGetChange(), ReorderBufferQueueChange(), ReorderBufferTXNByXid(), and repalloc().

Referenced by xact_decode().

◆ ReorderBufferAddNewCommandId()

void ReorderBufferAddNewCommandId ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn,
CommandId  cid 
)

◆ ReorderBufferAddNewTupleCids()

void ReorderBufferAddNewTupleCids ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn,
RelFileLocator  locator,
ItemPointerData  tid,
CommandId  cmin,
CommandId  cmax,
CommandId  combocid 
)

Definition at line 3263 of file reorderbuffer.c.

3267 {
3269  ReorderBufferTXN *txn;
3270 
3271  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3272 
3273  change->data.tuplecid.locator = locator;
3274  change->data.tuplecid.tid = tid;
3275  change->data.tuplecid.cmin = cmin;
3276  change->data.tuplecid.cmax = cmax;
3277  change->data.tuplecid.combocid = combocid;
3278  change->lsn = lsn;
3279  change->txn = txn;
3281 
3282  dlist_push_tail(&txn->tuplecids, &change->node);
3283  txn->ntuplecids++;
3284 }
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:364
struct ReorderBufferTXN * txn
Definition: reorderbuffer.h:79
struct ReorderBufferChange::@105::@109 tuplecid
dlist_head tuplecids

References ReorderBufferChange::action, ReorderBufferChange::data, dlist_push_tail(), ReorderBufferChange::lsn, ReorderBufferChange::node, ReorderBufferTXN::ntuplecids, REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID, ReorderBufferGetChange(), ReorderBufferTXNByXid(), ReorderBufferChange::tuplecid, ReorderBufferTXN::tuplecids, and ReorderBufferChange::txn.

Referenced by SnapBuildProcessNewCid().

◆ ReorderBufferAddSnapshot()

void ReorderBufferAddSnapshot ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn,
Snapshot  snap 
)

◆ ReorderBufferAllocate()

ReorderBuffer* ReorderBufferAllocate ( void  )

Definition at line 309 of file reorderbuffer.c.

310 {
311  ReorderBuffer *buffer;
312  HASHCTL hash_ctl;
313  MemoryContext new_ctx;
314 
315  Assert(MyReplicationSlot != NULL);
316 
317  /* allocate memory in own context, to have better accountability */
319  "ReorderBuffer",
321 
322  buffer =
323  (ReorderBuffer *) MemoryContextAlloc(new_ctx, sizeof(ReorderBuffer));
324 
325  memset(&hash_ctl, 0, sizeof(hash_ctl));
326 
327  buffer->context = new_ctx;
328 
329  buffer->change_context = SlabContextCreate(new_ctx,
330  "Change",
332  sizeof(ReorderBufferChange));
333 
334  buffer->txn_context = SlabContextCreate(new_ctx,
335  "TXN",
337  sizeof(ReorderBufferTXN));
338 
339  /*
340  * XXX the allocation sizes used below pre-date generation context's block
341  * growing code. These values should likely be benchmarked and set to
342  * more suitable values.
343  */
344  buffer->tup_context = GenerationContextCreate(new_ctx,
345  "Tuples",
349 
350  hash_ctl.keysize = sizeof(TransactionId);
351  hash_ctl.entrysize = sizeof(ReorderBufferTXNByIdEnt);
352  hash_ctl.hcxt = buffer->context;
353 
354  buffer->by_txn = hash_create("ReorderBufferByXid", 1000, &hash_ctl,
356 
358  buffer->by_txn_last_txn = NULL;
359 
360  buffer->outbuf = NULL;
361  buffer->outbufsize = 0;
362  buffer->size = 0;
363 
364  /* txn_heap is ordered by transaction size */
366 
367  buffer->spillTxns = 0;
368  buffer->spillCount = 0;
369  buffer->spillBytes = 0;
370  buffer->streamTxns = 0;
371  buffer->streamCount = 0;
372  buffer->streamBytes = 0;
373  buffer->totalTxns = 0;
374  buffer->totalBytes = 0;
375 
377 
378  dlist_init(&buffer->toplevel_by_lsn);
380  dclist_init(&buffer->catchange_txns);
381 
382  /*
383  * Ensure there's no stale data from prior uses of this slot, in case some
384  * prior exit avoided calling ReorderBufferFree. Failure to do this can
385  * produce duplicated txns, and it's very cheap if there's nothing there.
386  */
388 
389  return buffer;
390 }
#define NameStr(name)
Definition: c.h:746
uint32 TransactionId
Definition: c.h:652
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:352
MemoryContext GenerationContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: generation.c:160
#define HASH_CONTEXT
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
static void dlist_init(dlist_head *head)
Definition: ilist.h:314
static void dclist_init(dclist_head *head)
Definition: ilist.h:671
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1180
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
#define SLAB_DEFAULT_BLOCK_SIZE
Definition: memutils.h:189
#define SLAB_LARGE_BLOCK_SIZE
Definition: memutils.h:190
pairingheap * pairingheap_allocate(pairingheap_comparator compare, void *arg)
Definition: pairingheap.c:42
static int ReorderBufferTXNSizeCompare(const pairingheap_node *a, const pairingheap_node *b, void *arg)
struct ReorderBufferTXNByIdEnt ReorderBufferTXNByIdEnt
static void ReorderBufferCleanupSerializedTXNs(const char *slotname)
MemoryContext SlabContextCreate(MemoryContext parent, const char *name, Size blockSize, Size chunkSize)
Definition: slab.c:322
ReplicationSlot * MyReplicationSlot
Definition: slot.c:138
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
MemoryContext hcxt
Definition: hsearch.h:86
dlist_head txns_by_base_snapshot_lsn
dclist_head catchange_txns
MemoryContext change_context
ReorderBufferTXN * by_txn_last_txn
TransactionId by_txn_last_xid
MemoryContext tup_context
pairingheap * txn_heap
MemoryContext txn_context
XLogRecPtr current_restart_decoding_lsn
ReplicationSlotPersistentData data
Definition: slot.h:178
#define InvalidTransactionId
Definition: transam.h:31

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, ReorderBuffer::by_txn, ReorderBuffer::by_txn_last_txn, ReorderBuffer::by_txn_last_xid, ReorderBuffer::catchange_txns, ReorderBuffer::change_context, ReorderBuffer::context, ReorderBuffer::current_restart_decoding_lsn, CurrentMemoryContext, ReplicationSlot::data, dclist_init(), dlist_init(), HASHCTL::entrysize, GenerationContextCreate(), HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, HASHCTL::hcxt, InvalidTransactionId, InvalidXLogRecPtr, HASHCTL::keysize, MemoryContextAlloc(), MyReplicationSlot, ReplicationSlotPersistentData::name, NameStr, ReorderBuffer::outbuf, ReorderBuffer::outbufsize, pairingheap_allocate(), ReorderBufferCleanupSerializedTXNs(), ReorderBufferTXNSizeCompare(), ReorderBuffer::size, SLAB_DEFAULT_BLOCK_SIZE, SLAB_LARGE_BLOCK_SIZE, SlabContextCreate(), ReorderBuffer::spillBytes, ReorderBuffer::spillCount, ReorderBuffer::spillTxns, ReorderBuffer::streamBytes, ReorderBuffer::streamCount, ReorderBuffer::streamTxns, ReorderBuffer::toplevel_by_lsn, ReorderBuffer::totalBytes, ReorderBuffer::totalTxns, ReorderBuffer::tup_context, ReorderBuffer::txn_context, ReorderBuffer::txn_heap, and ReorderBuffer::txns_by_base_snapshot_lsn.

Referenced by StartupDecodingContext().

◆ ReorderBufferAssignChild()

void ReorderBufferAssignChild ( ReorderBuffer rb,
TransactionId  xid,
TransactionId  subxid,
XLogRecPtr  lsn 
)

Definition at line 1069 of file reorderbuffer.c.

1071 {
1072  ReorderBufferTXN *txn;
1073  ReorderBufferTXN *subtxn;
1074  bool new_top;
1075  bool new_sub;
1076 
1077  txn = ReorderBufferTXNByXid(rb, xid, true, &new_top, lsn, true);
1078  subtxn = ReorderBufferTXNByXid(rb, subxid, true, &new_sub, lsn, false);
1079 
1080  if (!new_sub)
1081  {
1082  if (rbtxn_is_known_subxact(subtxn))
1083  {
1084  /* already associated, nothing to do */
1085  return;
1086  }
1087  else
1088  {
1089  /*
1090  * We already saw this transaction, but initially added it to the
1091  * list of top-level txns. Now that we know it's not top-level,
1092  * remove it from there.
1093  */
1094  dlist_delete(&subtxn->node);
1095  }
1096  }
1097 
1098  subtxn->txn_flags |= RBTXN_IS_SUBXACT;
1099  subtxn->toplevel_xid = xid;
1100  Assert(subtxn->nsubtxns == 0);
1101 
1102  /* set the reference to top-level transaction */
1103  subtxn->toptxn = txn;
1104 
1105  /* add to subtransaction list */
1106  dlist_push_tail(&txn->subtxns, &subtxn->node);
1107  txn->nsubtxns++;
1108 
1109  /* Possibly transfer the subtxn's snapshot to its top-level txn. */
1110  ReorderBufferTransferSnapToParent(txn, subtxn);
1111 
1112  /* Verify LSN-ordering invariant */
1113  AssertTXNLsnOrder(rb);
1114 }
static void dlist_delete(dlist_node *node)
Definition: ilist.h:405
static void AssertTXNLsnOrder(ReorderBuffer *rb)
static void ReorderBufferTransferSnapToParent(ReorderBufferTXN *txn, ReorderBufferTXN *subtxn)
#define rbtxn_is_known_subxact(txn)
TransactionId toplevel_xid
struct ReorderBufferTXN * toptxn
dlist_head subtxns

References Assert, AssertTXNLsnOrder(), dlist_delete(), dlist_push_tail(), ReorderBufferTXN::node, ReorderBufferTXN::nsubtxns, rbtxn_is_known_subxact, RBTXN_IS_SUBXACT, ReorderBufferTransferSnapToParent(), ReorderBufferTXNByXid(), ReorderBufferTXN::subtxns, ReorderBufferTXN::toplevel_xid, ReorderBufferTXN::toptxn, and ReorderBufferTXN::txn_flags.

Referenced by LogicalDecodingProcessRecord(), and ReorderBufferCommitChild().

◆ ReorderBufferCommit()

void ReorderBufferCommit ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  commit_lsn,
XLogRecPtr  end_lsn,
TimestampTz  commit_time,
RepOriginId  origin_id,
XLogRecPtr  origin_lsn 
)

Definition at line 2711 of file reorderbuffer.c.

2715 {
2716  ReorderBufferTXN *txn;
2717 
2718  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2719  false);
2720 
2721  /* unknown transaction, nothing to replay */
2722  if (txn == NULL)
2723  return;
2724 
2725  ReorderBufferReplay(txn, rb, xid, commit_lsn, end_lsn, commit_time,
2726  origin_id, origin_lsn);
2727 }
static void ReorderBufferReplay(ReorderBufferTXN *txn, ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn)

References InvalidXLogRecPtr, ReorderBufferReplay(), and ReorderBufferTXNByXid().

Referenced by DecodeCommit().

◆ ReorderBufferCommitChild()

void ReorderBufferCommitChild ( ReorderBuffer rb,
TransactionId  xid,
TransactionId  subxid,
XLogRecPtr  commit_lsn,
XLogRecPtr  end_lsn 
)

Definition at line 1189 of file reorderbuffer.c.

1192 {
1193  ReorderBufferTXN *subtxn;
1194 
1195  subtxn = ReorderBufferTXNByXid(rb, subxid, false, NULL,
1196  InvalidXLogRecPtr, false);
1197 
1198  /*
1199  * No need to do anything if that subtxn didn't contain any changes
1200  */
1201  if (!subtxn)
1202  return;
1203 
1204  subtxn->final_lsn = commit_lsn;
1205  subtxn->end_lsn = end_lsn;
1206 
1207  /*
1208  * Assign this subxact as a child of the toplevel xact (no-op if already
1209  * done.)
1210  */
1211  ReorderBufferAssignChild(rb, xid, subxid, InvalidXLogRecPtr);
1212 }
void ReorderBufferAssignChild(ReorderBuffer *rb, TransactionId xid, TransactionId subxid, XLogRecPtr lsn)
XLogRecPtr end_lsn

References ReorderBufferTXN::end_lsn, ReorderBufferTXN::final_lsn, InvalidXLogRecPtr, ReorderBufferAssignChild(), and ReorderBufferTXNByXid().

Referenced by DecodeCommit(), and DecodePrepare().

◆ ReorderBufferFinishPrepared()

void ReorderBufferFinishPrepared ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  commit_lsn,
XLogRecPtr  end_lsn,
XLogRecPtr  two_phase_at,
TimestampTz  commit_time,
RepOriginId  origin_id,
XLogRecPtr  origin_lsn,
char *  gid,
bool  is_commit 
)

Definition at line 2817 of file reorderbuffer.c.

2822 {
2823  ReorderBufferTXN *txn;
2824  XLogRecPtr prepare_end_lsn;
2825  TimestampTz prepare_time;
2826 
2827  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, commit_lsn, false);
2828 
2829  /* unknown transaction, nothing to do */
2830  if (txn == NULL)
2831  return;
2832 
2833  /*
2834  * By this time the txn has the prepare record information, remember it to
2835  * be later used for rollback.
2836  */
2837  prepare_end_lsn = txn->end_lsn;
2838  prepare_time = txn->xact_time.prepare_time;
2839 
2840  /* add the gid in the txn */
2841  txn->gid = pstrdup(gid);
2842 
2843  /*
2844  * It is possible that this transaction is not decoded at prepare time
2845  * either because by that time we didn't have a consistent snapshot, or
2846  * two_phase was not enabled, or it was decoded earlier but we have
2847  * restarted. We only need to send the prepare if it was not decoded
2848  * earlier. We don't need to decode the xact for aborts if it is not done
2849  * already.
2850  */
2851  if ((txn->final_lsn < two_phase_at) && is_commit)
2852  {
2853  txn->txn_flags |= RBTXN_PREPARE;
2854 
2855  /*
2856  * The prepare info must have been updated in txn even if we skip
2857  * prepare.
2858  */
2860 
2861  /*
2862  * By this time the txn has the prepare record information and it is
2863  * important to use that so that downstream gets the accurate
2864  * information. If instead, we have passed commit information here
2865  * then downstream can behave as it has already replayed commit
2866  * prepared after the restart.
2867  */
2868  ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
2869  txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn);
2870  }
2871 
2872  txn->final_lsn = commit_lsn;
2873  txn->end_lsn = end_lsn;
2874  txn->xact_time.commit_time = commit_time;
2875  txn->origin_id = origin_id;
2876  txn->origin_lsn = origin_lsn;
2877 
2878  if (is_commit)
2879  rb->commit_prepared(rb, txn, commit_lsn);
2880  else
2881  rb->rollback_prepared(rb, txn, prepare_end_lsn, prepare_time);
2882 
2883  /* cleanup: make sure there's no cache pollution */
2885  txn->invalidations);
2886  ReorderBufferCleanupTXN(rb, txn);
2887 }
int64 TimestampTz
Definition: timestamp.h:39
char * pstrdup(const char *in)
Definition: mcxt.c:1695
static void ReorderBufferExecuteInvalidations(uint32 nmsgs, SharedInvalidationMessage *msgs)
TimestampTz commit_time
RepOriginId origin_id
XLogRecPtr origin_lsn
TimestampTz prepare_time
ReorderBufferCommitPreparedCB commit_prepared
ReorderBufferRollbackPreparedCB rollback_prepared
uint64 XLogRecPtr
Definition: xlogdefs.h:21

References Assert, ReorderBuffer::commit_prepared, ReorderBufferTXN::commit_time, ReorderBufferTXN::end_lsn, ReorderBufferTXN::final_lsn, ReorderBufferTXN::gid, ReorderBufferTXN::invalidations, InvalidXLogRecPtr, ReorderBufferTXN::ninvalidations, ReorderBufferTXN::origin_id, ReorderBufferTXN::origin_lsn, ReorderBufferTXN::prepare_time, pstrdup(), RBTXN_PREPARE, ReorderBufferCleanupTXN(), ReorderBufferExecuteInvalidations(), ReorderBufferReplay(), ReorderBufferTXNByXid(), ReorderBuffer::rollback_prepared, ReorderBufferTXN::txn_flags, and ReorderBufferTXN::xact_time.

Referenced by DecodeAbort(), and DecodeCommit().

◆ ReorderBufferForget()

void ReorderBufferForget ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn 
)

Definition at line 2994 of file reorderbuffer.c.

2995 {
2996  ReorderBufferTXN *txn;
2997 
2998  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2999  false);
3000 
3001  /* unknown, nothing to forget */
3002  if (txn == NULL)
3003  return;
3004 
3005  /* this transaction mustn't be streamed */
3006  Assert(!rbtxn_is_streamed(txn));
3007 
3008  /* cosmetic... */
3009  txn->final_lsn = lsn;
3010 
3011  /*
3012  * Process cache invalidation messages if there are any. Even if we're not
3013  * interested in the transaction's contents, it could have manipulated the
3014  * catalog and we need to update the caches according to that.
3015  */
3016  if (txn->base_snapshot != NULL && txn->ninvalidations > 0)
3018  txn->invalidations);
3019  else
3020  Assert(txn->ninvalidations == 0);
3021 
3022  /* remove potential on-disk data, and deallocate */
3023  ReorderBufferCleanupTXN(rb, txn);
3024 }
Snapshot base_snapshot

References Assert, ReorderBufferTXN::base_snapshot, ReorderBufferTXN::final_lsn, ReorderBufferTXN::invalidations, InvalidXLogRecPtr, ReorderBufferTXN::ninvalidations, rbtxn_is_streamed, ReorderBufferCleanupTXN(), ReorderBufferImmediateInvalidation(), and ReorderBufferTXNByXid().

Referenced by DecodeCommit().

◆ ReorderBufferFree()

void ReorderBufferFree ( ReorderBuffer rb)

Definition at line 396 of file reorderbuffer.c.

397 {
399 
400  /*
401  * We free separately allocated data by entirely scrapping reorderbuffer's
402  * memory context.
403  */
405 
406  /* Free disk space used by unconsumed reorder buffers */
408 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
tree context
Definition: radixtree.h:1833

References context, ReorderBuffer::context, ReplicationSlot::data, MemoryContextDelete(), MyReplicationSlot, ReplicationSlotPersistentData::name, NameStr, and ReorderBufferCleanupSerializedTXNs().

Referenced by FreeDecodingContext().

◆ ReorderBufferGetCatalogChangesXacts()

TransactionId* ReorderBufferGetCatalogChangesXacts ( ReorderBuffer rb)

Definition at line 3409 of file reorderbuffer.c.

3410 {
3411  dlist_iter iter;
3412  TransactionId *xids = NULL;
3413  size_t xcnt = 0;
3414 
3415  /* Quick return if the list is empty */
3416  if (dclist_count(&rb->catchange_txns) == 0)
3417  return NULL;
3418 
3419  /* Initialize XID array */
3420  xids = (TransactionId *) palloc(sizeof(TransactionId) *
3422  dclist_foreach(iter, &rb->catchange_txns)
3423  {
3425  catchange_node,
3426  iter.cur);
3427 
3429 
3430  xids[xcnt++] = txn->xid;
3431  }
3432 
3433  qsort(xids, xcnt, sizeof(TransactionId), xidComparator);
3434 
3435  Assert(xcnt == dclist_count(&rb->catchange_txns));
3436  return xids;
3437 }
#define dclist_container(type, membername, ptr)
Definition: ilist.h:947
static uint32 dclist_count(const dclist_head *head)
Definition: ilist.h:932
#define dclist_foreach(iter, lhead)
Definition: ilist.h:970
#define qsort(a, b, c, d)
Definition: port.h:449
#define rbtxn_has_catalog_changes(txn)
dlist_node * cur
Definition: ilist.h:179
int xidComparator(const void *arg1, const void *arg2)
Definition: xid.c:139

References Assert, ReorderBuffer::catchange_txns, dlist_iter::cur, dclist_container, dclist_count(), dclist_foreach, palloc(), qsort, rbtxn_has_catalog_changes, ReorderBufferTXN::xid, and xidComparator().

Referenced by SnapBuildSerialize().

◆ ReorderBufferGetChange()

◆ ReorderBufferGetOldestTXN()

ReorderBufferTXN* ReorderBufferGetOldestTXN ( ReorderBuffer rb)

Definition at line 1014 of file reorderbuffer.c.

1015 {
1016  ReorderBufferTXN *txn;
1017 
1018  AssertTXNLsnOrder(rb);
1019 
1020  if (dlist_is_empty(&rb->toplevel_by_lsn))
1021  return NULL;
1022 
1024 
1027  return txn;
1028 }
#define dlist_head_element(type, membername, lhead)
Definition: ilist.h:603
static bool dlist_is_empty(const dlist_head *head)
Definition: ilist.h:336
XLogRecPtr first_lsn

References Assert, AssertTXNLsnOrder(), dlist_head_element, dlist_is_empty(), ReorderBufferTXN::first_lsn, InvalidXLogRecPtr, rbtxn_is_known_subxact, and ReorderBuffer::toplevel_by_lsn.

Referenced by SnapBuildProcessRunningXacts().

◆ ReorderBufferGetOldestXmin()

TransactionId ReorderBufferGetOldestXmin ( ReorderBuffer rb)

Definition at line 1042 of file reorderbuffer.c.

1043 {
1044  ReorderBufferTXN *txn;
1045 
1046  AssertTXNLsnOrder(rb);
1047 
1049  return InvalidTransactionId;
1050 
1051  txn = dlist_head_element(ReorderBufferTXN, base_snapshot_node,
1053  return txn->base_snapshot->xmin;
1054 }
TransactionId xmin
Definition: snapshot.h:157

References AssertTXNLsnOrder(), ReorderBufferTXN::base_snapshot, dlist_head_element, dlist_is_empty(), InvalidTransactionId, ReorderBuffer::txns_by_base_snapshot_lsn, and SnapshotData::xmin.

Referenced by SnapBuildProcessRunningXacts().

◆ ReorderBufferGetRelids()

Oid* ReorderBufferGetRelids ( ReorderBuffer rb,
int  nrelids 
)

Definition at line 595 of file reorderbuffer.c.

596 {
597  Oid *relids;
598  Size alloc_len;
599 
600  alloc_len = sizeof(Oid) * nrelids;
601 
602  relids = (Oid *) MemoryContextAlloc(rb->context, alloc_len);
603 
604  return relids;
605 }
size_t Size
Definition: c.h:605
unsigned int Oid
Definition: postgres_ext.h:31

References ReorderBuffer::context, and MemoryContextAlloc().

Referenced by DecodeTruncate(), and ReorderBufferRestoreChange().

◆ ReorderBufferGetTupleBuf()

HeapTuple ReorderBufferGetTupleBuf ( ReorderBuffer rb,
Size  tuple_len 
)

Definition at line 562 of file reorderbuffer.c.

563 {
564  HeapTuple tuple;
565  Size alloc_len;
566 
567  alloc_len = tuple_len + SizeofHeapTupleHeader;
568 
570  HEAPTUPLESIZE + alloc_len);
571  tuple->t_data = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);
572 
573  return tuple;
574 }
#define HEAPTUPLESIZE
Definition: htup.h:73
HeapTupleData * HeapTuple
Definition: htup.h:71
HeapTupleHeaderData * HeapTupleHeader
Definition: htup.h:23
#define SizeofHeapTupleHeader
Definition: htup_details.h:185
HeapTupleHeader t_data
Definition: htup.h:68

References HEAPTUPLESIZE, MemoryContextAlloc(), SizeofHeapTupleHeader, HeapTupleData::t_data, and ReorderBuffer::tup_context.

Referenced by DecodeDelete(), DecodeInsert(), DecodeMultiInsert(), DecodeUpdate(), and ReorderBufferRestoreChange().

◆ ReorderBufferImmediateInvalidation()

void ReorderBufferImmediateInvalidation ( ReorderBuffer rb,
uint32  ninvalidations,
SharedInvalidationMessage invalidations 
)

Definition at line 3066 of file reorderbuffer.c.

3068 {
3069  bool use_subtxn = IsTransactionOrTransactionBlock();
3070  int i;
3071 
3072  if (use_subtxn)
3073  BeginInternalSubTransaction("replay");
3074 
3075  /*
3076  * Force invalidations to happen outside of a valid transaction - that way
3077  * entries will just be marked as invalid without accessing the catalog.
3078  * That's advantageous because we don't need to setup the full state
3079  * necessary for catalog access.
3080  */
3081  if (use_subtxn)
3083 
3084  for (i = 0; i < ninvalidations; i++)
3085  LocalExecuteInvalidationMessage(&invalidations[i]);
3086 
3087  if (use_subtxn)
3089 }
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
Definition: inval.c:705
int i
Definition: isn.c:73
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4933
void BeginInternalSubTransaction(const char *name)
Definition: xact.c:4643
void RollbackAndReleaseCurrentSubTransaction(void)
Definition: xact.c:4745
void AbortCurrentTransaction(void)
Definition: xact.c:3387

References AbortCurrentTransaction(), BeginInternalSubTransaction(), i, IsTransactionOrTransactionBlock(), LocalExecuteInvalidationMessage(), and RollbackAndReleaseCurrentSubTransaction().

Referenced by ReorderBufferAbort(), ReorderBufferForget(), ReorderBufferInvalidate(), and xact_decode().

◆ ReorderBufferInvalidate()

void ReorderBufferInvalidate ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn 
)

Definition at line 3035 of file reorderbuffer.c.

3036 {
3037  ReorderBufferTXN *txn;
3038 
3039  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
3040  false);
3041 
3042  /* unknown, nothing to do */
3043  if (txn == NULL)
3044  return;
3045 
3046  /*
3047  * Process cache invalidation messages if there are any. Even if we're not
3048  * interested in the transaction's contents, it could have manipulated the
3049  * catalog and we need to update the caches according to that.
3050  */
3051  if (txn->base_snapshot != NULL && txn->ninvalidations > 0)
3053  txn->invalidations);
3054  else
3055  Assert(txn->ninvalidations == 0);
3056 }

References Assert, ReorderBufferTXN::base_snapshot, ReorderBufferTXN::invalidations, InvalidXLogRecPtr, ReorderBufferTXN::ninvalidations, ReorderBufferImmediateInvalidation(), and ReorderBufferTXNByXid().

Referenced by DecodePrepare().

◆ ReorderBufferPrepare()

void ReorderBufferPrepare ( ReorderBuffer rb,
TransactionId  xid,
char *  gid 
)

Definition at line 2780 of file reorderbuffer.c.

2782 {
2783  ReorderBufferTXN *txn;
2784 
2785  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2786  false);
2787 
2788  /* unknown transaction, nothing to replay */
2789  if (txn == NULL)
2790  return;
2791 
2792  txn->txn_flags |= RBTXN_PREPARE;
2793  txn->gid = pstrdup(gid);
2794 
2795  /* The prepare info must have been updated in txn by now. */
2797 
2798  ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
2799  txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn);
2800 
2801  /*
2802  * We send the prepare for the concurrently aborted xacts so that later
2803  * when rollback prepared is decoded and sent, the downstream should be
2804  * able to rollback such a xact. See comments atop DecodePrepare.
2805  *
2806  * Note, for the concurrent_abort + streaming case a stream_prepare was
2807  * already sent within the ReorderBufferReplay call above.
2808  */
2809  if (txn->concurrent_abort && !rbtxn_is_streamed(txn))
2810  rb->prepare(rb, txn, txn->final_lsn);
2811 }
ReorderBufferPrepareCB prepare

References Assert, ReorderBufferTXN::concurrent_abort, ReorderBufferTXN::end_lsn, ReorderBufferTXN::final_lsn, ReorderBufferTXN::gid, InvalidXLogRecPtr, ReorderBufferTXN::origin_id, ReorderBufferTXN::origin_lsn, ReorderBuffer::prepare, ReorderBufferTXN::prepare_time, pstrdup(), rbtxn_is_streamed, RBTXN_PREPARE, ReorderBufferReplay(), ReorderBufferTXNByXid(), ReorderBufferTXN::txn_flags, and ReorderBufferTXN::xact_time.

Referenced by DecodePrepare().

◆ ReorderBufferProcessXid()

void ReorderBufferProcessXid ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn 
)

Definition at line 3102 of file reorderbuffer.c.

3103 {
3104  /* many records won't have an xid assigned, centralize check here */
3105  if (xid != InvalidTransactionId)
3106  ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3107 }

References InvalidTransactionId, and ReorderBufferTXNByXid().

Referenced by heap2_decode(), heap_decode(), LogicalDecodingProcessRecord(), logicalmsg_decode(), standby_decode(), xact_decode(), and xlog_decode().

◆ ReorderBufferQueueChange()

void ReorderBufferQueueChange ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn,
ReorderBufferChange change,
bool  toast_insert 
)

Definition at line 780 of file reorderbuffer.c.

782 {
783  ReorderBufferTXN *txn;
784 
785  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
786 
787  /*
788  * While streaming the previous changes we have detected that the
789  * transaction is aborted. So there is no point in collecting further
790  * changes for it.
791  */
792  if (txn->concurrent_abort)
793  {
794  /*
795  * We don't need to update memory accounting for this change as we
796  * have not added it to the queue yet.
797  */
798  ReorderBufferReturnChange(rb, change, false);
799  return;
800  }
801 
802  /*
803  * The changes that are sent downstream are considered streamable. We
804  * remember such transactions so that only those will later be considered
805  * for streaming.
806  */
807  if (change->action == REORDER_BUFFER_CHANGE_INSERT ||
813  {
814  ReorderBufferTXN *toptxn = rbtxn_get_toptxn(txn);
815 
817  }
818 
819  change->lsn = lsn;
820  change->txn = txn;
821 
822  Assert(InvalidXLogRecPtr != lsn);
823  dlist_push_tail(&txn->changes, &change->node);
824  txn->nentries++;
825  txn->nentries_mem++;
826 
827  /* update memory accounting information */
828  ReorderBufferChangeMemoryUpdate(rb, change, NULL, true,
829  ReorderBufferChangeSize(change));
830 
831  /* process partial change */
832  ReorderBufferProcessPartialChange(rb, txn, change, toast_insert);
833 
834  /* check the memory limits and evict something if needed */
836 }
void ReorderBufferReturnChange(ReorderBuffer *rb, ReorderBufferChange *change, bool upd_mem)
static Size ReorderBufferChangeSize(ReorderBufferChange *change)
static void ReorderBufferProcessPartialChange(ReorderBuffer *rb, ReorderBufferTXN *txn, ReorderBufferChange *change, bool toast_insert)
static void ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb, ReorderBufferChange *change, ReorderBufferTXN *txn, bool addition, Size sz)
dlist_head changes

References ReorderBufferChange::action, Assert, ReorderBufferTXN::changes, ReorderBufferTXN::concurrent_abort, dlist_push_tail(), InvalidXLogRecPtr, ReorderBufferChange::lsn, ReorderBufferTXN::nentries, ReorderBufferTXN::nentries_mem, ReorderBufferChange::node, rbtxn_get_toptxn, RBTXN_HAS_STREAMABLE_CHANGE, REORDER_BUFFER_CHANGE_DELETE, REORDER_BUFFER_CHANGE_INSERT, REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT, REORDER_BUFFER_CHANGE_MESSAGE, REORDER_BUFFER_CHANGE_TRUNCATE, REORDER_BUFFER_CHANGE_UPDATE, ReorderBufferChangeMemoryUpdate(), ReorderBufferChangeSize(), ReorderBufferCheckMemoryLimit(), ReorderBufferProcessPartialChange(), ReorderBufferReturnChange(), ReorderBufferTXNByXid(), ReorderBufferChange::txn, and ReorderBufferTXN::txn_flags.

Referenced by DecodeDelete(), DecodeInsert(), DecodeMultiInsert(), DecodeSpecConfirm(), DecodeTruncate(), DecodeUpdate(), ReorderBufferAddInvalidations(), ReorderBufferAddNewCommandId(), ReorderBufferAddSnapshot(), and ReorderBufferQueueMessage().

◆ ReorderBufferQueueMessage()

void ReorderBufferQueueMessage ( ReorderBuffer rb,
TransactionId  xid,
Snapshot  snap,
XLogRecPtr  lsn,
bool  transactional,
const char *  prefix,
Size  message_size,
const char *  message 
)

Definition at line 843 of file reorderbuffer.c.

847 {
848  if (transactional)
849  {
850  MemoryContext oldcontext;
851  ReorderBufferChange *change;
852 
854 
855  /*
856  * We don't expect snapshots for transactional changes - we'll use the
857  * snapshot derived later during apply (unless the change gets
858  * skipped).
859  */
860  Assert(!snap);
861 
862  oldcontext = MemoryContextSwitchTo(rb->context);
863 
864  change = ReorderBufferGetChange(rb);
866  change->data.msg.prefix = pstrdup(prefix);
867  change->data.msg.message_size = message_size;
868  change->data.msg.message = palloc(message_size);
869  memcpy(change->data.msg.message, message, message_size);
870 
871  ReorderBufferQueueChange(rb, xid, lsn, change, false);
872 
873  MemoryContextSwitchTo(oldcontext);
874  }
875  else
876  {
877  ReorderBufferTXN *txn = NULL;
878  volatile Snapshot snapshot_now = snap;
879 
880  /* Non-transactional changes require a valid snapshot. */
881  Assert(snapshot_now);
882 
883  if (xid != InvalidTransactionId)
884  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
885 
886  /* setup snapshot to allow catalog access */
887  SetupHistoricSnapshot(snapshot_now, NULL);
888  PG_TRY();
889  {
890  rb->message(rb, txn, lsn, false, prefix, message_size, message);
891 
893  }
894  PG_CATCH();
895  {
897  PG_RE_THROW();
898  }
899  PG_END_TRY();
900  }
901 }
#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 TeardownHistoricSnapshot(bool is_error)
Definition: snapmgr.c:1665
void SetupHistoricSnapshot(Snapshot historic_snapshot, HTAB *tuplecids)
Definition: snapmgr.c:1649
struct ReorderBufferChange::@105::@108 msg
ReorderBufferMessageCB message

References ReorderBufferChange::action, Assert, ReorderBuffer::context, ReorderBufferChange::data, InvalidTransactionId, MemoryContextSwitchTo(), ReorderBuffer::message, ReorderBufferChange::msg, palloc(), PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pstrdup(), REORDER_BUFFER_CHANGE_MESSAGE, ReorderBufferGetChange(), ReorderBufferQueueChange(), ReorderBufferTXNByXid(), SetupHistoricSnapshot(), and TeardownHistoricSnapshot().

Referenced by logicalmsg_decode().

◆ ReorderBufferRememberPrepareInfo()

bool ReorderBufferRememberPrepareInfo ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  prepare_lsn,
XLogRecPtr  end_lsn,
TimestampTz  prepare_time,
RepOriginId  origin_id,
XLogRecPtr  origin_lsn 
)

Definition at line 2733 of file reorderbuffer.c.

2737 {
2738  ReorderBufferTXN *txn;
2739 
2740  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr, false);
2741 
2742  /* unknown transaction, nothing to do */
2743  if (txn == NULL)
2744  return false;
2745 
2746  /*
2747  * Remember the prepare information to be later used by commit prepared in
2748  * case we skip doing prepare.
2749  */
2750  txn->final_lsn = prepare_lsn;
2751  txn->end_lsn = end_lsn;
2752  txn->xact_time.prepare_time = prepare_time;
2753  txn->origin_id = origin_id;
2754  txn->origin_lsn = origin_lsn;
2755 
2756  return true;
2757 }

References ReorderBufferTXN::end_lsn, ReorderBufferTXN::final_lsn, InvalidXLogRecPtr, ReorderBufferTXN::origin_id, ReorderBufferTXN::origin_lsn, ReorderBufferTXN::prepare_time, ReorderBufferTXNByXid(), and ReorderBufferTXN::xact_time.

Referenced by DecodePrepare().

◆ ReorderBufferReturnChange()

void ReorderBufferReturnChange ( ReorderBuffer rb,
ReorderBufferChange change,
bool  upd_mem 
)

Definition at line 492 of file reorderbuffer.c.

494 {
495  /* update memory accounting info */
496  if (upd_mem)
497  ReorderBufferChangeMemoryUpdate(rb, change, NULL, false,
498  ReorderBufferChangeSize(change));
499 
500  /* free contained data */
501  switch (change->action)
502  {
507  if (change->data.tp.newtuple)
508  {
509  ReorderBufferReturnTupleBuf(change->data.tp.newtuple);
510  change->data.tp.newtuple = NULL;
511  }
512 
513  if (change->data.tp.oldtuple)
514  {
515  ReorderBufferReturnTupleBuf(change->data.tp.oldtuple);
516  change->data.tp.oldtuple = NULL;
517  }
518  break;
520  if (change->data.msg.prefix != NULL)
521  pfree(change->data.msg.prefix);
522  change->data.msg.prefix = NULL;
523  if (change->data.msg.message != NULL)
524  pfree(change->data.msg.message);
525  change->data.msg.message = NULL;
526  break;
528  if (change->data.inval.invalidations)
529  pfree(change->data.inval.invalidations);
530  change->data.inval.invalidations = NULL;
531  break;
533  if (change->data.snapshot)
534  {
535  ReorderBufferFreeSnap(rb, change->data.snapshot);
536  change->data.snapshot = NULL;
537  }
538  break;
539  /* no data in addition to the struct itself */
541  if (change->data.truncate.relids != NULL)
542  {
543  ReorderBufferReturnRelids(rb, change->data.truncate.relids);
544  change->data.truncate.relids = NULL;
545  }
546  break;
551  break;
552  }
553 
554  pfree(change);
555 }
void pfree(void *pointer)
Definition: mcxt.c:1520
void ReorderBufferReturnTupleBuf(HeapTuple tuple)
static void ReorderBufferFreeSnap(ReorderBuffer *rb, Snapshot snap)
void ReorderBufferReturnRelids(ReorderBuffer *rb, Oid *relids)
struct ReorderBufferChange::@105::@107 truncate
struct ReorderBufferChange::@105::@106 tp

References ReorderBufferChange::action, ReorderBufferChange::data, ReorderBufferChange::inval, ReorderBufferChange::msg, pfree(), REORDER_BUFFER_CHANGE_DELETE, REORDER_BUFFER_CHANGE_INSERT, REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID, REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT, REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT, REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM, REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT, REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID, REORDER_BUFFER_CHANGE_INVALIDATION, REORDER_BUFFER_CHANGE_MESSAGE, REORDER_BUFFER_CHANGE_TRUNCATE, REORDER_BUFFER_CHANGE_UPDATE, ReorderBufferChangeMemoryUpdate(), ReorderBufferChangeSize(), ReorderBufferFreeSnap(), ReorderBufferReturnRelids(), ReorderBufferReturnTupleBuf(), ReorderBufferChange::snapshot, ReorderBufferChange::tp, and ReorderBufferChange::truncate.

Referenced by ReorderBufferCleanupTXN(), ReorderBufferIterTXNFinish(), ReorderBufferIterTXNNext(), ReorderBufferProcessTXN(), ReorderBufferQueueChange(), ReorderBufferResetTXN(), ReorderBufferRestoreChanges(), ReorderBufferSerializeTXN(), ReorderBufferToastReset(), and ReorderBufferTruncateTXN().

◆ ReorderBufferReturnRelids()

void ReorderBufferReturnRelids ( ReorderBuffer rb,
Oid relids 
)

Definition at line 611 of file reorderbuffer.c.

612 {
613  pfree(relids);
614 }

References pfree().

Referenced by ReorderBufferReturnChange().

◆ ReorderBufferReturnTupleBuf()

void ReorderBufferReturnTupleBuf ( HeapTuple  tuple)

Definition at line 580 of file reorderbuffer.c.

581 {
582  pfree(tuple);
583 }

References pfree().

Referenced by ReorderBufferReturnChange().

◆ ReorderBufferSetBaseSnapshot()

void ReorderBufferSetBaseSnapshot ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn,
Snapshot  snap 
)

Definition at line 3133 of file reorderbuffer.c.

3135 {
3136  ReorderBufferTXN *txn;
3137  bool is_new;
3138 
3139  Assert(snap != NULL);
3140 
3141  /*
3142  * Fetch the transaction to operate on. If we know it's a subtransaction,
3143  * operate on its top-level transaction instead.
3144  */
3145  txn = ReorderBufferTXNByXid(rb, xid, true, &is_new, lsn, true);
3146  if (rbtxn_is_known_subxact(txn))
3147  txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
3148  NULL, InvalidXLogRecPtr, false);
3149  Assert(txn->base_snapshot == NULL);
3150 
3151  txn->base_snapshot = snap;
3152  txn->base_snapshot_lsn = lsn;
3154 
3155  AssertTXNLsnOrder(rb);
3156 }
XLogRecPtr base_snapshot_lsn
dlist_node base_snapshot_node

References Assert, AssertTXNLsnOrder(), ReorderBufferTXN::base_snapshot, ReorderBufferTXN::base_snapshot_lsn, ReorderBufferTXN::base_snapshot_node, dlist_push_tail(), InvalidXLogRecPtr, rbtxn_is_known_subxact, ReorderBufferTXNByXid(), ReorderBufferTXN::toplevel_xid, and ReorderBuffer::txns_by_base_snapshot_lsn.

Referenced by SnapBuildCommitTxn(), and SnapBuildProcessChange().

◆ ReorderBufferSetRestartPoint()

void ReorderBufferSetRestartPoint ( ReorderBuffer rb,
XLogRecPtr  ptr 
)

Definition at line 1057 of file reorderbuffer.c.

1058 {
1059  rb->current_restart_decoding_lsn = ptr;
1060 }

References ReorderBuffer::current_restart_decoding_lsn.

Referenced by SnapBuildRestore(), and SnapBuildSerialize().

◆ ReorderBufferSkipPrepare()

void ReorderBufferSkipPrepare ( ReorderBuffer rb,
TransactionId  xid 
)

Definition at line 2761 of file reorderbuffer.c.

2762 {
2763  ReorderBufferTXN *txn;
2764 
2765  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr, false);
2766 
2767  /* unknown transaction, nothing to do */
2768  if (txn == NULL)
2769  return;
2770 
2772 }

References InvalidXLogRecPtr, RBTXN_SKIPPED_PREPARE, ReorderBufferTXNByXid(), and ReorderBufferTXN::txn_flags.

Referenced by DecodePrepare().

◆ ReorderBufferXidHasBaseSnapshot()

bool ReorderBufferXidHasBaseSnapshot ( ReorderBuffer rb,
TransactionId  xid 
)

Definition at line 3461 of file reorderbuffer.c.

3462 {
3463  ReorderBufferTXN *txn;
3464 
3465  txn = ReorderBufferTXNByXid(rb, xid, false,
3466  NULL, InvalidXLogRecPtr, false);
3467 
3468  /* transaction isn't known yet, ergo no snapshot */
3469  if (txn == NULL)
3470  return false;
3471 
3472  /* a known subtxn? operate on top-level txn instead */
3473  if (rbtxn_is_known_subxact(txn))
3474  txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
3475  NULL, InvalidXLogRecPtr, false);
3476 
3477  return txn->base_snapshot != NULL;
3478 }

References ReorderBufferTXN::base_snapshot, InvalidXLogRecPtr, rbtxn_is_known_subxact, ReorderBufferTXNByXid(), and ReorderBufferTXN::toplevel_xid.

Referenced by SnapBuildCommitTxn(), SnapBuildDistributeNewCatalogSnapshot(), and SnapBuildProcessChange().

◆ ReorderBufferXidHasCatalogChanges()

bool ReorderBufferXidHasCatalogChanges ( ReorderBuffer rb,
TransactionId  xid 
)

Definition at line 3444 of file reorderbuffer.c.

3445 {
3446  ReorderBufferTXN *txn;
3447 
3448  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
3449  false);
3450  if (txn == NULL)
3451  return false;
3452 
3453  return rbtxn_has_catalog_changes(txn);
3454 }

References InvalidXLogRecPtr, rbtxn_has_catalog_changes, and ReorderBufferTXNByXid().

Referenced by SnapBuildXidHasCatalogChanges().

◆ ReorderBufferXidSetCatalogChanges()

void ReorderBufferXidSetCatalogChanges ( ReorderBuffer rb,
TransactionId  xid,
XLogRecPtr  lsn 
)

Definition at line 3371 of file reorderbuffer.c.

3373 {
3374  ReorderBufferTXN *txn;
3375 
3376  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3377 
3378  if (!rbtxn_has_catalog_changes(txn))
3379  {
3382  }
3383 
3384  /*
3385  * Mark top-level transaction as having catalog changes too if one of its
3386  * children has so that the ReorderBufferBuildTupleCidHash can
3387  * conveniently check just top-level transaction and decide whether to
3388  * build the hash table or not.
3389  */
3390  if (rbtxn_is_subtxn(txn))
3391  {
3392  ReorderBufferTXN *toptxn = rbtxn_get_toptxn(txn);
3393 
3394  if (!rbtxn_has_catalog_changes(toptxn))
3395  {
3398  }
3399  }
3400 }
static void dclist_push_tail(dclist_head *head, dlist_node *node)
Definition: ilist.h:709
#define rbtxn_is_subtxn(txn)
dlist_node catchange_node

References ReorderBufferTXN::catchange_node, ReorderBuffer::catchange_txns, dclist_push_tail(), rbtxn_get_toptxn, RBTXN_HAS_CATALOG_CHANGES, rbtxn_has_catalog_changes, rbtxn_is_subtxn, ReorderBufferTXNByXid(), and ReorderBufferTXN::txn_flags.

Referenced by heap_decode(), SnapBuildProcessNewCid(), and xact_decode().

◆ StartupReorderBuffer()

void StartupReorderBuffer ( void  )

Definition at line 4625 of file reorderbuffer.c.

4626 {
4627  DIR *logical_dir;
4628  struct dirent *logical_de;
4629 
4630  logical_dir = AllocateDir("pg_replslot");
4631  while ((logical_de = ReadDir(logical_dir, "pg_replslot")) != NULL)
4632  {
4633  if (strcmp(logical_de->d_name, ".") == 0 ||
4634  strcmp(logical_de->d_name, "..") == 0)
4635  continue;
4636 
4637  /* if it cannot be a slot, skip the directory */
4638  if (!ReplicationSlotValidateName(logical_de->d_name, DEBUG2))
4639  continue;
4640 
4641  /*
4642  * ok, has to be a surviving logical slot, iterate and delete
4643  * everything starting with xid-*
4644  */
4646  }
4647  FreeDir(logical_dir);
4648 }
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2909
int FreeDir(DIR *dir)
Definition: fd.c:2961
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2843
bool ReplicationSlotValidateName(const char *name, int elevel)
Definition: slot.c:252
Definition: dirent.c:26
Definition: dirent.h:10
char d_name[MAX_PATH]
Definition: dirent.h:15

References AllocateDir(), dirent::d_name, DEBUG2, FreeDir(), ReadDir(), ReorderBufferCleanupSerializedTXNs(), and ReplicationSlotValidateName().

Referenced by StartupXLOG().

Variable Documentation

◆ debug_logical_replication_streaming

PGDLLIMPORT int debug_logical_replication_streaming
extern

Definition at line 216 of file reorderbuffer.c.

Referenced by pa_send_data(), and ReorderBufferCheckMemoryLimit().

◆ logical_decoding_work_mem

PGDLLIMPORT int logical_decoding_work_mem
extern

Definition at line 212 of file reorderbuffer.c.

Referenced by ReorderBufferCheckMemoryLimit().