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  ReorderBufferTupleBuf
 
struct  ReorderBufferChange
 
struct  ReorderBufferTXN
 
struct  ReorderBuffer
 

Macros

#define ReorderBufferTupleBufData(p)   ((HeapTupleHeader) MAXALIGN(((char *) p) + sizeof(ReorderBufferTupleBuf)))
 
#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_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_is_streamed(txn)
 
#define rbtxn_prepared(txn)
 
#define rbtxn_skip_prepared(txn)
 

Typedefs

typedef struct ReorderBufferTupleBuf ReorderBufferTupleBuf
 
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)
 

Enumerations

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 *)
 
ReorderBufferTupleBufReorderBufferGetTupleBuf (ReorderBuffer *, Size tuple_len)
 
void ReorderBufferReturnTupleBuf (ReorderBuffer *, ReorderBufferTupleBuf *tuple)
 
ReorderBufferChangeReorderBufferGetChange (ReorderBuffer *)
 
void ReorderBufferReturnChange (ReorderBuffer *, ReorderBufferChange *, bool)
 
OidReorderBufferGetRelids (ReorderBuffer *, int nrelids)
 
void ReorderBufferReturnRelids (ReorderBuffer *, Oid *relids)
 
void ReorderBufferQueueChange (ReorderBuffer *, TransactionId, XLogRecPtr lsn, ReorderBufferChange *, bool toast_insert)
 
void ReorderBufferQueueMessage (ReorderBuffer *, TransactionId, Snapshot snapshot, XLogRecPtr lsn, bool transactional, const char *prefix, Size message_size, const char *message)
 
void ReorderBufferCommit (ReorderBuffer *, TransactionId, 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 *, TransactionId, TransactionId, XLogRecPtr commit_lsn)
 
void ReorderBufferCommitChild (ReorderBuffer *, TransactionId, TransactionId, XLogRecPtr commit_lsn, XLogRecPtr end_lsn)
 
void ReorderBufferAbort (ReorderBuffer *, TransactionId, XLogRecPtr lsn)
 
void ReorderBufferAbortOld (ReorderBuffer *, TransactionId xid)
 
void ReorderBufferForget (ReorderBuffer *, TransactionId, XLogRecPtr lsn)
 
void ReorderBufferInvalidate (ReorderBuffer *, TransactionId, XLogRecPtr lsn)
 
void ReorderBufferSetBaseSnapshot (ReorderBuffer *, TransactionId, XLogRecPtr lsn, struct SnapshotData *snap)
 
void ReorderBufferAddSnapshot (ReorderBuffer *, TransactionId, XLogRecPtr lsn, struct SnapshotData *snap)
 
void ReorderBufferAddNewCommandId (ReorderBuffer *, TransactionId, XLogRecPtr lsn, CommandId cid)
 
void ReorderBufferAddNewTupleCids (ReorderBuffer *, TransactionId, XLogRecPtr lsn, RelFileNode node, ItemPointerData pt, CommandId cmin, CommandId cmax, CommandId combocid)
 
void ReorderBufferAddInvalidations (ReorderBuffer *, TransactionId, XLogRecPtr lsn, Size nmsgs, SharedInvalidationMessage *msgs)
 
void ReorderBufferImmediateInvalidation (ReorderBuffer *, uint32 ninvalidations, SharedInvalidationMessage *invalidations)
 
void ReorderBufferProcessXid (ReorderBuffer *, TransactionId xid, XLogRecPtr lsn)
 
void ReorderBufferXidSetCatalogChanges (ReorderBuffer *, TransactionId xid, XLogRecPtr lsn)
 
bool ReorderBufferXidHasCatalogChanges (ReorderBuffer *, TransactionId xid)
 
bool ReorderBufferXidHasBaseSnapshot (ReorderBuffer *, 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 *)
 
TransactionId ReorderBufferGetOldestXmin (ReorderBuffer *rb)
 
void ReorderBufferSetRestartPoint (ReorderBuffer *, XLogRecPtr ptr)
 
void StartupReorderBuffer (void)
 

Variables

PGDLLIMPORT int logical_decoding_work_mem
 

Macro Definition Documentation

◆ RBTXN_HAS_CATALOG_CHANGES

#define RBTXN_HAS_CATALOG_CHANGES   0x0001

Definition at line 171 of file reorderbuffer.h.

Referenced by ReorderBufferXidSetCatalogChanges().

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

Referenced by ReorderBufferBuildTupleCidHash(), and ReorderBufferXidHasCatalogChanges().

◆ RBTXN_HAS_PARTIAL_CHANGE

#define RBTXN_HAS_PARTIAL_CHANGE   0x0020

Definition at line 176 of file reorderbuffer.h.

Referenced by ReorderBufferProcessPartialChange().

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

Referenced by ReorderBufferLargestTopTXN(), and ReorderBufferProcessPartialChange().

◆ rbtxn_is_known_subxact

◆ RBTXN_IS_SERIALIZED

#define RBTXN_IS_SERIALIZED   0x0004

Definition at line 173 of file reorderbuffer.h.

Referenced by ReorderBufferSerializeTXN(), and ReorderBufferTruncateTXN().

◆ rbtxn_is_serialized

#define rbtxn_is_serialized (   txn)

◆ RBTXN_IS_SERIALIZED_CLEAR

#define RBTXN_IS_SERIALIZED_CLEAR   0x0008

Definition at line 174 of file reorderbuffer.h.

Referenced by ReorderBufferTruncateTXN().

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

Referenced by ReorderBufferSerializeTXN().

◆ RBTXN_IS_STREAMED

#define RBTXN_IS_STREAMED   0x0010

Definition at line 175 of file reorderbuffer.h.

Referenced by ReorderBufferTruncateTXN().

◆ rbtxn_is_streamed

◆ RBTXN_IS_SUBXACT

#define RBTXN_IS_SUBXACT   0x0002

Definition at line 172 of file reorderbuffer.h.

Referenced by ReorderBufferAssignChild().

◆ RBTXN_PREPARE

#define RBTXN_PREPARE   0x0040

Definition at line 177 of file reorderbuffer.h.

Referenced by ReorderBufferFinishPrepared(), and ReorderBufferPrepare().

◆ rbtxn_prepared

#define rbtxn_prepared (   txn)

◆ rbtxn_skip_prepared

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

Definition at line 231 of file reorderbuffer.h.

Referenced by SnapBuildDistributeNewCatalogSnapshot().

◆ RBTXN_SKIPPED_PREPARE

#define RBTXN_SKIPPED_PREPARE   0x0080

Definition at line 178 of file reorderbuffer.h.

Referenced by ReorderBufferSkipPrepare().

◆ ReorderBufferTupleBufData

#define ReorderBufferTupleBufData (   p)    ((HeapTupleHeader) MAXALIGN(((char *) p) + sizeof(ReorderBufferTupleBuf)))

