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_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)
 

Typedefs

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

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 *rb)
 
ReorderBufferTupleBufReorderBufferGetTupleBuf (ReorderBuffer *rb, Size tuple_len)
 
void ReorderBufferReturnTupleBuf (ReorderBuffer *rb, ReorderBufferTupleBuf *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)
 
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
 

Macro Definition Documentation

◆ RBTXN_HAS_CATALOG_CHANGES

#define RBTXN_HAS_CATALOG_CHANGES   0x0001

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

◆ RBTXN_HAS_PARTIAL_CHANGE

#define RBTXN_HAS_PARTIAL_CHANGE   0x0020

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

◆ RBTXN_HAS_STREAMABLE_CHANGE

#define RBTXN_HAS_STREAMABLE_CHANGE   0x0100

Definition at line 179 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 212 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 188 of file reorderbuffer.h.

◆ RBTXN_IS_SERIALIZED

#define RBTXN_IS_SERIALIZED   0x0004

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

◆ RBTXN_IS_SERIALIZED_CLEAR

#define RBTXN_IS_SERIALIZED_CLEAR   0x0008

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

◆ RBTXN_IS_STREAMED

#define RBTXN_IS_STREAMED   0x0010

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

◆ RBTXN_IS_SUBXACT

#define RBTXN_IS_SUBXACT   0x0002

Definition at line 172 of file reorderbuffer.h.

◆ RBTXN_PREPARE

#define RBTXN_PREPARE   0x0040

Definition at line 177 of file reorderbuffer.h.

◆ rbtxn_prepared

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

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

◆ RBTXN_SKIPPED_PREPARE

#define RBTXN_SKIPPED_PREPARE   0x0080

Definition at line 178 of file reorderbuffer.h.

◆ ReorderBufferTupleBufData

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

Definition at line 38 of file reorderbuffer.h.

Typedef Documentation

◆ ReorderBuffer

typedef struct ReorderBuffer ReorderBuffer

Definition at line 20 of file reorderbuffer.h.

◆ ReorderBufferApplyChangeCB

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

Definition at line 416 of file reorderbuffer.h.

◆ ReorderBufferApplyTruncateCB

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

Definition at line 422 of file reorderbuffer.h.

◆ ReorderBufferBeginCB

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

Definition at line 429 of file reorderbuffer.h.

◆ ReorderBufferBeginPrepareCB

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

Definition at line 446 of file reorderbuffer.h.

◆ ReorderBufferChange

◆ ReorderBufferChangeType

◆ ReorderBufferCommitCB

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

Definition at line 433 of file reorderbuffer.h.

◆ ReorderBufferCommitPreparedCB

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

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

◆ ReorderBufferPrepareCB

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

Definition at line 450 of file reorderbuffer.h.

◆ ReorderBufferRollbackPreparedCB

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

Definition at line 460 of file reorderbuffer.h.

◆ ReorderBufferStreamAbortCB

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

Definition at line 478 of file reorderbuffer.h.

◆ ReorderBufferStreamChangeCB

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

Definition at line 496 of file reorderbuffer.h.

◆ ReorderBufferStreamCommitCB

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

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

◆ ReorderBufferStreamPrepareCB

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

Definition at line 484 of file reorderbuffer.h.

◆ ReorderBufferStreamStartCB

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

Definition at line 466 of file reorderbuffer.h.

◆ ReorderBufferStreamStopCB

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

Definition at line 472 of file reorderbuffer.h.

◆ ReorderBufferStreamTruncateCB

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

Definition at line 512 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.

