PostgreSQL Source Code  git master
reorderbuffer.h File Reference
#include "access/htup_details.h"
#include "lib/ilist.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 246 of file reorderbuffer.h.

◆ RBTXN_HAS_CATALOG_CHANGES

#define RBTXN_HAS_CATALOG_CHANGES   0x0001

Definition at line 161 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 172 of file reorderbuffer.h.

◆ RBTXN_HAS_PARTIAL_CHANGE

#define RBTXN_HAS_PARTIAL_CHANGE   0x0020

Definition at line 166 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 196 of file reorderbuffer.h.

◆ RBTXN_HAS_STREAMABLE_CHANGE

#define RBTXN_HAS_STREAMABLE_CHANGE   0x0100

Definition at line 169 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 202 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 178 of file reorderbuffer.h.

◆ RBTXN_IS_SERIALIZED

#define RBTXN_IS_SERIALIZED   0x0004

Definition at line 163 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 184 of file reorderbuffer.h.

◆ RBTXN_IS_SERIALIZED_CLEAR

#define RBTXN_IS_SERIALIZED_CLEAR   0x0008

Definition at line 164 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 190 of file reorderbuffer.h.

◆ RBTXN_IS_STREAMED

#define RBTXN_IS_STREAMED   0x0010

Definition at line 165 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 216 of file reorderbuffer.h.

◆ rbtxn_is_subtxn

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

Definition at line 240 of file reorderbuffer.h.

◆ RBTXN_IS_SUBXACT

#define RBTXN_IS_SUBXACT   0x0002

Definition at line 162 of file reorderbuffer.h.

◆ rbtxn_is_toptxn

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

Definition at line 234 of file reorderbuffer.h.

◆ RBTXN_PREPARE

#define RBTXN_PREPARE   0x0040

Definition at line 167 of file reorderbuffer.h.

◆ rbtxn_prepared

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

Definition at line 222 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 228 of file reorderbuffer.h.

◆ RBTXN_SKIPPED_PREPARE

#define RBTXN_SKIPPED_PREPARE   0x0080

Definition at line 168 of file reorderbuffer.h.

Typedef Documentation

◆ ReorderBuffer

typedef struct ReorderBuffer ReorderBuffer

Definition at line 22 of file reorderbuffer.h.

◆ ReorderBufferApplyChangeCB

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

Definition at line 425 of file reorderbuffer.h.

◆ ReorderBufferApplyTruncateCB

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

Definition at line 431 of file reorderbuffer.h.

◆ ReorderBufferBeginCB

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

Definition at line 438 of file reorderbuffer.h.

◆ ReorderBufferBeginPrepareCB

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

Definition at line 455 of file reorderbuffer.h.

◆ ReorderBufferChange

◆ ReorderBufferChangeType

◆ ReorderBufferCommitCB

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

Definition at line 442 of file reorderbuffer.h.

◆ ReorderBufferCommitPreparedCB

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

Definition at line 464 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 447 of file reorderbuffer.h.

◆ ReorderBufferPrepareCB

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

Definition at line 459 of file reorderbuffer.h.

◆ ReorderBufferRollbackPreparedCB

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

Definition at line 469 of file reorderbuffer.h.

◆ ReorderBufferStreamAbortCB

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

Definition at line 487 of file reorderbuffer.h.

◆ ReorderBufferStreamChangeCB

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

Definition at line 505 of file reorderbuffer.h.

◆ ReorderBufferStreamCommitCB

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

Definition at line 499 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 512 of file reorderbuffer.h.

◆ ReorderBufferStreamPrepareCB

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

Definition at line 493 of file reorderbuffer.h.

◆ ReorderBufferStreamStartCB

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

Definition at line 475 of file reorderbuffer.h.

◆ ReorderBufferStreamStopCB

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

Definition at line 481 of file reorderbuffer.h.

◆ ReorderBufferStreamTruncateCB

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

Definition at line 521 of file reorderbuffer.h.

◆ ReorderBufferTXN

◆ ReorderBufferUpdateProgressTxnCB

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

Definition at line 529 of file reorderbuffer.h.

Enumeration Type Documentation

◆ DebugLogicalRepStreamingMode

Enumerator
DEBUG_LOGICAL_REP_STREAMING_BUFFERED 
DEBUG_LOGICAL_REP_STREAMING_IMMEDIATE 

Definition at line 25 of file reorderbuffer.h.

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