Typedef Documentation

◆ ReorderBuffer

typedef struct ReorderBuffer ReorderBuffer

Definition at line 401 of file reorderbuffer.h.

◆ ReorderBufferApplyChangeCB

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

Definition at line 404 of file reorderbuffer.h.

◆ ReorderBufferApplyTruncateCB

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

Definition at line 410 of file reorderbuffer.h.

◆ ReorderBufferBeginCB

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

Definition at line 417 of file reorderbuffer.h.

◆ ReorderBufferBeginPrepareCB

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

Definition at line 434 of file reorderbuffer.h.

◆ ReorderBufferChange

◆ ReorderBufferCommitCB

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

Definition at line 421 of file reorderbuffer.h.

◆ ReorderBufferCommitPreparedCB

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

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

◆ ReorderBufferPrepareCB

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

Definition at line 438 of file reorderbuffer.h.

◆ ReorderBufferRollbackPreparedCB

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

Definition at line 448 of file reorderbuffer.h.

◆ ReorderBufferStreamAbortCB

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

Definition at line 466 of file reorderbuffer.h.

◆ ReorderBufferStreamChangeCB

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

Definition at line 484 of file reorderbuffer.h.

◆ ReorderBufferStreamCommitCB

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

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

◆ ReorderBufferStreamPrepareCB

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

Definition at line 472 of file reorderbuffer.h.

◆ ReorderBufferStreamStartCB

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

Definition at line 454 of file reorderbuffer.h.

◆ ReorderBufferStreamStopCB

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

Definition at line 460 of file reorderbuffer.h.

◆ ReorderBufferStreamTruncateCB

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

Definition at line 500 of file reorderbuffer.h.

◆ ReorderBufferTupleBuf

◆ ReorderBufferTXN

Enumeration Type Documentation

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

Function Documentation

◆ ReorderBufferAbort()

void ReorderBufferAbort ( ReorderBuffer ,
TransactionId  ,
XLogRecPtr  lsn 
)

Definition at line 2823 of file reorderbuffer.c.

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

Referenced by DecodeAbort().

2824 {
2825  ReorderBufferTXN *txn;
2826 
2827  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2828  false);
2829 
2830  /* unknown, nothing to remove */
2831  if (txn == NULL)
2832  return;
2833 
2834  /* For streamed transactions notify the remote node about the abort. */
2835  if (rbtxn_is_streamed(txn))
2836  {
2837  rb->stream_abort(rb, txn, lsn);
2838 
2839  /*
2840  * We might have decoded changes for this transaction that could load
2841  * the cache as per the current transaction's view (consider DDL's
2842  * happened in this transaction). We don't want the decoding of future
2843  * transactions to use those cache entries so execute invalidations.
2844  */
2845  if (txn->ninvalidations > 0)
2847  txn->invalidations);
2848  }
2849 
2850  /* cosmetic... */
2851  txn->final_lsn = lsn;
2852 
2853  /* remove potential on-disk data, and deallocate */
2854  ReorderBufferCleanupTXN(rb, txn);
2855 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define rbtxn_is_streamed(txn)
void ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations)
XLogRecPtr final_lsn
static void ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
SharedInvalidationMessage * invalidations
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)

◆ ReorderBufferAbortOld()

void ReorderBufferAbortOld ( ReorderBuffer ,
TransactionId  xid 
)

Definition at line 2865 of file reorderbuffer.c.

References dlist_mutable_iter::cur, DEBUG2, dlist_container, dlist_foreach_modify, elog, ReorderBufferCleanupTXN(), ReorderBuffer::toplevel_by_lsn, TransactionIdPrecedes(), ReorderBufferTXNByIdEnt::txn, and ReorderBufferTXN::xid.

Referenced by DecodeStandbyOp().

2866 {
2867  dlist_mutable_iter it;
2868 
2869  /*
2870  * Iterate through all (potential) toplevel TXNs and abort all that are
2871  * older than what possibly can be running. Once we've found the first
2872  * that is alive we stop, there might be some that acquired an xid earlier
2873  * but started writing later, but it's unlikely and they will be cleaned
2874  * up in a later call to this function.
2875  */
2876  dlist_foreach_modify(it, &rb->toplevel_by_lsn)
2877  {
2878  ReorderBufferTXN *txn;
2879 
2880  txn = dlist_container(ReorderBufferTXN, node, it.cur);
2881 
2882  if (TransactionIdPrecedes(txn->xid, oldestRunningXid))
2883  {
2884  elog(DEBUG2, "aborting old transaction %u", txn->xid);
2885 
2886  /* remove potential on-disk data, and deallocate this tx */
2887  ReorderBufferCleanupTXN(rb, txn);
2888  }
2889  else
2890  return;
2891  }
2892 }
dlist_node * cur
Definition: ilist.h:180
#define dlist_foreach_modify(iter, lhead)
Definition: ilist.h:543
#define dlist_container(type, membername, ptr)
Definition: ilist.h:496
#define DEBUG2
Definition: elog.h:24
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
static void ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
TransactionId xid
#define elog(elevel,...)
Definition: elog.h:232

◆ ReorderBufferAddInvalidations()

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

Definition at line 3197 of file reorderbuffer.c.

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

Referenced by DecodeXactOp().

3200 {
3201  ReorderBufferTXN *txn;
3202  MemoryContext oldcontext;
3203  ReorderBufferChange *change;
3204 
3205  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3206 
3207  oldcontext = MemoryContextSwitchTo(rb->context);
3208 
3209  /*
3210  * Collect all the invalidations under the top transaction so that we can
3211  * execute them all together. See comment atop this function
3212  */
3213  if (txn->toptxn)
3214  txn = txn->toptxn;
3215 
3216  Assert(nmsgs > 0);
3217 
3218  /* Accumulate invalidations. */
3219  if (txn->ninvalidations == 0)
3220  {
3221  txn->ninvalidations = nmsgs;
3223  palloc(sizeof(SharedInvalidationMessage) * nmsgs);
3224  memcpy(txn->invalidations, msgs,
3225  sizeof(SharedInvalidationMessage) * nmsgs);
3226  }
3227  else
3228  {
3231  (txn->ninvalidations + nmsgs));
3232 
3233  memcpy(txn->invalidations + txn->ninvalidations, msgs,
3234  nmsgs * sizeof(SharedInvalidationMessage));
3235  txn->ninvalidations += nmsgs;
3236  }
3237 
3238  change = ReorderBufferGetChange(rb);
3240  change->data.inval.ninvalidations = nmsgs;
3241  change->data.inval.invalidations = (SharedInvalidationMessage *)
3242  palloc(sizeof(SharedInvalidationMessage) * nmsgs);
3243  memcpy(change->data.inval.invalidations, msgs,
3244  sizeof(SharedInvalidationMessage) * nmsgs);
3245 
3246  ReorderBufferQueueChange(rb, xid, lsn, change, false);
3247 
3248  MemoryContextSwitchTo(oldcontext);
3249 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
ReorderBufferChange * ReorderBufferGetChange(ReorderBuffer *rb)
enum ReorderBufferChangeType action
Definition: reorderbuffer.h:85
struct ReorderBufferTXN * toptxn
struct ReorderBufferChange::@97::@102 inval
union ReorderBufferChange::@97 data
void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, ReorderBufferChange *change, bool toast_insert)
#define Assert(condition)
Definition: c.h:804
SharedInvalidationMessage * invalidations
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1182
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
void * palloc(Size size)
Definition: mcxt.c:1062