55 {
ReorderBufferChangeType
Definition: reorderbuffer.h:55
@ REORDER_BUFFER_CHANGE_INVALIDATION
Definition: reorderbuffer.h:60
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM
Definition: reorderbuffer.h:65
@ REORDER_BUFFER_CHANGE_INSERT
Definition: reorderbuffer.h:56
@ REORDER_BUFFER_CHANGE_MESSAGE
Definition: reorderbuffer.h:59
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT
Definition: reorderbuffer.h:66
@ REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID
Definition: reorderbuffer.h:62
@ REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID
Definition: reorderbuffer.h:63
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT
Definition: reorderbuffer.h:64
@ REORDER_BUFFER_CHANGE_TRUNCATE
Definition: reorderbuffer.h:67
@ REORDER_BUFFER_CHANGE_DELETE
Definition: reorderbuffer.h:58
@ REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT
Definition: reorderbuffer.h:61
@ REORDER_BUFFER_CHANGE_UPDATE
Definition: reorderbuffer.h:57

Function Documentation

◆ ReorderBufferAbort()

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

Definition at line 2873 of file reorderbuffer.c.

2874 {
2875  ReorderBufferTXN *txn;
2876 
2877  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2878  false);
2879 
2880  /* unknown, nothing to remove */
2881  if (txn == NULL)
2882  return;
2883 
2884  /* For streamed transactions notify the remote node about the abort. */
2885  if (rbtxn_is_streamed(txn))
2886  {
2887  rb->stream_abort(rb, txn, lsn);
2888 
2889  /*
2890  * We might have decoded changes for this transaction that could load
2891  * the cache as per the current transaction's view (consider DDL's
2892  * happened in this transaction). We don't want the decoding of future
2893  * transactions to use those cache entries so execute invalidations.
2894  */
2895  if (txn->ninvalidations > 0)
2897  txn->invalidations);
2898  }
2899 
2900  /* cosmetic... */
2901  txn->final_lsn = lsn;
2902 
2903  /* remove potential on-disk data, and deallocate */
2904  ReorderBufferCleanupTXN(rb, txn);
2905 }
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
XLogRecPtr final_lsn
ReorderBufferStreamAbortCB stream_abort
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28

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

Referenced by DecodeAbort().

◆ ReorderBufferAbortOld()

void ReorderBufferAbortOld ( ReorderBuffer rb,
TransactionId  oldestRunningXid 
)

Definition at line 2915 of file reorderbuffer.c.

2916 {
2917  dlist_mutable_iter it;
2918 
2919  /*
2920  * Iterate through all (potential) toplevel TXNs and abort all that are
2921  * older than what possibly can be running. Once we've found the first
2922  * that is alive we stop, there might be some that acquired an xid earlier
2923  * but started writing later, but it's unlikely and they will be cleaned
2924  * up in a later call to this function.
2925  */
2927  {
2928  ReorderBufferTXN *txn;
2929 
2930  txn = dlist_container(ReorderBufferTXN, node, it.cur);
2931 
2932  if (TransactionIdPrecedes(txn->xid, oldestRunningXid))
2933  {
2934  elog(DEBUG2, "aborting old transaction %u", txn->xid);
2935 
2936  /* remove potential on-disk data, and deallocate this tx */
2937  ReorderBufferCleanupTXN(rb, txn);
2938  }
2939  else
2940  return;
2941  }
2942 }
#define DEBUG2
Definition: elog.h:29
#define dlist_foreach_modify(iter, lhead)
Definition: ilist.h:590
#define dlist_container(type, membername, ptr)
Definition: ilist.h:543
TransactionId xid
dlist_head toplevel_by_lsn
dlist_node * cur
Definition: ilist.h:200
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:273

References dlist_mutable_iter::cur, DEBUG2, dlist_container, dlist_foreach_modify, elog(), ReorderBufferCleanupTXN(), 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 3247 of file reorderbuffer.c.