◆ 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 44 of file reorderbuffer.h.

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

Function Documentation

◆ ReorderBufferAbort()

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

Definition at line 2887 of file reorderbuffer.c.

2889 {
2890  ReorderBufferTXN *txn;
2891 
2892  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2893  false);
2894 
2895  /* unknown, nothing to remove */
2896  if (txn == NULL)
2897  return;
2898 
2899  txn->xact_time.abort_time = abort_time;
2900 
2901  /* For streamed transactions notify the remote node about the abort. */
2902  if (rbtxn_is_streamed(txn))
2903  {
2904  rb->stream_abort(rb, txn, lsn);
2905 
2906  /*
2907  * We might have decoded changes for this transaction that could load
2908  * the cache as per the current transaction's view (consider DDL's
2909  * happened in this transaction). We don't want the decoding of future
2910  * transactions to use those cache entries so execute invalidations.
2911  */
2912  if (txn->ninvalidations > 0)
2914  txn->invalidations);
2915  }
2916 
2917  /* cosmetic... */
2918  txn->final_lsn = lsn;
2919 
2920  /* remove potential on-disk data, and deallocate */
2921  ReorderBufferCleanupTXN(rb, txn);
2922 }
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::@106 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 2932 of file reorderbuffer.c.

2933 {
2934  dlist_mutable_iter it;
2935 
2936  /*
2937  * Iterate through all (potential) toplevel TXNs and abort all that are
2938  * older than what possibly can be running. Once we've found the first
2939  * that is alive we stop, there might be some that acquired an xid earlier
2940  * but started writing later, but it's unlikely and they will be cleaned
2941  * up in a later call to this function.
2942  */
2944  {
2945  ReorderBufferTXN *txn;
2946 
2947  txn = dlist_container(ReorderBufferTXN, node, it.cur);
2948 
2949  if (TransactionIdPrecedes(txn->xid, oldestRunningXid))
2950  {
2951  elog(DEBUG2, "aborting old transaction %u", txn->xid);
2952 
2953  /* Notify the remote node about the crash/immediate restart. */
2954  if (rbtxn_is_streamed(txn))
2955  rb->stream_abort(rb, txn, InvalidXLogRecPtr);
2956 
2957  /* remove potential on-disk data, and deallocate this tx */
2958  ReorderBufferCleanupTXN(rb, txn);
2959  }
2960  else
2961  return;
2962  }
2963 }
#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 3265 of file reorderbuffer.c.

3268 {
3269  ReorderBufferTXN *txn;
3270  MemoryContext oldcontext;
3271  ReorderBufferChange *change;
3272 
3273  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3274 
3275  oldcontext = MemoryContextSwitchTo(rb->context);
3276 
3277  /*
3278  * Collect all the invalidations under the top transaction, if available,
3279  * so that we can execute them all together. See comments atop this
3280  * function.
3281  */
3282  txn = rbtxn_get_toptxn(txn);
3283 
3284  Assert(nmsgs > 0);
3285 
3286  /* Accumulate invalidations. */
3287  if (txn->ninvalidations == 0)
3288  {
3289  txn->ninvalidations = nmsgs;
3291  palloc(sizeof(SharedInvalidationMessage) * nmsgs);
3292  memcpy(txn->invalidations, msgs,
3293  sizeof(SharedInvalidationMessage) * nmsgs);
3294  }
3295  else
3296  {
3299  (txn->ninvalidations + nmsgs));
3300 
3301  memcpy(txn->invalidations + txn->ninvalidations, msgs,
3302  nmsgs * sizeof(SharedInvalidationMessage));
3303  txn->ninvalidations += nmsgs;
3304  }
3305 
3306  change = ReorderBufferGetChange(rb);
3308  change->data.inval.ninvalidations = nmsgs;
3309  change->data.inval.invalidations = (SharedInvalidationMessage *)
3310  palloc(sizeof(SharedInvalidationMessage) * nmsgs);
3311  memcpy(change->data.inval.invalidations, msgs,
3312  sizeof(SharedInvalidationMessage) * nmsgs);
3313 
3314  ReorderBufferQueueChange(rb, xid, lsn, change, false);
3315 
3316  MemoryContextSwitchTo(oldcontext);
3317 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1528
void * palloc(Size size)
Definition: mcxt.c:1304
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
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:75
union ReorderBufferChange::@100 data
struct ReorderBufferChange::@100::@105 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 3228 of file reorderbuffer.c.