◆ ReorderBufferAddNewCommandId()

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

Definition at line 3079 of file reorderbuffer.c.

References ReorderBufferChange::action, ReorderBufferChange::command_id, ReorderBufferChange::data, REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID, ReorderBufferGetChange(), and ReorderBufferQueueChange().

Referenced by SnapBuildProcessNewCid().

3081 {
3083 
3084  change->data.command_id = cid;
3086 
3087  ReorderBufferQueueChange(rb, xid, lsn, change, false);
3088 }
ReorderBufferChange * ReorderBufferGetChange(ReorderBuffer *rb)
enum ReorderBufferChangeType action
Definition: reorderbuffer.h:85
union ReorderBufferChange::@97 data
void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, ReorderBufferChange *change, bool toast_insert)

◆ ReorderBufferAddNewTupleCids()

void ReorderBufferAddNewTupleCids ( ReorderBuffer ,
TransactionId  ,
XLogRecPtr  lsn,
RelFileNode  node,
ItemPointerData  pt,
CommandId  cmin,
CommandId  cmax,
CommandId  combocid 
)

Definition at line 3161 of file reorderbuffer.c.

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, ReorderBufferChange::txn, and ReorderBufferTXNByIdEnt::txn.

Referenced by SnapBuildProcessNewCid().

3165 {
3167  ReorderBufferTXN *txn;
3168 
3169  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3170 
3171  change->data.tuplecid.node = node;
3172  change->data.tuplecid.tid = tid;
3173  change->data.tuplecid.cmin = cmin;
3174  change->data.tuplecid.cmax = cmax;
3175  change->data.tuplecid.combocid = combocid;
3176  change->lsn = lsn;
3177  change->txn = txn;
3179 
3180  dlist_push_tail(&txn->tuplecids, &change->node);
3181  txn->ntuplecids++;
3182 }
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:317
struct ReorderBufferTXN * txn
Definition: reorderbuffer.h:88
ReorderBufferChange * ReorderBufferGetChange(ReorderBuffer *rb)
enum ReorderBufferChangeType action
Definition: reorderbuffer.h:85
union ReorderBufferChange::@97 data
struct ReorderBufferChange::@97::@101 tuplecid
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
dlist_head tuplecids

◆ ReorderBufferAddSnapshot()

void ReorderBufferAddSnapshot ( ReorderBuffer ,
TransactionId  ,
XLogRecPtr  lsn,
struct SnapshotData snap 
)

◆ ReorderBufferAllocate()

ReorderBuffer* ReorderBufferAllocate ( void  )

Definition at line 301 of file reorderbuffer.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, ReorderBuffer::by_txn, ReorderBuffer::by_txn_last_txn, ReorderBuffer::by_txn_last_xid, ReorderBuffer::change_context, ReorderBuffer::context, ReorderBuffer::current_restart_decoding_lsn, CurrentMemoryContext, ReplicationSlot::data, 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().