3250 {
3251  ReorderBufferTXN *txn;
3252  MemoryContext oldcontext;
3253  ReorderBufferChange *change;
3254 
3255  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3256 
3257  oldcontext = MemoryContextSwitchTo(rb->context);
3258 
3259  /*
3260  * Collect all the invalidations under the top transaction, if available,
3261  * so that we can execute them all together. See comments atop this
3262  * function.
3263  */
3264  if (txn->toptxn)
3265  txn = txn->toptxn;
3266 
3267  Assert(nmsgs > 0);
3268 
3269  /* Accumulate invalidations. */
3270  if (txn->ninvalidations == 0)
3271  {
3272  txn->ninvalidations = nmsgs;
3274  palloc(sizeof(SharedInvalidationMessage) * nmsgs);
3275  memcpy(txn->invalidations, msgs,
3276  sizeof(SharedInvalidationMessage) * nmsgs);
3277  }
3278  else
3279  {
3282  (txn->ninvalidations + nmsgs));
3283 
3284  memcpy(txn->invalidations + txn->ninvalidations, msgs,
3285  nmsgs * sizeof(SharedInvalidationMessage));
3286  txn->ninvalidations += nmsgs;
3287  }
3288 
3289  change = ReorderBufferGetChange(rb);
3291  change->data.inval.ninvalidations = nmsgs;
3292  change->data.inval.invalidations = (SharedInvalidationMessage *)
3293  palloc(sizeof(SharedInvalidationMessage) * nmsgs);
3294  memcpy(change->data.inval.invalidations, msgs,
3295  sizeof(SharedInvalidationMessage) * nmsgs);
3296 
3297  ReorderBufferQueueChange(rb, xid, lsn, change, false);
3298 
3299  MemoryContextSwitchTo(oldcontext);
3300 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1321
void * palloc(Size size)
Definition: mcxt.c:1199
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:135
void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, ReorderBufferChange *change, bool toast_insert)
ReorderBufferChange * ReorderBufferGetChange(ReorderBuffer *rb)
ReorderBufferChangeType action
Definition: reorderbuffer.h:85
union ReorderBufferChange::@97 data
struct ReorderBufferChange::@97::@102 inval
struct ReorderBufferTXN * toptxn
MemoryContext context

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

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

3214 {
3216  ReorderBufferTXN *txn;
3217 
3218  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3219 
3220  change->data.tuplecid.locator = locator;
3221  change->data.tuplecid.tid = tid;
3222  change->data.tuplecid.cmin = cmin;
3223  change->data.tuplecid.cmax = cmax;
3224  change->data.tuplecid.combocid = combocid;
3225  change->lsn = lsn;
3226  change->txn = txn;
3228 
3229  dlist_push_tail(&txn->tuplecids, &change->node);
3230  txn->ntuplecids++;
3231 }
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:353
struct ReorderBufferTXN * txn
Definition: reorderbuffer.h:88
struct ReorderBufferChange::@97::@101 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 301 of file reorderbuffer.c.

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  /*
332  * XXX the allocation sizes used below pre-date generation context's block
333  * growing code. These values should likely be benchmarked and set to
334  * more suitable values.
335  */
336  buffer->tup_context = GenerationContextCreate(new_ctx,
337  "Tuples",
341 
342  hash_ctl.keysize = sizeof(TransactionId);
343  hash_ctl.entrysize = sizeof(ReorderBufferTXNByIdEnt);
344  hash_ctl.hcxt = buffer->context;
345 
346  buffer->by_txn = hash_create("ReorderBufferByXid", 1000, &hash_ctl,
348 
350  buffer->by_txn_last_txn = NULL;
351 
352  buffer->outbuf = NULL;
353  buffer->outbufsize = 0;
354  buffer->size = 0;
355 
356  buffer->spillTxns = 0;
357  buffer->spillCount = 0;
358  buffer->spillBytes = 0;
359  buffer->streamTxns = 0;
360  buffer->streamCount = 0;
361  buffer->streamBytes = 0;
362  buffer->totalTxns = 0;
363  buffer->totalBytes = 0;
364 
366 
367  dlist_init(&buffer->toplevel_by_lsn);
369  dclist_init(&buffer->catchange_txns);
370 
371  /*
372  * Ensure there's no stale data from prior uses of this slot, in case some
373  * prior exit avoided calling ReorderBufferFree. Failure to do this can
374  * produce duplicated txns, and it's very cheap if there's nothing there.
375  */
377 
378  return buffer;
379 }
#define NameStr(name)
Definition: c.h:682
uint32 TransactionId
Definition: c.h:588
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:350
MemoryContext GenerationContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: generation.c:158
#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:621
MemoryContext CurrentMemoryContext
Definition: mcxt.c:124
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:994
#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:141
ReplicationSlot * MyReplicationSlot
Definition: slot.c:98
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:147
#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:394
static void AssertTXNLsnOrder(ReorderBuffer *rb)
static void ReorderBufferTransferSnapToParent(ReorderBufferTXN *txn, ReorderBufferTXN *subtxn)
#define rbtxn_is_known_subxact(txn)
TransactionId toplevel_xid
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 2682 of file reorderbuffer.c.

2686 {
2687  ReorderBufferTXN *txn;
2688 
2689  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2690  false);
2691 
2692  /* unknown transaction, nothing to replay */
2693  if (txn == NULL)
2694  return;
2695 
2696  ReorderBufferReplay(txn, rb, xid, commit_lsn, end_lsn, commit_time,
2697  origin_id, origin_lsn);
2698 }
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 2788 of file reorderbuffer.c.

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