3232 {
3234  ReorderBufferTXN *txn;
3235 
3236  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3237 
3238  change->data.tuplecid.locator = locator;
3239  change->data.tuplecid.tid = tid;
3240  change->data.tuplecid.cmin = cmin;
3241  change->data.tuplecid.cmax = cmax;
3242  change->data.tuplecid.combocid = combocid;
3243  change->lsn = lsn;
3244  change->txn = txn;
3246 
3247  dlist_push_tail(&txn->tuplecids, &change->node);
3248  txn->ntuplecids++;
3249 }
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:364
struct ReorderBufferTXN * txn
Definition: reorderbuffer.h:78
struct ReorderBufferChange::@100::@104 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 303 of file reorderbuffer.c.

304 {
305  ReorderBuffer *buffer;
306  HASHCTL hash_ctl;
307  MemoryContext new_ctx;
308 
309  Assert(MyReplicationSlot != NULL);
310 
311  /* allocate memory in own context, to have better accountability */
313  "ReorderBuffer",
315 
316  buffer =
317  (ReorderBuffer *) MemoryContextAlloc(new_ctx, sizeof(ReorderBuffer));
318 
319  memset(&hash_ctl, 0, sizeof(hash_ctl));
320 
321  buffer->context = new_ctx;
322 
323  buffer->change_context = SlabContextCreate(new_ctx,
324  "Change",
326  sizeof(ReorderBufferChange));
327 
328  buffer->txn_context = SlabContextCreate(new_ctx,
329  "TXN",
331  sizeof(ReorderBufferTXN));
332 
333  /*
334  * XXX the allocation sizes used below pre-date generation context's block
335  * growing code. These values should likely be benchmarked and set to
336  * more suitable values.
337  */
338  buffer->tup_context = GenerationContextCreate(new_ctx,
339  "Tuples",
343 
344  hash_ctl.keysize = sizeof(TransactionId);
345  hash_ctl.entrysize = sizeof(ReorderBufferTXNByIdEnt);
346  hash_ctl.hcxt = buffer->context;
347 
348  buffer->by_txn = hash_create("ReorderBufferByXid", 1000, &hash_ctl,
350 
352  buffer->by_txn_last_txn = NULL;
353 
354  buffer->outbuf = NULL;
355  buffer->outbufsize = 0;
356  buffer->size = 0;
357 
358  buffer->spillTxns = 0;
359  buffer->spillCount = 0;
360  buffer->spillBytes = 0;
361  buffer->streamTxns = 0;
362  buffer->streamCount = 0;
363  buffer->streamBytes = 0;
364  buffer->totalTxns = 0;
365  buffer->totalBytes = 0;
366 
368 
369  dlist_init(&buffer->toplevel_by_lsn);
371  dclist_init(&buffer->catchange_txns);
372 
373  /*
374  * Ensure there's no stale data from prior uses of this slot, in case some
375  * prior exit avoided calling ReorderBufferFree. Failure to do this can
376  * produce duplicated txns, and it's very cheap if there's nothing there.
377  */
379 
380  return buffer;
381 }
#define NameStr(name)
Definition: c.h:733
uint32 TransactionId
Definition: c.h:639
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:131
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1168
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
#define SLAB_DEFAULT_BLOCK_SIZE
Definition: memutils.h:182
#define SLAB_LARGE_BLOCK_SIZE
Definition: memutils.h:183
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
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, ReorderBufferCleanupSerializedTXNs(), 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, and ReorderBuffer::txns_by_base_snapshot_lsn.

Referenced by StartupDecodingContext().

◆ ReorderBufferAssignChild()

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

Definition at line 1060 of file reorderbuffer.c.

1062 {
1063  ReorderBufferTXN *txn;
1064  ReorderBufferTXN *subtxn;
1065  bool new_top;
1066  bool new_sub;
1067 
1068  txn = ReorderBufferTXNByXid(rb, xid, true, &new_top, lsn, true);
1069  subtxn = ReorderBufferTXNByXid(rb, subxid, true, &new_sub, lsn, false);
1070 
1071  if (!new_sub)
1072  {
1073  if (rbtxn_is_known_subxact(subtxn))
1074  {
1075  /* already associated, nothing to do */
1076  return;
1077  }
1078  else
1079  {
1080  /*
1081  * We already saw this transaction, but initially added it to the
1082  * list of top-level txns. Now that we know it's not top-level,
1083  * remove it from there.
1084  */
1085  dlist_delete(&subtxn->node);
1086  }
1087  }
1088 
1089  subtxn->txn_flags |= RBTXN_IS_SUBXACT;
1090  subtxn->toplevel_xid = xid;
1091  Assert(subtxn->nsubtxns == 0);
1092 
1093  /* set the reference to top-level transaction */
1094  subtxn->toptxn = txn;
1095 
1096  /* add to subtransaction list */
1097  dlist_push_tail(&txn->subtxns, &subtxn->node);
1098  txn->nsubtxns++;
1099 
1100  /* Possibly transfer the subtxn's snapshot to its top-level txn. */
1101  ReorderBufferTransferSnapToParent(txn, subtxn);
1102 
1103  /* Verify LSN-ordering invariant */
1104  AssertTXNLsnOrder(rb);
1105 }
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 2696 of file reorderbuffer.c.

2700 {
2701  ReorderBufferTXN *txn;
2702 
2703  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2704  false);
2705 
2706  /* unknown transaction, nothing to replay */
2707  if (txn == NULL)
2708  return;
2709 
2710  ReorderBufferReplay(txn, rb, xid, commit_lsn, end_lsn, commit_time,
2711  origin_id, origin_lsn);
2712 }
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 1180 of file reorderbuffer.c.

1183 {
1184  ReorderBufferTXN *subtxn;
1185 
1186  subtxn = ReorderBufferTXNByXid(rb, subxid, false, NULL,
1187  InvalidXLogRecPtr, false);
1188 
1189  /*
1190  * No need to do anything if that subtxn didn't contain any changes
1191  */
1192  if (!subtxn)
1193  return;
1194 
1195  subtxn->final_lsn = commit_lsn;
1196  subtxn->end_lsn = end_lsn;
1197 
1198  /*
1199  * Assign this subxact as a child of the toplevel xact (no-op if already
1200  * done.)
1201  */
1202  ReorderBufferAssignChild(rb, xid, subxid, InvalidXLogRecPtr);
1203 }
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 2802 of file reorderbuffer.c.

2807 {
2808  ReorderBufferTXN *txn;
2809  XLogRecPtr prepare_end_lsn;
2810  TimestampTz prepare_time;
2811 
2812  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, commit_lsn, false);
2813 
2814  /* unknown transaction, nothing to do */
2815  if (txn == NULL)
2816  return;
2817 
2818  /*
2819  * By this time the txn has the prepare record information, remember it to
2820  * be later used for rollback.
2821  */
2822  prepare_end_lsn = txn->end_lsn;
2823  prepare_time = txn->xact_time.prepare_time;
2824 
2825  /* add the gid in the txn */
2826  txn->gid = pstrdup(gid);
2827 
2828  /*
2829  * It is possible that this transaction is not decoded at prepare time
2830  * either because by that time we didn't have a consistent snapshot, or
2831  * two_phase was not enabled, or it was decoded earlier but we have
2832  * restarted. We only need to send the prepare if it was not decoded
2833  * earlier. We don't need to decode the xact for aborts if it is not done
2834  * already.
2835  */
2836  if ((txn->final_lsn < two_phase_at) && is_commit)
2837  {
2838  txn->txn_flags |= RBTXN_PREPARE;
2839 
2840  /*
2841  * The prepare info must have been updated in txn even if we skip
2842  * prepare.
2843  */
2845 
2846  /*
2847  * By this time the txn has the prepare record information and it is
2848  * important to use that so that downstream gets the accurate
2849  * information. If instead, we have passed commit information here
2850  * then downstream can behave as it has already replayed commit
2851  * prepared after the restart.
2852  */
2853  ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
2854  txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn);
2855  }
2856 
2857  txn->final_lsn = commit_lsn;
2858  txn->end_lsn = end_lsn;
2859  txn->xact_time.commit_time = commit_time;
2860  txn->origin_id = origin_id;
2861  txn->origin_lsn = origin_lsn;
2862 
2863  if (is_commit)
2864  rb->commit_prepared(rb, txn, commit_lsn);
2865  else
2866  rb->rollback_prepared(rb, txn, prepare_end_lsn, prepare_time);
2867 
2868  /* cleanup: make sure there's no cache pollution */
2870  txn->invalidations);
2871  ReorderBufferCleanupTXN(rb, txn);
2872 }
int64 TimestampTz
Definition: timestamp.h:39
char * pstrdup(const char *in)
Definition: mcxt.c:1683
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 2979 of file reorderbuffer.c.