302 {
303  ReorderBuffer *buffer;
304  HASHCTL hash_ctl;
305  MemoryContext new_ctx;
306 
307  Assert(MyReplicationSlot != NULL);
308 
309  /* allocate memory in own context, to have better accountability */
311  "ReorderBuffer",
313 
314  buffer =
315  (ReorderBuffer *) MemoryContextAlloc(new_ctx, sizeof(ReorderBuffer));
316 
317  memset(&hash_ctl, 0, sizeof(hash_ctl));
318 
319  buffer->context = new_ctx;
320 
321  buffer->change_context = SlabContextCreate(new_ctx,
322  "Change",
324  sizeof(ReorderBufferChange));
325 
326  buffer->txn_context = SlabContextCreate(new_ctx,
327  "TXN",
329  sizeof(ReorderBufferTXN));
330 
331  buffer->tup_context = GenerationContextCreate(new_ctx,
332  "Tuples",
334 
335  hash_ctl.keysize = sizeof(TransactionId);
336  hash_ctl.entrysize = sizeof(ReorderBufferTXNByIdEnt);
337  hash_ctl.hcxt = buffer->context;
338 
339  buffer->by_txn = hash_create("ReorderBufferByXid", 1000, &hash_ctl,
341 
343  buffer->by_txn_last_txn = NULL;
344 
345  buffer->outbuf = NULL;
346  buffer->outbufsize = 0;
347  buffer->size = 0;
348 
349  buffer->spillTxns = 0;
350  buffer->spillCount = 0;
351  buffer->spillBytes = 0;
352  buffer->streamTxns = 0;
353  buffer->streamCount = 0;
354  buffer->streamBytes = 0;
355  buffer->totalTxns = 0;
356  buffer->totalBytes = 0;
357 
359 
360  dlist_init(&buffer->toplevel_by_lsn);
362 
363  /*
364  * Ensure there's no stale data from prior uses of this slot, in case some
365  * prior exit avoided calling ReorderBufferFree. Failure to do this can
366  * produce duplicated txns, and it's very cheap if there's nothing there.
367  */
369 
370  return buffer;
371 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define AllocSetContextCreate
Definition: memutils.h:173
#define HASH_CONTEXT
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
uint32 TransactionId
Definition: c.h:587
MemoryContext hcxt
Definition: hsearch.h:86
TransactionId by_txn_last_xid
XLogRecPtr current_restart_decoding_lsn
Size entrysize
Definition: hsearch.h:76
MemoryContext SlabContextCreate(MemoryContext parent, const char *name, Size blockSize, Size chunkSize)
Definition: slab.c:175
ReplicationSlotPersistentData data
Definition: slot.h:147
MemoryContext change_context
#define SLAB_LARGE_BLOCK_SIZE
Definition: memutils.h:225
dlist_head txns_by_base_snapshot_lsn
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
#define InvalidTransactionId
Definition: transam.h:31
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
#define HASH_BLOBS
Definition: hsearch.h:97
MemoryContext GenerationContextCreate(MemoryContext parent, const char *name, Size blockSize)
Definition: generation.c:197
MemoryContext context
ReorderBufferTXN * by_txn_last_txn
dlist_head toplevel_by_lsn
Size keysize
Definition: hsearch.h:75
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
#define Assert(condition)
Definition: c.h:804
#define SLAB_DEFAULT_BLOCK_SIZE
Definition: memutils.h:224
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
#define NameStr(name)
Definition: c.h:681
struct ReorderBufferTXNByIdEnt ReorderBufferTXNByIdEnt
MemoryContext tup_context
static void ReorderBufferCleanupSerializedTXNs(const char *slotname)
MemoryContext txn_context

◆ ReorderBufferAssignChild()

void ReorderBufferAssignChild ( ReorderBuffer ,
TransactionId  ,
TransactionId  ,
XLogRecPtr  commit_lsn 
)

Definition at line 1014 of file reorderbuffer.c.

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, ReorderBufferTXNByIdEnt::txn, ReorderBufferTXN::txn_flags, and ReorderBufferTXNByIdEnt::xid.

Referenced by LogicalDecodingProcessRecord(), and ReorderBufferCommitChild().

1016 {
1017  ReorderBufferTXN *txn;
1018  ReorderBufferTXN *subtxn;
1019  bool new_top;
1020  bool new_sub;
1021 
1022  txn = ReorderBufferTXNByXid(rb, xid, true, &new_top, lsn, true);
1023  subtxn = ReorderBufferTXNByXid(rb, subxid, true, &new_sub, lsn, false);
1024 
1025  if (!new_sub)
1026  {
1027  if (rbtxn_is_known_subxact(subtxn))
1028  {
1029  /* already associated, nothing to do */
1030  return;
1031  }
1032  else
1033  {
1034  /*
1035  * We already saw this transaction, but initially added it to the
1036  * list of top-level txns. Now that we know it's not top-level,
1037  * remove it from there.
1038  */
1039  dlist_delete(&subtxn->node);
1040  }
1041  }
1042 
1043  subtxn->txn_flags |= RBTXN_IS_SUBXACT;
1044  subtxn->toplevel_xid = xid;
1045  Assert(subtxn->nsubtxns == 0);
1046 
1047  /* set the reference to top-level transaction */
1048  subtxn->toptxn = txn;
1049 
1050  /* add to subtransaction list */
1051  dlist_push_tail(&txn->subtxns, &subtxn->node);
1052  txn->nsubtxns++;
1053 
1054  /* Possibly transfer the subtxn's snapshot to its top-level txn. */
1055  ReorderBufferTransferSnapToParent(txn, subtxn);
1056 
1057  /* Verify LSN-ordering invariant */
1058  AssertTXNLsnOrder(rb);
1059 }
static void ReorderBufferTransferSnapToParent(ReorderBufferTXN *txn, ReorderBufferTXN *subtxn)
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:317
#define RBTXN_IS_SUBXACT
struct ReorderBufferTXN * toptxn
static void dlist_delete(dlist_node *node)
Definition: ilist.h:358
static void AssertTXNLsnOrder(ReorderBuffer *rb)
#define Assert(condition)
Definition: c.h:804
dlist_head subtxns
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
#define rbtxn_is_known_subxact(txn)
TransactionId toplevel_xid

◆ ReorderBufferCommit()

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

Definition at line 2632 of file reorderbuffer.c.

References InvalidXLogRecPtr, ReorderBufferReplay(), ReorderBufferTXNByXid(), and ReorderBufferTXNByIdEnt::txn.

Referenced by DecodeCommit().

2636 {
2637  ReorderBufferTXN *txn;
2638 
2639  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2640  false);
2641 
2642  /* unknown transaction, nothing to replay */
2643  if (txn == NULL)
2644  return;
2645 
2646  ReorderBufferReplay(txn, rb, xid, commit_lsn, end_lsn, commit_time,
2647  origin_id, origin_lsn);
2648 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
static void ReorderBufferReplay(ReorderBufferTXN *txn, ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn)
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)

◆ ReorderBufferCommitChild()

void ReorderBufferCommitChild ( ReorderBuffer ,
TransactionId  ,
TransactionId  ,
XLogRecPtr  commit_lsn,
XLogRecPtr  end_lsn 
)

Definition at line 1134 of file reorderbuffer.c.

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

Referenced by DecodeCommit(), and DecodePrepare().

1137 {
1138  ReorderBufferTXN *subtxn;
1139 
1140  subtxn = ReorderBufferTXNByXid(rb, subxid, false, NULL,
1141  InvalidXLogRecPtr, false);
1142 
1143  /*
1144  * No need to do anything if that subtxn didn't contain any changes
1145  */
1146  if (!subtxn)
1147  return;
1148 
1149  subtxn->final_lsn = commit_lsn;
1150  subtxn->end_lsn = end_lsn;
1151 
1152  /*
1153  * Assign this subxact as a child of the toplevel xact (no-op if already
1154  * done.)
1155  */
1156  ReorderBufferAssignChild(rb, xid, subxid, InvalidXLogRecPtr);
1157 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
XLogRecPtr final_lsn
void ReorderBufferAssignChild(ReorderBuffer *rb, TransactionId xid, TransactionId subxid, XLogRecPtr lsn)
XLogRecPtr end_lsn
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)

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

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, ReorderBufferTXNByIdEnt::txn, ReorderBufferTXN::txn_flags, and ReorderBufferTXN::xact_time.

Referenced by DecodeAbort(), and DecodeCommit().

2743 {
2744  ReorderBufferTXN *txn;
2745  XLogRecPtr prepare_end_lsn;
2746  TimestampTz prepare_time;
2747 
2748  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, commit_lsn, false);
2749 
2750  /* unknown transaction, nothing to do */
2751  if (txn == NULL)
2752  return;
2753 
2754  /*
2755  * By this time the txn has the prepare record information, remember it to
2756  * be later used for rollback.
2757  */
2758  prepare_end_lsn = txn->end_lsn;
2759  prepare_time = txn->xact_time.prepare_time;
2760 
2761  /* add the gid in the txn */
2762  txn->gid = pstrdup(gid);
2763 
2764  /*
2765  * It is possible that this transaction is not decoded at prepare time
2766  * either because by that time we didn't have a consistent snapshot, or
2767  * two_phase was not enabled, or it was decoded earlier but we have
2768  * restarted. We only need to send the prepare if it was not decoded
2769  * earlier. We don't need to decode the xact for aborts if it is not done
2770  * already.
2771  */
2772  if ((txn->final_lsn < two_phase_at) && is_commit)
2773  {
2774  txn->txn_flags |= RBTXN_PREPARE;
2775 
2776  /*
2777  * The prepare info must have been updated in txn even if we skip
2778  * prepare.
2779  */
2781 
2782  /*
2783  * By this time the txn has the prepare record information and it is
2784  * important to use that so that downstream gets the accurate
2785  * information. If instead, we have passed commit information here
2786  * then downstream can behave as it has already replayed commit
2787  * prepared after the restart.
2788  */
2789  ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
2790  txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn);
2791  }
2792 
2793  txn->final_lsn = commit_lsn;
2794  txn->end_lsn = end_lsn;
2795  txn->xact_time.commit_time = commit_time;
2796  txn->origin_id = origin_id;
2797  txn->origin_lsn = origin_lsn;
2798 
2799  if (is_commit)
2800  rb->commit_prepared(rb, txn, commit_lsn);
2801  else
2802  rb->rollback_prepared(rb, txn, prepare_end_lsn, prepare_time);
2803 
2804  /* cleanup: make sure there's no cache pollution */
2806  txn->invalidations);
2807  ReorderBufferCleanupTXN(rb, txn);
2808 }
TimestampTz commit_time
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
RepOriginId origin_id
int64 TimestampTz
Definition: timestamp.h:39
char * pstrdup(const char *in)
Definition: mcxt.c:1299
XLogRecPtr origin_lsn
XLogRecPtr final_lsn
static void ReorderBufferReplay(ReorderBufferTXN *txn, ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn)
static void ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
union ReorderBufferTXN::@103 xact_time
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:804
XLogRecPtr end_lsn
ReorderBufferRollbackPreparedCB rollback_prepared
SharedInvalidationMessage * invalidations
#define RBTXN_PREPARE
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
static void ReorderBufferExecuteInvalidations(uint32 nmsgs, SharedInvalidationMessage *msgs)
TimestampTz prepare_time
ReorderBufferCommitPreparedCB commit_prepared