2959 {
2960  ReorderBufferTXN *txn;
2961 
2962  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2963  false);
2964 
2965  /* unknown, nothing to forget */
2966  if (txn == NULL)
2967  return;
2968 
2969  /* this transaction mustn't be streamed */
2970  Assert(!rbtxn_is_streamed(txn));
2971 
2972  /* cosmetic... */
2973  txn->final_lsn = lsn;
2974 
2975  /*
2976  * Process cache invalidation messages if there are any. Even if we're not
2977  * interested in the transaction's contents, it could have manipulated the
2978  * catalog and we need to update the caches according to that.
2979  */
2980  if (txn->base_snapshot != NULL && txn->ninvalidations > 0)
2982  txn->invalidations);
2983  else
2984  Assert(txn->ninvalidations == 0);
2985 
2986  /* remove potential on-disk data, and deallocate */
2987  ReorderBufferCleanupTXN(rb, txn);
2988 }
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 385 of file reorderbuffer.c.

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

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

Referenced by FreeDecodingContext().

◆ ReorderBufferGetCatalogChangesXacts()

TransactionId* ReorderBufferGetCatalogChangesXacts ( ReorderBuffer rb)

Definition at line 3354 of file reorderbuffer.c.

3355 {
3356  dlist_iter iter;
3357  TransactionId *xids = NULL;
3358  size_t xcnt = 0;
3359 
3360  /* Quick return if the list is empty */
3361  if (dclist_count(&rb->catchange_txns) == 0)
3362  return NULL;
3363 
3364  /* Initialize XID array */
3365  xids = (TransactionId *) palloc(sizeof(TransactionId) *
3367  dclist_foreach(iter, &rb->catchange_txns)
3368  {
3370  catchange_node,
3371  iter.cur);
3372 
3374 
3375  xids[xcnt++] = txn->xid;
3376  }
3377 
3378  qsort(xids, xcnt, sizeof(TransactionId), xidComparator);
3379 
3380  Assert(xcnt == dclist_count(&rb->catchange_txns));
3381  return xids;
3382 }
#define dclist_container(type, membername, ptr)
Definition: ilist.h:884
static uint32 dclist_count(dclist_head *head)
Definition: ilist.h:869
#define dclist_foreach(iter, lhead)
Definition: ilist.h:907
#define qsort(a, b, c, d)
Definition: port.h:445
#define rbtxn_has_catalog_changes(txn)
dlist_node * cur
Definition: ilist.h:179
int xidComparator(const void *arg1, const void *arg2)
Definition: xid.c:136

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:553
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:325
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 587 of file reorderbuffer.c.

588 {
589  Oid *relids;
590  Size alloc_len;
591 
592  alloc_len = sizeof(Oid) * nrelids;
593 
594  relids = (Oid *) MemoryContextAlloc(rb->context, alloc_len);
595 
596  return relids;
597 }
size_t Size
Definition: c.h:541
unsigned int Oid
Definition: postgres_ext.h:31

References ReorderBuffer::context, and MemoryContextAlloc().

Referenced by DecodeTruncate(), and ReorderBufferRestoreChange().

◆ ReorderBufferGetTupleBuf()

ReorderBufferTupleBuf* ReorderBufferGetTupleBuf ( ReorderBuffer rb,
Size  tuple_len 
)

Definition at line 551 of file reorderbuffer.c.