2980 {
2981  ReorderBufferTXN *txn;
2982 
2983  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2984  false);
2985 
2986  /* unknown, nothing to forget */
2987  if (txn == NULL)
2988  return;
2989 
2990  /* this transaction mustn't be streamed */
2991  Assert(!rbtxn_is_streamed(txn));
2992 
2993  /* cosmetic... */
2994  txn->final_lsn = lsn;
2995 
2996  /*
2997  * Process cache invalidation messages if there are any. Even if we're not
2998  * interested in the transaction's contents, it could have manipulated the
2999  * catalog and we need to update the caches according to that.
3000  */
3001  if (txn->base_snapshot != NULL && txn->ninvalidations > 0)
3003  txn->invalidations);
3004  else
3005  Assert(txn->ninvalidations == 0);
3006 
3007  /* remove potential on-disk data, and deallocate */
3008  ReorderBufferCleanupTXN(rb, txn);
3009 }
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 387 of file reorderbuffer.c.

388 {
389  MemoryContext context = rb->context;
390 
391  /*
392  * We free separately allocated data by entirely scrapping reorderbuffer's
393  * memory context.
394  */
395  MemoryContextDelete(context);
396 
397  /* Free disk space used by unconsumed reorder buffers */
399 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:442

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

Referenced by FreeDecodingContext().

◆ ReorderBufferGetCatalogChangesXacts()

TransactionId* ReorderBufferGetCatalogChangesXacts ( ReorderBuffer rb)

Definition at line 3374 of file reorderbuffer.c.

3375 {
3376  dlist_iter iter;
3377  TransactionId *xids = NULL;
3378  size_t xcnt = 0;
3379 
3380  /* Quick return if the list is empty */
3381  if (dclist_count(&rb->catchange_txns) == 0)
3382  return NULL;
3383 
3384  /* Initialize XID array */
3385  xids = (TransactionId *) palloc(sizeof(TransactionId) *
3387  dclist_foreach(iter, &rb->catchange_txns)
3388  {
3390  catchange_node,
3391  iter.cur);
3392 
3394 
3395  xids[xcnt++] = txn->xid;
3396  }
3397 
3398  qsort(xids, xcnt, sizeof(TransactionId), xidComparator);
3399 
3400  Assert(xcnt == dclist_count(&rb->catchange_txns));
3401  return xids;
3402 }
#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 1005 of file reorderbuffer.c.

1006 {
1007  ReorderBufferTXN *txn;
1008 
1009  AssertTXNLsnOrder(rb);
1010 
1011  if (dlist_is_empty(&rb->toplevel_by_lsn))
1012  return NULL;
1013 
1015 
1018  return txn;
1019 }
#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 1033 of file reorderbuffer.c.

1034 {
1035  ReorderBufferTXN *txn;
1036 
1037  AssertTXNLsnOrder(rb);
1038 
1040  return InvalidTransactionId;
1041 
1042  txn = dlist_head_element(ReorderBufferTXN, base_snapshot_node,
1044  return txn->base_snapshot->xmin;
1045 }
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 586 of file reorderbuffer.c.

587 {
588  Oid *relids;
589  Size alloc_len;
590 
591  alloc_len = sizeof(Oid) * nrelids;
592 
593  relids = (Oid *) MemoryContextAlloc(rb->context, alloc_len);
594 
595  return relids;
596 }
size_t Size
Definition: c.h:592
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 553 of file reorderbuffer.c.

554 {
555  HeapTuple tuple;
556  Size alloc_len;
557 
558  alloc_len = tuple_len + SizeofHeapTupleHeader;
559 
561  HEAPTUPLESIZE + alloc_len);
562  tuple->t_data = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);
563 
564  return tuple;
565 }
#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 3051 of file reorderbuffer.c.