◆ ReorderBufferForget()

void ReorderBufferForget ( ReorderBuffer ,
TransactionId  ,
XLogRecPtr  lsn 
)

Definition at line 2908 of file reorderbuffer.c.

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

Referenced by DecodeCommit().

2909 {
2910  ReorderBufferTXN *txn;
2911 
2912  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2913  false);
2914 
2915  /* unknown, nothing to forget */
2916  if (txn == NULL)
2917  return;
2918 
2919  /* For streamed transactions notify the remote node about the abort. */
2920  if (rbtxn_is_streamed(txn))
2921  rb->stream_abort(rb, txn, lsn);
2922 
2923  /* cosmetic... */
2924  txn->final_lsn = lsn;
2925 
2926  /*
2927  * Process cache invalidation messages if there are any. Even if we're not
2928  * interested in the transaction's contents, it could have manipulated the
2929  * catalog and we need to update the caches according to that.
2930  */
2931  if (txn->base_snapshot != NULL && txn->ninvalidations > 0)
2933  txn->invalidations);
2934  else
2935  Assert(txn->ninvalidations == 0);
2936 
2937  /* remove potential on-disk data, and deallocate */
2938  ReorderBufferCleanupTXN(rb, txn);
2939 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
Snapshot base_snapshot
#define rbtxn_is_streamed(txn)
void ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations)
XLogRecPtr final_lsn
static void ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
#define Assert(condition)
Definition: c.h:804
SharedInvalidationMessage * invalidations
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)

◆ ReorderBufferFree()

void ReorderBufferFree ( ReorderBuffer )

Definition at line 377 of file reorderbuffer.c.

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

Referenced by FreeDecodingContext().

378 {
379  MemoryContext context = rb->context;
380 
381  /*
382  * We free separately allocated data by entirely scrapping reorderbuffer's
383  * memory context.
384  */
385  MemoryContextDelete(context);
386 
387  /* Free disk space used by unconsumed reorder buffers */
389 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
ReplicationSlotPersistentData data
Definition: slot.h:147
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
#define NameStr(name)
Definition: c.h:681
static void ReorderBufferCleanupSerializedTXNs(const char *slotname)

◆ ReorderBufferGetChange()

ReorderBufferChange* ReorderBufferGetChange ( ReorderBuffer )

Definition at line 458 of file reorderbuffer.c.

References ReorderBuffer::change_context, and MemoryContextAlloc().

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

459 {
460  ReorderBufferChange *change;
461 
462  change = (ReorderBufferChange *)
463  MemoryContextAlloc(rb->change_context, sizeof(ReorderBufferChange));
464 
465  memset(change, 0, sizeof(ReorderBufferChange));
466  return change;
467 }
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863

◆ ReorderBufferGetOldestTXN()

ReorderBufferTXN* ReorderBufferGetOldestTXN ( ReorderBuffer )

Definition at line 959 of file reorderbuffer.c.

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

Referenced by SnapBuildProcessRunningXacts().

960 {
961  ReorderBufferTXN *txn;
962 
963  AssertTXNLsnOrder(rb);
964 
965  if (dlist_is_empty(&rb->toplevel_by_lsn))
966  return NULL;
967 
968  txn = dlist_head_element(ReorderBufferTXN, node, &rb->toplevel_by_lsn);
969 
972  return txn;
973 }
XLogRecPtr first_lsn
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define dlist_head_element(type, membername, lhead)
Definition: ilist.h:506
static void AssertTXNLsnOrder(ReorderBuffer *rb)
#define Assert(condition)
Definition: c.h:804
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289
#define rbtxn_is_known_subxact(txn)

◆ ReorderBufferGetOldestXmin()

TransactionId ReorderBufferGetOldestXmin ( ReorderBuffer rb)

Definition at line 987 of file reorderbuffer.c.

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

Referenced by SnapBuildProcessRunningXacts().

988 {
989  ReorderBufferTXN *txn;
990 
991  AssertTXNLsnOrder(rb);
992 
994  return InvalidTransactionId;
995 
996  txn = dlist_head_element(ReorderBufferTXN, base_snapshot_node,
998  return txn->base_snapshot->xmin;
999 }
Snapshot base_snapshot
dlist_head txns_by_base_snapshot_lsn
#define InvalidTransactionId
Definition: transam.h:31
TransactionId xmin
Definition: snapshot.h:157
#define dlist_head_element(type, membername, lhead)
Definition: ilist.h:506
static void AssertTXNLsnOrder(ReorderBuffer *rb)
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289

◆ ReorderBufferGetRelids()

Oid* ReorderBufferGetRelids ( ReorderBuffer ,
int  nrelids 
)

Definition at line 579 of file reorderbuffer.c.

References ReorderBuffer::context, and MemoryContextAlloc().

Referenced by DecodeTruncate(), and ReorderBufferRestoreChange().

580 {
581  Oid *relids;
582  Size alloc_len;
583 
584  alloc_len = sizeof(Oid) * nrelids;
585 
586  relids = (Oid *) MemoryContextAlloc(rb->context, alloc_len);
587 
588  return relids;
589 }
unsigned int Oid
Definition: postgres_ext.h:31
size_t Size
Definition: c.h:540
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863

◆ ReorderBufferGetTupleBuf()

ReorderBufferTupleBuf* ReorderBufferGetTupleBuf ( ReorderBuffer ,
Size  tuple_len 
)

Definition at line 543 of file reorderbuffer.c.

References ReorderBufferTupleBuf::alloc_tuple_size, MemoryContextAlloc(), ReorderBufferTupleBufData, SizeofHeapTupleHeader, HeapTupleData::t_data, ReorderBuffer::tup_context, and ReorderBufferTupleBuf::tuple.

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

544 {
545  ReorderBufferTupleBuf *tuple;
546  Size alloc_len;
547 
548  alloc_len = tuple_len + SizeofHeapTupleHeader;
549 
550  tuple = (ReorderBufferTupleBuf *)
551  MemoryContextAlloc(rb->tup_context,
552  sizeof(ReorderBufferTupleBuf) +
553  MAXIMUM_ALIGNOF + alloc_len);
554  tuple->alloc_tuple_size = alloc_len;
555  tuple->tuple.t_data = ReorderBufferTupleBufData(tuple);
556 
557  return tuple;
558 }
#define SizeofHeapTupleHeader
Definition: htup_details.h:184
HeapTupleHeader t_data
Definition: htup.h:68
#define ReorderBufferTupleBufData(p)
Definition: reorderbuffer.h:38
HeapTupleData tuple
Definition: reorderbuffer.h:29
size_t Size
Definition: c.h:540
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863

◆ ReorderBufferImmediateInvalidation()

void ReorderBufferImmediateInvalidation ( ReorderBuffer ,
uint32  ninvalidations,
SharedInvalidationMessage invalidations 
)

Definition at line 2981 of file reorderbuffer.c.

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

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

2983 {
2984  bool use_subtxn = IsTransactionOrTransactionBlock();
2985  int i;
2986 
2987  if (use_subtxn)
2988  BeginInternalSubTransaction("replay");
2989 
2990  /*
2991  * Force invalidations to happen outside of a valid transaction - that way
2992  * entries will just be marked as invalid without accessing the catalog.
2993  * That's advantageous because we don't need to setup the full state
2994  * necessary for catalog access.
2995  */
2996  if (use_subtxn)
2998 
2999  for (i = 0; i < ninvalidations; i++)
3000  LocalExecuteInvalidationMessage(&invalidations[i]);
3001 
3002  if (use_subtxn)
3004 }
void AbortCurrentTransaction(void)
Definition: xact.c:3230
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4721
void RollbackAndReleaseCurrentSubTransaction(void)
Definition: xact.c:4532
void BeginInternalSubTransaction(const char *name)
Definition: xact.c:4427
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
Definition: inval.c:614
int i

◆ ReorderBufferInvalidate()

void ReorderBufferInvalidate ( ReorderBuffer ,
TransactionId  ,
XLogRecPtr  lsn 
)

Definition at line 2950 of file reorderbuffer.c.

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

Referenced by DecodePrepare().

2951 {
2952  ReorderBufferTXN *txn;
2953 
2954  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2955  false);
2956 
2957  /* unknown, nothing to do */
2958  if (txn == NULL)
2959  return;
2960 
2961  /*
2962  * Process cache invalidation messages if there are any. Even if we're not
2963  * interested in the transaction's contents, it could have manipulated the
2964  * catalog and we need to update the caches according to that.
2965  */
2966  if (txn->base_snapshot != NULL && txn->ninvalidations > 0)
2968  txn->invalidations);
2969  else
2970  Assert(txn->ninvalidations == 0);
2971 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
Snapshot base_snapshot
void ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations)
#define Assert(condition)
Definition: c.h:804
SharedInvalidationMessage * invalidations
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)