552 {
553  ReorderBufferTupleBuf *tuple;
554  Size alloc_len;
555 
556  alloc_len = tuple_len + SizeofHeapTupleHeader;
557 
558  tuple = (ReorderBufferTupleBuf *)
560  sizeof(ReorderBufferTupleBuf) +
561  MAXIMUM_ALIGNOF + alloc_len);
562  tuple->alloc_tuple_size = alloc_len;
563  tuple->tuple.t_data = ReorderBufferTupleBufData(tuple);
564 
565  return tuple;
566 }
#define SizeofHeapTupleHeader
Definition: htup_details.h:184
#define ReorderBufferTupleBufData(p)
Definition: reorderbuffer.h:38
HeapTupleHeader t_data
Definition: htup.h:68
HeapTupleData tuple
Definition: reorderbuffer.h:29

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

◆ ReorderBufferImmediateInvalidation()

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

Definition at line 3030 of file reorderbuffer.c.

3032 {
3033  bool use_subtxn = IsTransactionOrTransactionBlock();
3034  int i;
3035 
3036  if (use_subtxn)
3037  BeginInternalSubTransaction("replay");
3038 
3039  /*
3040  * Force invalidations to happen outside of a valid transaction - that way
3041  * entries will just be marked as invalid without accessing the catalog.
3042  * That's advantageous because we don't need to setup the full state
3043  * necessary for catalog access.
3044  */
3045  if (use_subtxn)
3047 
3048  for (i = 0; i < ninvalidations; i++)
3049  LocalExecuteInvalidationMessage(&invalidations[i]);
3050 
3051  if (use_subtxn)
3053 }
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
Definition: inval.c:615
int i
Definition: isn.c:73
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4814
void BeginInternalSubTransaction(const char *name)
Definition: xact.c:4520
void RollbackAndReleaseCurrentSubTransaction(void)
Definition: xact.c:4625
void AbortCurrentTransaction(void)
Definition: xact.c:3293

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

3000 {
3001  ReorderBufferTXN *txn;
3002 
3003  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
3004  false);
3005 
3006  /* unknown, nothing to do */
3007  if (txn == NULL)
3008  return;
3009 
3010  /*
3011  * Process cache invalidation messages if there are any. Even if we're not
3012  * interested in the transaction's contents, it could have manipulated the
3013  * catalog and we need to update the caches according to that.
3014  */
3015  if (txn->base_snapshot != NULL && txn->ninvalidations > 0)
3017  txn->invalidations);
3018  else
3019  Assert(txn->ninvalidations == 0);
3020 }

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

2753 {
2754  ReorderBufferTXN *txn;
2755 
2756  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2757  false);
2758 
2759  /* unknown transaction, nothing to replay */
2760  if (txn == NULL)
2761  return;
2762 
2763  txn->txn_flags |= RBTXN_PREPARE;
2764  txn->gid = pstrdup(gid);
2765 
2766  /* The prepare info must have been updated in txn by now. */
2768 
2769  ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
2770  txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn);
2771 
2772  /*
2773  * We send the prepare for the concurrently aborted xacts so that later
2774  * when rollback prepared is decoded and sent, the downstream should be
2775  * able to rollback such a xact. See comments atop DecodePrepare.
2776  *
2777  * Note, for the concurrent_abort + streaming case a stream_prepare was
2778  * already sent within the ReorderBufferReplay call above.
2779  */
2780  if (txn->concurrent_abort && !rbtxn_is_streamed(txn))
2781  rb->prepare(rb, txn, txn->final_lsn);
2782 }
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 3066 of file reorderbuffer.c.

3067 {
3068  /* many records won't have an xid assigned, centralize check here */
3069  if (xid != InvalidTransactionId)
3070  ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3071 }

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

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