3053 {
3054  bool use_subtxn = IsTransactionOrTransactionBlock();
3055  int i;
3056 
3057  if (use_subtxn)
3058  BeginInternalSubTransaction("replay");
3059 
3060  /*
3061  * Force invalidations to happen outside of a valid transaction - that way
3062  * entries will just be marked as invalid without accessing the catalog.
3063  * That's advantageous because we don't need to setup the full state
3064  * necessary for catalog access.
3065  */
3066  if (use_subtxn)
3068 
3069  for (i = 0; i < ninvalidations; i++)
3070  LocalExecuteInvalidationMessage(&invalidations[i]);
3071 
3072  if (use_subtxn)
3074 }
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
Definition: inval.c:705
int i
Definition: isn.c:73
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4910
void BeginInternalSubTransaction(const char *name)
Definition: xact.c:4616
void RollbackAndReleaseCurrentSubTransaction(void)
Definition: xact.c:4721
void AbortCurrentTransaction(void)
Definition: xact.c:3351

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 3020 of file reorderbuffer.c.

3021 {
3022  ReorderBufferTXN *txn;
3023 
3024  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
3025  false);
3026 
3027  /* unknown, nothing to do */
3028  if (txn == NULL)
3029  return;
3030 
3031  /*
3032  * Process cache invalidation messages if there are any. Even if we're not
3033  * interested in the transaction's contents, it could have manipulated the
3034  * catalog and we need to update the caches according to that.
3035  */
3036  if (txn->base_snapshot != NULL && txn->ninvalidations > 0)
3038  txn->invalidations);
3039  else
3040  Assert(txn->ninvalidations == 0);
3041 }

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 2765 of file reorderbuffer.c.