◆ ReorderBufferPrepare()

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

Definition at line 2701 of file reorderbuffer.c.

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(), ReorderBufferTXNByIdEnt::txn, ReorderBufferTXN::txn_flags, and ReorderBufferTXN::xact_time.

Referenced by DecodePrepare().

2703 {
2704  ReorderBufferTXN *txn;
2705 
2706  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2707  false);
2708 
2709  /* unknown transaction, nothing to replay */
2710  if (txn == NULL)
2711  return;
2712 
2713  txn->txn_flags |= RBTXN_PREPARE;
2714  txn->gid = pstrdup(gid);
2715 
2716  /* The prepare info must have been updated in txn by now. */
2718 
2719  ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
2720  txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn);
2721 
2722  /*
2723  * We send the prepare for the concurrently aborted xacts so that later
2724  * when rollback prepared is decoded and sent, the downstream should be
2725  * able to rollback such a xact. See comments atop DecodePrepare.
2726  *
2727  * Note, for the concurrent_abort + streaming case a stream_prepare was
2728  * already sent within the ReorderBufferReplay call above.
2729  */
2730  if (txn->concurrent_abort && !rbtxn_is_streamed(txn))
2731  rb->prepare(rb, txn, txn->final_lsn);
2732 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
RepOriginId origin_id
char * pstrdup(const char *in)
Definition: mcxt.c:1299
XLogRecPtr origin_lsn
#define rbtxn_is_streamed(txn)
XLogRecPtr final_lsn
static void ReorderBufferReplay(ReorderBufferTXN *txn, ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn)
union ReorderBufferTXN::@103 xact_time
#define Assert(condition)
Definition: c.h:804
XLogRecPtr end_lsn
#define RBTXN_PREPARE
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
TimestampTz prepare_time
ReorderBufferPrepareCB prepare

◆ ReorderBufferProcessXid()

void ReorderBufferProcessXid ( ReorderBuffer ,
TransactionId  xid,
XLogRecPtr  lsn 
)

Definition at line 3017 of file reorderbuffer.c.

References InvalidTransactionId, and ReorderBufferTXNByXid().

Referenced by DecodeHeap2Op(), DecodeHeapOp(), DecodeLogicalMsgOp(), DecodeStandbyOp(), DecodeXactOp(), DecodeXLogOp(), and LogicalDecodingProcessRecord().

3018 {
3019  /* many records won't have an xid assigned, centralize check here */
3020  if (xid != InvalidTransactionId)
3021  ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3022 }
#define InvalidTransactionId
Definition: transam.h:31
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)

◆ ReorderBufferQueueChange()

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

Definition at line 766 of file reorderbuffer.c.

References Assert, ReorderBufferTXN::changes, ReorderBufferTXN::concurrent_abort, dlist_push_tail(), InvalidXLogRecPtr, ReorderBufferChange::lsn, ReorderBufferTXN::nentries, ReorderBufferTXN::nentries_mem, ReorderBufferChange::node, ReorderBufferChangeMemoryUpdate(), ReorderBufferChangeSize(), ReorderBufferCheckMemoryLimit(), ReorderBufferProcessPartialChange(), ReorderBufferReturnChange(), ReorderBufferTXNByXid(), ReorderBufferChange::txn, and ReorderBufferTXNByIdEnt::txn.

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