848 {
849  if (transactional)
850  {
851  MemoryContext oldcontext;
852  ReorderBufferChange *change;
853 
855 
856  oldcontext = MemoryContextSwitchTo(rb->context);
857 
858  change = ReorderBufferGetChange(rb);
860  change->data.msg.prefix = pstrdup(prefix);
861  change->data.msg.message_size = message_size;
862  change->data.msg.message = palloc(message_size);
863  memcpy(change->data.msg.message, message, message_size);
864 
865  ReorderBufferQueueChange(rb, xid, lsn, change, false);
866 
867  MemoryContextSwitchTo(oldcontext);
868  }
869  else
870  {
871  ReorderBufferTXN *txn = NULL;
872  volatile Snapshot snapshot_now = snap;
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:2096
void SetupHistoricSnapshot(Snapshot historic_snapshot, HTAB *tuplecids)
Definition: snapmgr.c:2080
struct ReorderBufferChange::@97::@100 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 2704 of file reorderbuffer.c.

2708 {
2709  ReorderBufferTXN *txn;
2710 
2711  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr, false);
2712 
2713  /* unknown transaction, nothing to do */
2714  if (txn == NULL)
2715  return false;
2716 
2717  /*
2718  * Remember the prepare information to be later used by commit prepared in
2719  * case we skip doing prepare.
2720  */
2721  txn->final_lsn = prepare_lsn;
2722  txn->end_lsn = end_lsn;
2723  txn->xact_time.prepare_time = prepare_time;
2724  txn->origin_id = origin_id;
2725  txn->origin_lsn = origin_lsn;
2726 
2727  return true;
2728 }

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

483 {
484  /* update memory accounting info */
485  if (upd_mem)
486  ReorderBufferChangeMemoryUpdate(rb, change, false,
487  ReorderBufferChangeSize(change));
488 
489  /* free contained data */
490  switch (change->action)
491  {
496  if (change->data.tp.newtuple)
497  {
498  ReorderBufferReturnTupleBuf(rb, change->data.tp.newtuple);
499  change->data.tp.newtuple = NULL;
500  }
501 
502  if (change->data.tp.oldtuple)
503  {
504  ReorderBufferReturnTupleBuf(rb, change->data.tp.oldtuple);
505  change->data.tp.oldtuple = NULL;
506  }
507  break;
509  if (change->data.msg.prefix != NULL)
510  pfree(change->data.msg.prefix);
511  change->data.msg.prefix = NULL;
512  if (change->data.msg.message != NULL)
513  pfree(change->data.msg.message);
514  change->data.msg.message = NULL;
515  break;
517  if (change->data.inval.invalidations)
518  pfree(change->data.inval.invalidations);
519  change->data.inval.invalidations = NULL;
520  break;
522  if (change->data.snapshot)
523  {
524  ReorderBufferFreeSnap(rb, change->data.snapshot);
525  change->data.snapshot = NULL;
526  }
527  break;
528  /* no data in addition to the struct itself */
530  if (change->data.truncate.relids != NULL)
531  {
532  ReorderBufferReturnRelids(rb, change->data.truncate.relids);
533  change->data.truncate.relids = NULL;
534  }
535  break;
540  break;
541  }
542 
543  pfree(change);
544 }
void pfree(void *pointer)
Definition: mcxt.c:1306
void ReorderBufferReturnTupleBuf(ReorderBuffer *rb, ReorderBufferTupleBuf *tuple)
static void ReorderBufferFreeSnap(ReorderBuffer *rb, Snapshot snap)
void ReorderBufferReturnRelids(ReorderBuffer *rb, Oid *relids)
struct ReorderBufferChange::@97::@99 truncate
struct ReorderBufferChange::@97::@98 tp

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

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

◆ ReorderBufferReturnRelids()

void ReorderBufferReturnRelids ( ReorderBuffer rb,
Oid relids 
)

Definition at line 603 of file reorderbuffer.c.

604 {
605  pfree(relids);
606 }

References pfree().

Referenced by ReorderBufferReturnChange().

◆ ReorderBufferReturnTupleBuf()

void ReorderBufferReturnTupleBuf ( ReorderBuffer rb,
ReorderBufferTupleBuf tuple 
)

Definition at line 572 of file reorderbuffer.c.

573 {
574  pfree(tuple);
575 }

References pfree().

Referenced by ReorderBufferReturnChange().

◆ ReorderBufferSetBaseSnapshot()

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

Definition at line 3097 of file reorderbuffer.c.

3099 {
3100  ReorderBufferTXN *txn;
3101  bool is_new;
3102 
3103  Assert(snap != NULL);
3104 
3105  /*
3106  * Fetch the transaction to operate on. If we know it's a subtransaction,
3107  * operate on its top-level transaction instead.
3108  */
3109  txn = ReorderBufferTXNByXid(rb, xid, true, &is_new, lsn, true);
3110  if (rbtxn_is_known_subxact(txn))
3111  txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
3112  NULL, InvalidXLogRecPtr, false);
3113  Assert(txn->base_snapshot == NULL);
3114 
3115  txn->base_snapshot = snap;
3116  txn->base_snapshot_lsn = lsn;
3118 
3119  AssertTXNLsnOrder(rb);
3120 }
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 2732 of file reorderbuffer.c.