2767 {
2768  ReorderBufferTXN *txn;
2769 
2770  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2771  false);
2772 
2773  /* unknown transaction, nothing to replay */
2774  if (txn == NULL)
2775  return;
2776 
2777  txn->txn_flags |= RBTXN_PREPARE;
2778  txn->gid = pstrdup(gid);
2779 
2780  /* The prepare info must have been updated in txn by now. */
2782 
2783  ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
2784  txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn);
2785 
2786  /*
2787  * We send the prepare for the concurrently aborted xacts so that later
2788  * when rollback prepared is decoded and sent, the downstream should be
2789  * able to rollback such a xact. See comments atop DecodePrepare.
2790  *
2791  * Note, for the concurrent_abort + streaming case a stream_prepare was
2792  * already sent within the ReorderBufferReplay call above.
2793  */
2794  if (txn->concurrent_abort && !rbtxn_is_streamed(txn))
2795  rb->prepare(rb, txn, txn->final_lsn);
2796 }
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 3087 of file reorderbuffer.c.

3088 {
3089  /* many records won't have an xid assigned, centralize check here */
3090  if (xid != InvalidTransactionId)
3091  ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3092 }

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 771 of file reorderbuffer.c.

773 {
774  ReorderBufferTXN *txn;
775 
776  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
777 
778  /*
779  * While streaming the previous changes we have detected that the
780  * transaction is aborted. So there is no point in collecting further
781  * changes for it.
782  */
783  if (txn->concurrent_abort)
784  {
785  /*
786  * We don't need to update memory accounting for this change as we
787  * have not added it to the queue yet.
788  */
789  ReorderBufferReturnChange(rb, change, false);
790  return;
791  }
792 
793  /*
794  * The changes that are sent downstream are considered streamable. We
795  * remember such transactions so that only those will later be considered
796  * for streaming.
797  */
798  if (change->action == REORDER_BUFFER_CHANGE_INSERT ||
804  {
805  ReorderBufferTXN *toptxn = rbtxn_get_toptxn(txn);
806 
808  }
809 
810  change->lsn = lsn;
811  change->txn = txn;
812 
813  Assert(InvalidXLogRecPtr != lsn);
814  dlist_push_tail(&txn->changes, &change->node);
815  txn->nentries++;
816  txn->nentries_mem++;
817 
818  /* update memory accounting information */
819  ReorderBufferChangeMemoryUpdate(rb, change, true,
820  ReorderBufferChangeSize(change));
821 
822  /* process partial change */
823  ReorderBufferProcessPartialChange(rb, txn, change, toast_insert);
824 
825  /* check the memory limits and evict something if needed */
827 }
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, 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 834 of file reorderbuffer.c.

838 {
839  if (transactional)
840  {
841  MemoryContext oldcontext;
842  ReorderBufferChange *change;
843 
845 
846  /*
847  * We don't expect snapshots for transactional changes - we'll use the
848  * snapshot derived later during apply (unless the change gets
849  * skipped).
850  */
851  Assert(!snap);
852 
853  oldcontext = MemoryContextSwitchTo(rb->context);
854 
855  change = ReorderBufferGetChange(rb);
857  change->data.msg.prefix = pstrdup(prefix);
858  change->data.msg.message_size = message_size;
859  change->data.msg.message = palloc(message_size);
860  memcpy(change->data.msg.message, message, message_size);
861 
862  ReorderBufferQueueChange(rb, xid, lsn, change, false);
863 
864  MemoryContextSwitchTo(oldcontext);
865  }
866  else
867  {
868  ReorderBufferTXN *txn = NULL;
869  volatile Snapshot snapshot_now = snap;
870 
871  /* Non-transactional changes require a valid snapshot. */
872  Assert(snapshot_now);
873 
874  if (xid != InvalidTransactionId)
875  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
876 
877  /* setup snapshot to allow catalog access */
878  SetupHistoricSnapshot(snapshot_now, NULL);
879  PG_TRY();
880  {
881  rb->message(rb, txn, lsn, false, prefix, message_size, message);
882 
884  }
885  PG_CATCH();
886  {
888  PG_RE_THROW();
889  }
890  PG_END_TRY();
891  }
892 }
#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::@100::@103 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 2718 of file reorderbuffer.c.

2722 {
2723  ReorderBufferTXN *txn;
2724 
2725  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr, false);
2726 
2727  /* unknown transaction, nothing to do */
2728  if (txn == NULL)
2729  return false;
2730 
2731  /*
2732  * Remember the prepare information to be later used by commit prepared in
2733  * case we skip doing prepare.
2734  */
2735  txn->final_lsn = prepare_lsn;
2736  txn->end_lsn = end_lsn;
2737  txn->xact_time.prepare_time = prepare_time;
2738  txn->origin_id = origin_id;
2739  txn->origin_lsn = origin_lsn;
2740 
2741  return true;
2742 }

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 483 of file reorderbuffer.c.