768 {
769  ReorderBufferTXN *txn;
770 
771  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
772 
773  /*
774  * While streaming the previous changes we have detected that the
775  * transaction is aborted. So there is no point in collecting further
776  * changes for it.
777  */
778  if (txn->concurrent_abort)
779  {
780  /*
781  * We don't need to update memory accounting for this change as we
782  * have not added it to the queue yet.
783  */
784  ReorderBufferReturnChange(rb, change, false);
785  return;
786  }
787 
788  change->lsn = lsn;
789  change->txn = txn;
790 
791  Assert(InvalidXLogRecPtr != lsn);
792  dlist_push_tail(&txn->changes, &change->node);
793  txn->nentries++;
794  txn->nentries_mem++;
795 
796  /* update memory accounting information */
797  ReorderBufferChangeMemoryUpdate(rb, change, true,
798  ReorderBufferChangeSize(change));
799 
800  /* process partial change */
801  ReorderBufferProcessPartialChange(rb, txn, change, toast_insert);
802 
803  /* check the memory limits and evict something if needed */
805 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:317
dlist_head changes
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb, ReorderBufferChange *change, bool addition, Size sz)
static Size ReorderBufferChangeSize(ReorderBufferChange *change)
static void ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
static void ReorderBufferProcessPartialChange(ReorderBuffer *rb, ReorderBufferTXN *txn, ReorderBufferChange *change, bool toast_insert)
#define Assert(condition)
Definition: c.h:804
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
void ReorderBufferReturnChange(ReorderBuffer *rb, ReorderBufferChange *change, bool upd_mem)

◆ ReorderBufferQueueMessage()

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

Definition at line 812 of file reorderbuffer.c.

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(), TeardownHistoricSnapshot(), and ReorderBufferTXNByIdEnt::txn.

Referenced by DecodeLogicalMsgOp().

816 {
817  if (transactional)
818  {
819  MemoryContext oldcontext;
820  ReorderBufferChange *change;
821 
823 
824  oldcontext = MemoryContextSwitchTo(rb->context);
825 
826  change = ReorderBufferGetChange(rb);
828  change->data.msg.prefix = pstrdup(prefix);
829  change->data.msg.message_size = message_size;
830  change->data.msg.message = palloc(message_size);
831  memcpy(change->data.msg.message, message, message_size);
832 
833  ReorderBufferQueueChange(rb, xid, lsn, change, false);
834 
835  MemoryContextSwitchTo(oldcontext);
836  }
837  else
838  {
839  ReorderBufferTXN *txn = NULL;
840  volatile Snapshot snapshot_now = snapshot;
841 
842  if (xid != InvalidTransactionId)
843  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
844 
845  /* setup snapshot to allow catalog access */
846  SetupHistoricSnapshot(snapshot_now, NULL);
847  PG_TRY();
848  {
849  rb->message(rb, txn, lsn, false, prefix, message_size, message);
850 
852  }
853  PG_CATCH();
854  {
856  PG_RE_THROW();
857  }
858  PG_END_TRY();
859  }
860 }
char * pstrdup(const char *in)
Definition: mcxt.c:1299
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void TeardownHistoricSnapshot(bool is_error)
Definition: snapmgr.c:2066
ReorderBufferChange * ReorderBufferGetChange(ReorderBuffer *rb)
enum ReorderBufferChangeType action
Definition: reorderbuffer.h:85
#define InvalidTransactionId
Definition: transam.h:31
union ReorderBufferChange::@97 data
void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, ReorderBufferChange *change, bool toast_insert)
#define PG_CATCH()
Definition: elog.h:323
#define Assert(condition)
Definition: c.h:804
struct ReorderBufferChange::@97::@100 msg
#define PG_RE_THROW()
Definition: elog.h:354
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
void * palloc(Size size)
Definition: mcxt.c:1062
void SetupHistoricSnapshot(Snapshot historic_snapshot, HTAB *tuplecids)
Definition: snapmgr.c:2050
#define PG_TRY()
Definition: elog.h:313
#define PG_END_TRY()
Definition: elog.h:338

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

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

Referenced by DecodePrepare().

2658 {
2659  ReorderBufferTXN *txn;
2660 
2661  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr, false);
2662 
2663  /* unknown transaction, nothing to do */
2664  if (txn == NULL)
2665  return false;
2666 
2667  /*
2668  * Remember the prepare information to be later used by commit prepared in
2669  * case we skip doing prepare.
2670  */
2671  txn->final_lsn = prepare_lsn;
2672  txn->end_lsn = end_lsn;
2673  txn->xact_time.prepare_time = prepare_time;
2674  txn->origin_id = origin_id;
2675  txn->origin_lsn = origin_lsn;
2676 
2677  return true;
2678 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
RepOriginId origin_id
XLogRecPtr origin_lsn
XLogRecPtr final_lsn
union ReorderBufferTXN::@103 xact_time
XLogRecPtr end_lsn
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
TimestampTz prepare_time

◆ ReorderBufferReturnChange()

void ReorderBufferReturnChange ( ReorderBuffer ,
ReorderBufferChange ,
bool   
)

Definition at line 473 of file reorderbuffer.c.

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

475 {
476  /* update memory accounting info */
477  if (upd_mem)
478  ReorderBufferChangeMemoryUpdate(rb, change, false,
479  ReorderBufferChangeSize(change));
480 
481  /* free contained data */
482  switch (change->action)
483  {
488  if (change->data.tp.newtuple)
489  {
490  ReorderBufferReturnTupleBuf(rb, change->data.tp.newtuple);
491  change->data.tp.newtuple = NULL;
492  }
493 
494  if (change->data.tp.oldtuple)
495  {
496  ReorderBufferReturnTupleBuf(rb, change->data.tp.oldtuple);
497  change->data.tp.oldtuple = NULL;
498  }
499  break;
501  if (change->data.msg.prefix != NULL)
502  pfree(change->data.msg.prefix);
503  change->data.msg.prefix = NULL;
504  if (change->data.msg.message != NULL)
505  pfree(change->data.msg.message);
506  change->data.msg.message = NULL;
507  break;
509  if (change->data.inval.invalidations)
510  pfree(change->data.inval.invalidations);
511  change->data.inval.invalidations = NULL;
512  break;
514  if (change->data.snapshot)
515  {
516  ReorderBufferFreeSnap(rb, change->data.snapshot);
517  change->data.snapshot = NULL;
518  }
519  break;
520  /* no data in addition to the struct itself */
522  if (change->data.truncate.relids != NULL)
523  {
524  ReorderBufferReturnRelids(rb, change->data.truncate.relids);
525  change->data.truncate.relids = NULL;
526  }
527  break;
532  break;
533  }
534 
535  pfree(change);
536 }
void pfree(void *pointer)
Definition: mcxt.c:1169
void ReorderBufferReturnRelids(ReorderBuffer *rb, Oid *relids)
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb, ReorderBufferChange *change, bool addition, Size sz)
static Size ReorderBufferChangeSize(ReorderBufferChange *change)
void ReorderBufferReturnTupleBuf(ReorderBuffer *rb, ReorderBufferTupleBuf *tuple)
static void ReorderBufferFreeSnap(ReorderBuffer *rb, Snapshot snap)