2733 {
2734  ReorderBufferTXN *txn;
2735 
2736  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr, false);
2737 
2738  /* unknown transaction, nothing to do */
2739  if (txn == NULL)
2740  return;
2741 
2743 }

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

Referenced by DecodePrepare().

◆ ReorderBufferXidHasBaseSnapshot()

bool ReorderBufferXidHasBaseSnapshot ( ReorderBuffer rb,
TransactionId  xid 
)

Definition at line 3406 of file reorderbuffer.c.

3407 {
3408  ReorderBufferTXN *txn;
3409 
3410  txn = ReorderBufferTXNByXid(rb, xid, false,
3411  NULL, InvalidXLogRecPtr, false);
3412 
3413  /* transaction isn't known yet, ergo no snapshot */
3414  if (txn == NULL)
3415  return false;
3416 
3417  /* a known subtxn? operate on top-level txn instead */
3418  if (rbtxn_is_known_subxact(txn))
3419  txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
3420  NULL, InvalidXLogRecPtr, false);
3421 
3422  return txn->base_snapshot != NULL;
3423 }

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

3390 {
3391  ReorderBufferTXN *txn;
3392 
3393  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
3394  false);
3395  if (txn == NULL)
3396  return false;
3397 
3398  return rbtxn_has_catalog_changes(txn);
3399 }

References InvalidXLogRecPtr, rbtxn_has_catalog_changes, and ReorderBufferTXNByXid().

Referenced by SnapBuildXidHasCatalogChanges().

◆ ReorderBufferXidSetCatalogChanges()

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

Definition at line 3319 of file reorderbuffer.c.

3321 {
3322  ReorderBufferTXN *txn;
3323  ReorderBufferTXN *toptxn;
3324 
3325  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
3326 
3327  if (!rbtxn_has_catalog_changes(txn))
3328  {
3331  }
3332 
3333  /*
3334  * Mark top-level transaction as having catalog changes too if one of its
3335  * children has so that the ReorderBufferBuildTupleCidHash can
3336  * conveniently check just top-level transaction and decide whether to
3337  * build the hash table or not.
3338  */
3339  toptxn = txn->toptxn;
3340  if (toptxn != NULL && !rbtxn_has_catalog_changes(toptxn))
3341  {
3344  }
3345 }
static void dclist_push_tail(dclist_head *head, dlist_node *node)
Definition: ilist.h:659
dlist_node catchange_node

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

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

◆ StartupReorderBuffer()

void StartupReorderBuffer ( void  )

Definition at line 4557 of file reorderbuffer.c.

4558 {
4559  DIR *logical_dir;
4560  struct dirent *logical_de;
4561 
4562  logical_dir = AllocateDir("pg_replslot");
4563  while ((logical_de = ReadDir(logical_dir, "pg_replslot")) != NULL)
4564  {
4565  if (strcmp(logical_de->d_name, ".") == 0 ||
4566  strcmp(logical_de->d_name, "..") == 0)
4567  continue;
4568 
4569  /* if it cannot be a slot, skip the directory */
4570  if (!ReplicationSlotValidateName(logical_de->d_name, DEBUG2))
4571  continue;
4572 
4573  /*
4574  * ok, has to be a surviving logical slot, iterate and delete
4575  * everything starting with xid-*
4576  */
4578  }
4579  FreeDir(logical_dir);
4580 }
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2709
int FreeDir(DIR *dir)
Definition: fd.c:2761
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2643
bool ReplicationSlotValidateName(const char *name, int elevel)
Definition: slot.c:198
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

◆ logical_decoding_work_mem

PGDLLIMPORT int logical_decoding_work_mem
extern

Definition at line 209 of file reorderbuffer.c.

Referenced by ReorderBufferCheckMemoryLimit().