485 {
486  /* update memory accounting info */
487  if (upd_mem)
488  ReorderBufferChangeMemoryUpdate(rb, change, false,
489  ReorderBufferChangeSize(change));
490 
491  /* free contained data */
492  switch (change->action)
493  {
498  if (change->data.tp.newtuple)
499  {
500  ReorderBufferReturnTupleBuf(change->data.tp.newtuple);
501  change->data.tp.newtuple = NULL;
502  }
503 
504  if (change->data.tp.oldtuple)
505  {
506  ReorderBufferReturnTupleBuf(change->data.tp.oldtuple);
507  change->data.tp.oldtuple = NULL;
508  }
509  break;
511  if (change->data.msg.prefix != NULL)
512  pfree(change->data.msg.prefix);
513  change->data.msg.prefix = NULL;
514  if (change->data.msg.message != NULL)
515  pfree(change->data.msg.message);
516  change->data.msg.message = NULL;
517  break;
519  if (change->data.inval.invalidations)
520  pfree(change->data.inval.invalidations);
521  change->data.inval.invalidations = NULL;
522  break;
524  if (change->data.snapshot)
525  {
526  ReorderBufferFreeSnap(rb, change->data.snapshot);
527  change->data.snapshot = NULL;
528  }
529  break;
530  /* no data in addition to the struct itself */
532  if (change->data.truncate.relids != NULL)
533  {
534  ReorderBufferReturnRelids(rb, change->data.truncate.relids);
535  change->data.truncate.relids = NULL;
536  }
537  break;
542  break;
543  }
544 
545  pfree(change);
546 }
void pfree(void *pointer)
Definition: mcxt.c:1508
void ReorderBufferReturnTupleBuf(HeapTuple tuple)
static void ReorderBufferFreeSnap(ReorderBuffer *rb, Snapshot snap)
void ReorderBufferReturnRelids(ReorderBuffer *rb, Oid *relids)
struct ReorderBufferChange::@100::@101 tp
struct ReorderBufferChange::@100::@102 truncate

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 602 of file reorderbuffer.c.

603 {
604  pfree(relids);
605 }

References pfree().

Referenced by ReorderBufferReturnChange().

◆ ReorderBufferReturnTupleBuf()

void ReorderBufferReturnTupleBuf ( HeapTuple  tuple)

Definition at line 571 of file reorderbuffer.c.

572 {
573  pfree(tuple);
574 }

References pfree().

Referenced by ReorderBufferReturnChange().

◆ ReorderBufferSetBaseSnapshot()

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

Definition at line 3118 of file reorderbuffer.c.