◆ ReorderBufferReturnRelids()

void ReorderBufferReturnRelids ( ReorderBuffer ,
Oid relids 
)

Definition at line 595 of file reorderbuffer.c.

References pfree().

Referenced by ReorderBufferReturnChange().

596 {
597  pfree(relids);
598 }
void pfree(void *pointer)
Definition: mcxt.c:1169

◆ ReorderBufferReturnTupleBuf()

void ReorderBufferReturnTupleBuf ( ReorderBuffer ,
ReorderBufferTupleBuf tuple 
)

Definition at line 564 of file reorderbuffer.c.

References pfree().

Referenced by ReorderBufferReturnChange().

565 {
566  pfree(tuple);
567 }
void pfree(void *pointer)
Definition: mcxt.c:1169

◆ ReorderBufferSetBaseSnapshot()

void ReorderBufferSetBaseSnapshot ( ReorderBuffer ,
TransactionId  ,
XLogRecPtr  lsn,
struct SnapshotData snap 
)

◆ ReorderBufferSetRestartPoint()

void ReorderBufferSetRestartPoint ( ReorderBuffer ,
XLogRecPtr  ptr 
)

Definition at line 1002 of file reorderbuffer.c.

References ReorderBuffer::current_restart_decoding_lsn.

Referenced by SnapBuildRestore(), and SnapBuildSerialize().

1003 {
1004  rb->current_restart_decoding_lsn = ptr;
1005 }

◆ ReorderBufferSkipPrepare()

void ReorderBufferSkipPrepare ( ReorderBuffer rb,
TransactionId  xid 
)

Definition at line 2682 of file reorderbuffer.c.

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

Referenced by DecodePrepare().

2683 {
2684  ReorderBufferTXN *txn;
2685 
2686  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr, false);
2687 
2688  /* unknown transaction, nothing to do */
2689  if (txn == NULL)
2690  return;
2691 
2693 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define RBTXN_SKIPPED_PREPARE
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)

◆ ReorderBufferXidHasBaseSnapshot()

bool ReorderBufferXidHasBaseSnapshot ( ReorderBuffer ,
TransactionId  xid 
)

Definition at line 3309 of file reorderbuffer.c.

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

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

3310 {
3311  ReorderBufferTXN *txn;
3312 
3313  txn = ReorderBufferTXNByXid(rb, xid, false,
3314  NULL, InvalidXLogRecPtr, false);
3315 
3316  /* transaction isn't known yet, ergo no snapshot */
3317  if (txn == NULL)
3318  return false;
3319 
3320  /* a known subtxn? operate on top-level txn instead */
3321  if (rbtxn_is_known_subxact(txn))
3322  txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
3323  NULL, InvalidXLogRecPtr, false);
3324 
3325  return txn->base_snapshot != NULL;
3326 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
Snapshot base_snapshot
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
#define rbtxn_is_known_subxact(txn)
TransactionId toplevel_xid

◆ ReorderBufferXidHasCatalogChanges()

bool ReorderBufferXidHasCatalogChanges ( ReorderBuffer ,
TransactionId  xid 
)

Definition at line 3292 of file reorderbuffer.c.

References InvalidXLogRecPtr, rbtxn_has_catalog_changes, ReorderBufferTXNByXid(), and ReorderBufferTXNByIdEnt::txn.

Referenced by SnapBuildCommitTxn().

3293 {
3294  ReorderBufferTXN *txn;
3295 
3296  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
3297  false);
3298  if (txn == NULL)
3299  return false;
3300 
3301  return rbtxn_has_catalog_changes(txn);
3302 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define rbtxn_has_catalog_changes(txn)
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)

◆ ReorderBufferXidSetCatalogChanges()

void ReorderBufferXidSetCatalogChanges ( ReorderBuffer ,
TransactionId  xid,
XLogRecPtr  lsn 
)

Definition at line 3268 of file reorderbuffer.c.

References RBTXN_HAS_CATALOG_CHANGES, ReorderBufferTXNByXid(), ReorderBufferTXN::toptxn, ReorderBufferTXNByIdEnt::txn, and ReorderBufferTXN::txn_flags.

Referenced by DecodeHeapOp(), DecodeXactOp(), and SnapBuildProcessNewCid().

3270 {
3271  ReorderBufferTXN *txn;
3272 
3273  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3274 
3276 
3277  /*
3278  * Mark top-level transaction as having catalog changes too if one of its
3279  * children has so that the ReorderBufferBuildTupleCidHash can
3280  * conveniently check just top-level transaction and decide whether to
3281  * build the hash table or not.
3282  */
3283  if (txn->toptxn != NULL)
3285 }
#define RBTXN_HAS_CATALOG_CHANGES
struct ReorderBufferTXN * toptxn
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)

◆ StartupReorderBuffer()

void StartupReorderBuffer ( void  )

Definition at line 4456 of file reorderbuffer.c.

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

Referenced by StartupXLOG().

4457 {
4458  DIR *logical_dir;
4459  struct dirent *logical_de;
4460 
4461  logical_dir = AllocateDir("pg_replslot");
4462  while ((logical_de = ReadDir(logical_dir, "pg_replslot")) != NULL)
4463  {
4464  if (strcmp(logical_de->d_name, ".") == 0 ||
4465  strcmp(logical_de->d_name, "..") == 0)
4466  continue;
4467 
4468  /* if it cannot be a slot, skip the directory */
4469  if (!ReplicationSlotValidateName(logical_de->d_name, DEBUG2))
4470  continue;
4471 
4472  /*
4473  * ok, has to be a surviving logical slot, iterate and delete
4474  * everything starting with xid-*
4475  */
4477  }
4478  FreeDir(logical_dir);
4479 }
Definition: dirent.h:9
bool ReplicationSlotValidateName(const char *name, int elevel)
Definition: slot.c:172
Definition: dirent.c:25
#define DEBUG2
Definition: elog.h:24
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2720
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2786
char d_name[MAX_PATH]
Definition: dirent.h:15
static void ReorderBufferCleanupSerializedTXNs(const char *slotname)
int FreeDir(DIR *dir)
Definition: fd.c:2838

Variable Documentation

◆ logical_decoding_work_mem

PGDLLIMPORT int logical_decoding_work_mem

Definition at line 209 of file reorderbuffer.c.

Referenced by ReorderBufferCheckMemoryLimit().