3120 {
3121  ReorderBufferTXN *txn;
3122  bool is_new;
3123 
3124  Assert(snap != NULL);
3125 
3126  /*
3127  * Fetch the transaction to operate on. If we know it's a subtransaction,
3128  * operate on its top-level transaction instead.
3129  */
3130  txn = ReorderBufferTXNByXid(rb, xid, true, &is_new, lsn, true);
3131  if (rbtxn_is_known_subxact(txn))
3132  txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
3133  NULL, InvalidXLogRecPtr, false);
3134  Assert(txn->base_snapshot == NULL);
3135 
3136  txn->base_snapshot = snap;
3137  txn->base_snapshot_lsn = lsn;
3139 
3140  AssertTXNLsnOrder(rb);
3141 }
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 1048 of file reorderbuffer.c.

1049 {
1050  rb->current_restart_decoding_lsn = ptr;
1051 }

References ReorderBuffer::current_restart_decoding_lsn.

Referenced by SnapBuildRestore(), and SnapBuildSerialize().

◆ ReorderBufferSkipPrepare()

void ReorderBufferSkipPrepare ( ReorderBuffer rb,
TransactionId  xid 
)

Definition at line 2746 of file reorderbuffer.c.

2747 {
2748  ReorderBufferTXN *txn;
2749 
2750  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr, false);
2751 
2752  /* unknown transaction, nothing to do */
2753  if (txn == NULL)
2754  return;
2755 
2757 }

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

Referenced by DecodePrepare().

◆ ReorderBufferXidHasBaseSnapshot()

bool ReorderBufferXidHasBaseSnapshot ( ReorderBuffer rb,
TransactionId  xid 
)

Definition at line 3426 of file reorderbuffer.c.

3427 {
3428  ReorderBufferTXN *txn;
3429 
3430  txn = ReorderBufferTXNByXid(rb, xid, false,
3431  NULL, InvalidXLogRecPtr, false);
3432 
3433  /* transaction isn't known yet, ergo no snapshot */
3434  if (txn == NULL)
3435  return false;
3436 
3437  /* a known subtxn? operate on top-level txn instead */
3438  if (rbtxn_is_known_subxact(txn))
3439  txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
3440  NULL, InvalidXLogRecPtr, false);
3441 
3442  return txn->base_snapshot != NULL;
3443 }

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 3409 of file reorderbuffer.c.

3410 {
3411  ReorderBufferTXN *txn;
3412 
3413  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
3414  false);
3415  if (txn == NULL)
3416  return false;
3417 
3418  return rbtxn_has_catalog_changes(txn);
3419 }

References InvalidXLogRecPtr, rbtxn_has_catalog_changes, and ReorderBufferTXNByXid().

Referenced by SnapBuildXidHasCatalogChanges().

◆ ReorderBufferXidSetCatalogChanges()

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

Definition at line 3336 of file reorderbuffer.c.

3338 {
3339  ReorderBufferTXN *txn;
3340 
3341  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3342 
3343  if (!rbtxn_has_catalog_changes(txn))
3344  {
3347  }
3348 
3349  /*
3350  * Mark top-level transaction as having catalog changes too if one of its
3351  * children has so that the ReorderBufferBuildTupleCidHash can
3352  * conveniently check just top-level transaction and decide whether to
3353  * build the hash table or not.
3354  */
3355  if (rbtxn_is_subtxn(txn))
3356  {
3357  ReorderBufferTXN *toptxn = rbtxn_get_toptxn(txn);
3358 
3359  if (!rbtxn_has_catalog_changes(toptxn))
3360  {
3363  }
3364  }
3365 }
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 4587 of file reorderbuffer.c.

4588 {
4589  DIR *logical_dir;
4590  struct dirent *logical_de;
4591 
4592  logical_dir = AllocateDir("pg_replslot");
4593  while ((logical_de = ReadDir(logical_dir, "pg_replslot")) != NULL)
4594  {
4595  if (strcmp(logical_de->d_name, ".") == 0 ||
4596  strcmp(logical_de->d_name, "..") == 0)
4597  continue;
4598 
4599  /* if it cannot be a slot, skip the directory */
4600  if (!ReplicationSlotValidateName(logical_de->d_name, DEBUG2))
4601  continue;
4602 
4603  /*
4604  * ok, has to be a surviving logical slot, iterate and delete
4605  * everything starting with xid-*
4606  */
4608  }
4609  FreeDir(logical_dir);
4610 }
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 212 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 208 of file reorderbuffer.c.

Referenced by ReorderBufferCheckMemoryLimit().