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

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)
 

Enumerations

enum  ReorderBufferChangeType {
  REORDER_BUFFER_CHANGE_INSERT, REORDER_BUFFER_CHANGE_UPDATE, REORDER_BUFFER_CHANGE_DELETE, REORDER_BUFFER_CHANGE_MESSAGE,
  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_TRUNCATE
}
 

Functions

ReorderBufferReorderBufferAllocate (void)
 
void ReorderBufferFree (ReorderBuffer *)
 
ReorderBufferTupleBufReorderBufferGetTupleBuf (ReorderBuffer *, Size tuple_len)
 
void ReorderBufferReturnTupleBuf (ReorderBuffer *, ReorderBufferTupleBuf *tuple)
 
ReorderBufferChangeReorderBufferGetChange (ReorderBuffer *)
 
void ReorderBufferReturnChange (ReorderBuffer *, ReorderBufferChange *)
 
OidReorderBufferGetRelids (ReorderBuffer *, int nrelids)
 
void ReorderBufferReturnRelids (ReorderBuffer *, Oid *relids)
 
void ReorderBufferQueueChange (ReorderBuffer *, TransactionId, XLogRecPtr lsn, ReorderBufferChange *)
 
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 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 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)
 
ReorderBufferTXNReorderBufferGetOldestTXN (ReorderBuffer *)
 
TransactionId ReorderBufferGetOldestXmin (ReorderBuffer *rb)
 
void ReorderBufferSetRestartPoint (ReorderBuffer *, XLogRecPtr ptr)
 
void StartupReorderBuffer (void)
 

Variables

PGDLLIMPORT int logical_decoding_work_mem
 

Macro Definition Documentation

◆ ReorderBufferTupleBufData

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

Typedef Documentation

◆ ReorderBuffer

typedef struct ReorderBuffer ReorderBuffer

Definition at line 305 of file reorderbuffer.h.

◆ ReorderBufferApplyChangeCB

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

Definition at line 308 of file reorderbuffer.h.

◆ ReorderBufferApplyTruncateCB

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

Definition at line 314 of file reorderbuffer.h.

◆ ReorderBufferBeginCB

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

Definition at line 321 of file reorderbuffer.h.

◆ ReorderBufferChange

◆ ReorderBufferCommitCB

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

Definition at line 325 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 330 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_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_TRUNCATE 

Definition at line 54 of file reorderbuffer.h.

Function Documentation

◆ ReorderBufferAbort()

void ReorderBufferAbort ( ReorderBuffer ,
TransactionId  ,
XLogRecPtr  lsn 
)

Definition at line 1914 of file reorderbuffer.c.

References ReorderBufferTXN::final_lsn, InvalidXLogRecPtr, ReorderBufferCleanupTXN(), ReorderBufferTXNByXid(), and ReorderBufferTXNByIdEnt::txn.

Referenced by DecodeAbort().

1915 {
1916  ReorderBufferTXN *txn;
1917 
1918  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
1919  false);
1920 
1921  /* unknown, nothing to remove */
1922  if (txn == NULL)
1923  return;
1924 
1925  /* cosmetic... */
1926  txn->final_lsn = lsn;
1927 
1928  /* remove potential on-disk data, and deallocate */
1929  ReorderBufferCleanupTXN(rb, txn);
1930 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
XLogRecPtr final_lsn
static void ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
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 1940 of file reorderbuffer.c.

References ReorderBufferTXN::changes, dlist_mutable_iter::cur, DEBUG2, dlist_container, dlist_foreach_modify, dlist_tail_element, elog, ReorderBufferTXN::final_lsn, ReorderBufferChange::lsn, ReorderBufferCleanupTXN(), ReorderBufferTXN::serialized, ReorderBuffer::toplevel_by_lsn, TransactionIdPrecedes(), ReorderBufferTXNByIdEnt::txn, and ReorderBufferTXN::xid.

Referenced by DecodeStandbyOp().

1941 {
1942  dlist_mutable_iter it;
1943 
1944  /*
1945  * Iterate through all (potential) toplevel TXNs and abort all that are
1946  * older than what possibly can be running. Once we've found the first
1947  * that is alive we stop, there might be some that acquired an xid earlier
1948  * but started writing later, but it's unlikely and they will be cleaned
1949  * up in a later call to this function.
1950  */
1951  dlist_foreach_modify(it, &rb->toplevel_by_lsn)
1952  {
1953  ReorderBufferTXN *txn;
1954 
1955  txn = dlist_container(ReorderBufferTXN, node, it.cur);
1956 
1957  if (TransactionIdPrecedes(txn->xid, oldestRunningXid))
1958  {
1959  /*
1960  * We set final_lsn on a transaction when we decode its commit or
1961  * abort record, but we never see those records for crashed
1962  * transactions. To ensure cleanup of these transactions, set
1963  * final_lsn to that of their last change; this causes
1964  * ReorderBufferRestoreCleanup to do the right thing.
1965  */
1966  if (txn->serialized && txn->final_lsn == 0)
1967  {
1968  ReorderBufferChange *last =
1970 
1971  txn->final_lsn = last->lsn;
1972  }
1973 
1974  elog(DEBUG2, "aborting old transaction %u", txn->xid);
1975 
1976  /* remove potential on-disk data, and deallocate this tx */
1977  ReorderBufferCleanupTXN(rb, txn);
1978  }
1979  else
1980  return;
1981  }
1982 }
dlist_node * cur
Definition: ilist.h:180
#define dlist_foreach_modify(iter, lhead)
Definition: ilist.h:524
#define dlist_container(type, membername, ptr)
Definition: ilist.h:477
#define dlist_tail_element(type, membername, lhead)
Definition: ilist.h:496
dlist_head changes
#define DEBUG2
Definition: elog.h:24
XLogRecPtr final_lsn
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:228

◆ ReorderBufferAddInvalidations()

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

Definition at line 2216 of file reorderbuffer.c.

References Assert, ReorderBuffer::context, elog, ERROR, ReorderBufferTXN::invalidations, MemoryContextAlloc(), ReorderBufferTXN::ninvalidations, ReorderBufferTXNByXid(), and ReorderBufferTXNByIdEnt::txn.

Referenced by DecodeCommit().

2219 {
2220  ReorderBufferTXN *txn;
2221 
2222  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
2223 
2224  if (txn->ninvalidations != 0)
2225  elog(ERROR, "only ever add one set of invalidations");
2226 
2227  Assert(nmsgs > 0);
2228 
2229  txn->ninvalidations = nmsgs;
2231  MemoryContextAlloc(rb->context,
2232  sizeof(SharedInvalidationMessage) * nmsgs);
2233  memcpy(txn->invalidations, msgs,
2234  sizeof(SharedInvalidationMessage) * nmsgs);
2235 }
#define ERROR
Definition: elog.h:43
#define Assert(condition)
Definition: c.h:739
SharedInvalidationMessage * invalidations
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796
#define elog(elevel,...)
Definition: elog.h:228

◆ ReorderBufferAddNewCommandId()

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

Definition at line 2132 of file reorderbuffer.c.

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

Referenced by SnapBuildProcessNewCid().

2134 {
2136 
2137  change->data.command_id = cid;
2139 
2140  ReorderBufferQueueChange(rb, xid, lsn, change);
2141 }
ReorderBufferChange * ReorderBufferGetChange(ReorderBuffer *rb)
enum ReorderBufferChangeType action
Definition: reorderbuffer.h:83
union ReorderBufferChange::@101 data
void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, ReorderBufferChange *change)

◆ ReorderBufferAddNewTupleCids()

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

Definition at line 2187 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().

2191 {
2193  ReorderBufferTXN *txn;
2194 
2195  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
2196 
2197  change->data.tuplecid.node = node;
2198  change->data.tuplecid.tid = tid;
2199  change->data.tuplecid.cmin = cmin;
2200  change->data.tuplecid.cmax = cmax;
2201  change->data.tuplecid.combocid = combocid;
2202  change->lsn = lsn;
2203  change->txn = txn;
2205 
2206  dlist_push_tail(&txn->tuplecids, &change->node);
2207  txn->ntuplecids++;
2208 }
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:317
struct ReorderBufferTXN * txn
Definition: reorderbuffer.h:86
struct ReorderBufferChange::@101::@105 tuplecid
ReorderBufferChange * ReorderBufferGetChange(ReorderBuffer *rb)
enum ReorderBufferChangeType action
Definition: reorderbuffer.h:83
union ReorderBufferChange::@101 data
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 263 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::toplevel_by_lsn, ReorderBuffer::tup_context, ReorderBuffer::txn_context, and ReorderBuffer::txns_by_base_snapshot_lsn.

Referenced by StartupDecodingContext().

264 {
265  ReorderBuffer *buffer;
266  HASHCTL hash_ctl;
267  MemoryContext new_ctx;
268 
269  Assert(MyReplicationSlot != NULL);
270 
271  /* allocate memory in own context, to have better accountability */
273  "ReorderBuffer",
275 
276  buffer =
277  (ReorderBuffer *) MemoryContextAlloc(new_ctx, sizeof(ReorderBuffer));
278 
279  memset(&hash_ctl, 0, sizeof(hash_ctl));
280 
281  buffer->context = new_ctx;
282 
283  buffer->change_context = SlabContextCreate(new_ctx,
284  "Change",
286  sizeof(ReorderBufferChange));
287 
288  buffer->txn_context = SlabContextCreate(new_ctx,
289  "TXN",
291  sizeof(ReorderBufferTXN));
292 
293  buffer->tup_context = GenerationContextCreate(new_ctx,
294  "Tuples",
296 
297  hash_ctl.keysize = sizeof(TransactionId);
298  hash_ctl.entrysize = sizeof(ReorderBufferTXNByIdEnt);
299  hash_ctl.hcxt = buffer->context;
300 
301  buffer->by_txn = hash_create("ReorderBufferByXid", 1000, &hash_ctl,
303 
305  buffer->by_txn_last_txn = NULL;
306 
307  buffer->outbuf = NULL;
308  buffer->outbufsize = 0;
309  buffer->size = 0;
310 
311  buffer->spillCount = 0;
312  buffer->spillTxns = 0;
313  buffer->spillBytes = 0;
314 
316 
317  dlist_init(&buffer->toplevel_by_lsn);
319 
320  /*
321  * Ensure there's no stale data from prior uses of this slot, in case some
322  * prior exit avoided calling ReorderBufferFree. Failure to do this can
323  * produce duplicated txns, and it's very cheap if there's nothing there.
324  */
326 
327  return buffer;
328 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define AllocSetContextCreate
Definition: memutils.h:170
#define HASH_CONTEXT
Definition: hsearch.h:93
#define HASH_ELEM
Definition: hsearch.h:87
uint32 TransactionId
Definition: c.h:514
MemoryContext hcxt
Definition: hsearch.h:78
TransactionId by_txn_last_xid
XLogRecPtr current_restart_decoding_lsn
Size entrysize
Definition: hsearch.h:73
MemoryContext SlabContextCreate(MemoryContext parent, const char *name, Size blockSize, Size chunkSize)
Definition: slab.c:187
ReplicationSlotPersistentData data
Definition: slot.h:132
MemoryContext change_context
#define SLAB_LARGE_BLOCK_SIZE
Definition: memutils.h:222
dlist_head txns_by_base_snapshot_lsn
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
#define InvalidTransactionId
Definition: transam.h:31
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define HASH_BLOBS
Definition: hsearch.h:88
MemoryContext GenerationContextCreate(MemoryContext parent, const char *name, Size blockSize)
Definition: generation.c:212
MemoryContext context
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:316
ReorderBufferTXN * by_txn_last_txn
dlist_head toplevel_by_lsn
Size keysize
Definition: hsearch.h:72
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
#define Assert(condition)
Definition: c.h:739
#define SLAB_DEFAULT_BLOCK_SIZE
Definition: memutils.h:221
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796
#define NameStr(name)
Definition: c.h:616
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 821 of file reorderbuffer.c.

References Assert, AssertTXNLsnOrder(), dlist_delete(), dlist_push_tail(), elog, ERROR, ReorderBufferTXN::is_known_as_subxact, ReorderBufferTXN::node, ReorderBufferTXN::nsubtxns, ReorderBufferTransferSnapToParent(), ReorderBufferTXNByXid(), ReorderBufferTXN::subtxns, ReorderBufferTXN::toplevel_xid, ReorderBufferTXNByIdEnt::txn, and ReorderBufferTXNByIdEnt::xid.

Referenced by DecodeXactOp(), and ReorderBufferCommitChild().

823 {
824  ReorderBufferTXN *txn;
825  ReorderBufferTXN *subtxn;
826  bool new_top;
827  bool new_sub;
828 
829  txn = ReorderBufferTXNByXid(rb, xid, true, &new_top, lsn, true);
830  subtxn = ReorderBufferTXNByXid(rb, subxid, true, &new_sub, lsn, false);
831 
832  if (new_top && !new_sub)
833  elog(ERROR, "subtransaction logged without previous top-level txn record");
834 
835  if (!new_sub)
836  {
837  if (subtxn->is_known_as_subxact)
838  {
839  /* already associated, nothing to do */
840  return;
841  }
842  else
843  {
844  /*
845  * We already saw this transaction, but initially added it to the
846  * list of top-level txns. Now that we know it's not top-level,
847  * remove it from there.
848  */
849  dlist_delete(&subtxn->node);
850  }
851  }
852 
853  subtxn->is_known_as_subxact = true;
854  subtxn->toplevel_xid = xid;
855  Assert(subtxn->nsubtxns == 0);
856 
857  /* add to subtransaction list */
858  dlist_push_tail(&txn->subtxns, &subtxn->node);
859  txn->nsubtxns++;
860 
861  /* Possibly transfer the subtxn's snapshot to its top-level txn. */
863 
864  /* Verify LSN-ordering invariant */
865  AssertTXNLsnOrder(rb);
866 }
static void ReorderBufferTransferSnapToParent(ReorderBufferTXN *txn, ReorderBufferTXN *subtxn)
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:317
#define ERROR
Definition: elog.h:43
static void dlist_delete(dlist_node *node)
Definition: ilist.h:358
static void AssertTXNLsnOrder(ReorderBuffer *rb)
#define Assert(condition)
Definition: c.h:739
dlist_head subtxns
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
#define elog(elevel,...)
Definition: elog.h:228
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 1492 of file reorderbuffer.c.

References AbortCurrentTransaction(), ReorderBufferChange::action, ReorderBuffer::apply_change, ReorderBuffer::apply_truncate, Assert, ReorderBufferTXN::base_snapshot, ReorderBuffer::begin, BeginInternalSubTransaction(), ReorderBufferChange::command_id, ReorderBuffer::commit, ReorderBufferTXN::commit_time, SnapshotData::copied, SnapshotData::curcid, ReorderBufferChange::data, dlist_delete(), elog, ReorderBufferTXN::end_lsn, ERROR, ReorderBufferTXN::final_lsn, FirstCommandId, GetCurrentTransactionId(), GetCurrentTransactionIdIfAny(), i, InvalidCommandId, InvalidOid, InvalidTransactionId, InvalidXLogRecPtr, IsToastRelation(), IsTransactionOrTransactionBlock(), ReorderBufferChange::lsn, MAIN_FORKNUM, ReorderBuffer::message, ReorderBufferChange::msg, ReorderBufferTXN::ninvalidations, ReorderBufferChange::node, ReorderBufferTXN::origin_id, ReorderBufferTXN::origin_lsn, ReorderBuffer::output_rewrites, palloc0(), PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, RelationData::rd_rel, RelationClose(), RelationIdGetRelation(), RelationIsLogicallyLogged, RelationIsValid, RelidByRelfilenode(), relpathperm, REORDER_BUFFER_CHANGE_DELETE, REORDER_BUFFER_CHANGE_INSERT, REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID, REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT, REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM, REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT, REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID, REORDER_BUFFER_CHANGE_MESSAGE, REORDER_BUFFER_CHANGE_TRUNCATE, REORDER_BUFFER_CHANGE_UPDATE, ReorderBufferBuildTupleCidHash(), ReorderBufferCleanupTXN(), ReorderBufferCopySnap(), ReorderBufferExecuteInvalidations(), ReorderBufferFreeSnap(), ReorderBufferIterTXNFinish(), ReorderBufferIterTXNInit(), ReorderBufferIterTXNNext(), ReorderBufferReturnChange(), ReorderBufferToastAppendChunk(), ReorderBufferToastReplace(), ReorderBufferToastReset(), ReorderBufferTXNByXid(), RollbackAndReleaseCurrentSubTransaction(), SetupHistoricSnapshot(), ReorderBufferChange::snapshot, StartTransactionCommand(), TeardownHistoricSnapshot(), ReorderBufferChange::tp, ReorderBufferChange::truncate, ReorderBufferTXN::tuplecid_hash, and ReorderBufferTXNByIdEnt::txn.

Referenced by DecodeCommit().

1496 {
1497  ReorderBufferTXN *txn;
1498  volatile Snapshot snapshot_now;
1499  volatile CommandId command_id = FirstCommandId;
1500  bool using_subtxn;
1501  ReorderBufferIterTXNState *volatile iterstate = NULL;
1502 
1503  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
1504  false);
1505 
1506  /* unknown transaction, nothing to replay */
1507  if (txn == NULL)
1508  return;
1509 
1510  txn->final_lsn = commit_lsn;
1511  txn->end_lsn = end_lsn;
1512  txn->commit_time = commit_time;
1513  txn->origin_id = origin_id;
1514  txn->origin_lsn = origin_lsn;
1515 
1516  /*
1517  * If this transaction has no snapshot, it didn't make any changes to the
1518  * database, so there's nothing to decode. Note that
1519  * ReorderBufferCommitChild will have transferred any snapshots from
1520  * subtransactions if there were any.
1521  */
1522  if (txn->base_snapshot == NULL)
1523  {
1524  Assert(txn->ninvalidations == 0);
1525  ReorderBufferCleanupTXN(rb, txn);
1526  return;
1527  }
1528 
1529  snapshot_now = txn->base_snapshot;
1530 
1531  /* build data to be able to lookup the CommandIds of catalog tuples */
1533 
1534  /* setup the initial snapshot */
1535  SetupHistoricSnapshot(snapshot_now, txn->tuplecid_hash);
1536 
1537  /*
1538  * Decoding needs access to syscaches et al., which in turn use
1539  * heavyweight locks and such. Thus we need to have enough state around to
1540  * keep track of those. The easiest way is to simply use a transaction
1541  * internally. That also allows us to easily enforce that nothing writes
1542  * to the database by checking for xid assignments.
1543  *
1544  * When we're called via the SQL SRF there's already a transaction
1545  * started, so start an explicit subtransaction there.
1546  */
1547  using_subtxn = IsTransactionOrTransactionBlock();
1548 
1549  PG_TRY();
1550  {
1551  ReorderBufferChange *change;
1552  ReorderBufferChange *specinsert = NULL;
1553 
1554  if (using_subtxn)
1555  BeginInternalSubTransaction("replay");
1556  else
1558 
1559  rb->begin(rb, txn);
1560 
1561  iterstate = ReorderBufferIterTXNInit(rb, txn);
1562  while ((change = ReorderBufferIterTXNNext(rb, iterstate)) != NULL)
1563  {
1564  Relation relation = NULL;
1565  Oid reloid;
1566 
1567  switch (change->action)
1568  {
1570 
1571  /*
1572  * Confirmation for speculative insertion arrived. Simply
1573  * use as a normal record. It'll be cleaned up at the end
1574  * of INSERT processing.
1575  */
1576  if (specinsert == NULL)
1577  elog(ERROR, "invalid ordering of speculative insertion changes");
1578  Assert(specinsert->data.tp.oldtuple == NULL);
1579  change = specinsert;
1581 
1582  /* intentionally fall through */
1586  Assert(snapshot_now);
1587 
1588  reloid = RelidByRelfilenode(change->data.tp.relnode.spcNode,
1589  change->data.tp.relnode.relNode);
1590 
1591  /*
1592  * Mapped catalog tuple without data, emitted while
1593  * catalog table was in the process of being rewritten. We
1594  * can fail to look up the relfilenode, because the
1595  * relmapper has no "historic" view, in contrast to normal
1596  * the normal catalog during decoding. Thus repeated
1597  * rewrites can cause a lookup failure. That's OK because
1598  * we do not decode catalog changes anyway. Normally such
1599  * tuples would be skipped over below, but we can't
1600  * identify whether the table should be logically logged
1601  * without mapping the relfilenode to the oid.
1602  */
1603  if (reloid == InvalidOid &&
1604  change->data.tp.newtuple == NULL &&
1605  change->data.tp.oldtuple == NULL)
1606  goto change_done;
1607  else if (reloid == InvalidOid)
1608  elog(ERROR, "could not map filenode \"%s\" to relation OID",
1609  relpathperm(change->data.tp.relnode,
1610  MAIN_FORKNUM));
1611 
1612  relation = RelationIdGetRelation(reloid);
1613 
1614  if (!RelationIsValid(relation))
1615  elog(ERROR, "could not open relation with OID %u (for filenode \"%s\")",
1616  reloid,
1617  relpathperm(change->data.tp.relnode,
1618  MAIN_FORKNUM));
1619 
1620  if (!RelationIsLogicallyLogged(relation))
1621  goto change_done;
1622 
1623  /*
1624  * Ignore temporary heaps created during DDL unless the
1625  * plugin has asked for them.
1626  */
1627  if (relation->rd_rel->relrewrite && !rb->output_rewrites)
1628  goto change_done;
1629 
1630  /*
1631  * For now ignore sequence changes entirely. Most of the
1632  * time they don't log changes using records we
1633  * understand, so it doesn't make sense to handle the few
1634  * cases we do.
1635  */
1636  if (relation->rd_rel->relkind == RELKIND_SEQUENCE)
1637  goto change_done;
1638 
1639  /* user-triggered change */
1640  if (!IsToastRelation(relation))
1641  {
1642  ReorderBufferToastReplace(rb, txn, relation, change);
1643  rb->apply_change(rb, txn, relation, change);
1644 
1645  /*
1646  * Only clear reassembled toast chunks if we're sure
1647  * they're not required anymore. The creator of the
1648  * tuple tells us.
1649  */
1650  if (change->data.tp.clear_toast_afterwards)
1651  ReorderBufferToastReset(rb, txn);
1652  }
1653  /* we're not interested in toast deletions */
1654  else if (change->action == REORDER_BUFFER_CHANGE_INSERT)
1655  {
1656  /*
1657  * Need to reassemble the full toasted Datum in
1658  * memory, to ensure the chunks don't get reused till
1659  * we're done remove it from the list of this
1660  * transaction's changes. Otherwise it will get
1661  * freed/reused while restoring spooled data from
1662  * disk.
1663  */
1664  Assert(change->data.tp.newtuple != NULL);
1665 
1666  dlist_delete(&change->node);
1667  ReorderBufferToastAppendChunk(rb, txn, relation,
1668  change);
1669  }
1670 
1671  change_done:
1672 
1673  /*
1674  * Either speculative insertion was confirmed, or it was
1675  * unsuccessful and the record isn't needed anymore.
1676  */
1677  if (specinsert != NULL)
1678  {
1679  ReorderBufferReturnChange(rb, specinsert);
1680  specinsert = NULL;
1681  }
1682 
1683  if (relation != NULL)
1684  {
1685  RelationClose(relation);
1686  relation = NULL;
1687  }
1688  break;
1689 
1691 
1692  /*
1693  * Speculative insertions are dealt with by delaying the
1694  * processing of the insert until the confirmation record
1695  * arrives. For that we simply unlink the record from the
1696  * chain, so it does not get freed/reused while restoring
1697  * spooled data from disk.
1698  *
1699  * This is safe in the face of concurrent catalog changes
1700  * because the relevant relation can't be changed between
1701  * speculative insertion and confirmation due to
1702  * CheckTableNotInUse() and locking.
1703  */
1704 
1705  /* clear out a pending (and thus failed) speculation */
1706  if (specinsert != NULL)
1707  {
1708  ReorderBufferReturnChange(rb, specinsert);
1709  specinsert = NULL;
1710  }
1711 
1712  /* and memorize the pending insertion */
1713  dlist_delete(&change->node);
1714  specinsert = change;
1715  break;
1716 
1718  {
1719  int i;
1720  int nrelids = change->data.truncate.nrelids;
1721  int nrelations = 0;
1722  Relation *relations;
1723 
1724  relations = palloc0(nrelids * sizeof(Relation));
1725  for (i = 0; i < nrelids; i++)
1726  {
1727  Oid relid = change->data.truncate.relids[i];
1728  Relation relation;
1729 
1730  relation = RelationIdGetRelation(relid);
1731 
1732  if (!RelationIsValid(relation))
1733  elog(ERROR, "could not open relation with OID %u", relid);
1734 
1735  if (!RelationIsLogicallyLogged(relation))
1736  continue;
1737 
1738  relations[nrelations++] = relation;
1739  }
1740 
1741  rb->apply_truncate(rb, txn, nrelations, relations, change);
1742 
1743  for (i = 0; i < nrelations; i++)
1744  RelationClose(relations[i]);
1745 
1746  break;
1747  }
1748 
1750  rb->message(rb, txn, change->lsn, true,
1751  change->data.msg.prefix,
1752  change->data.msg.message_size,
1753  change->data.msg.message);
1754  break;
1755 
1757  /* get rid of the old */
1758  TeardownHistoricSnapshot(false);
1759 
1760  if (snapshot_now->copied)
1761  {
1762  ReorderBufferFreeSnap(rb, snapshot_now);
1763  snapshot_now =
1764  ReorderBufferCopySnap(rb, change->data.snapshot,
1765  txn, command_id);
1766  }
1767 
1768  /*
1769  * Restored from disk, need to be careful not to double
1770  * free. We could introduce refcounting for that, but for
1771  * now this seems infrequent enough not to care.
1772  */
1773  else if (change->data.snapshot->copied)
1774  {
1775  snapshot_now =
1776  ReorderBufferCopySnap(rb, change->data.snapshot,
1777  txn, command_id);
1778  }
1779  else
1780  {
1781  snapshot_now = change->data.snapshot;
1782  }
1783 
1784 
1785  /* and continue with the new one */
1786  SetupHistoricSnapshot(snapshot_now, txn->tuplecid_hash);
1787  break;
1788 
1790  Assert(change->data.command_id != InvalidCommandId);
1791 
1792  if (command_id < change->data.command_id)
1793  {
1794  command_id = change->data.command_id;
1795 
1796  if (!snapshot_now->copied)
1797  {
1798  /* we don't use the global one anymore */
1799  snapshot_now = ReorderBufferCopySnap(rb, snapshot_now,
1800  txn, command_id);
1801  }
1802 
1803  snapshot_now->curcid = command_id;
1804 
1805  TeardownHistoricSnapshot(false);
1806  SetupHistoricSnapshot(snapshot_now, txn->tuplecid_hash);
1807 
1808  /*
1809  * Every time the CommandId is incremented, we could
1810  * see new catalog contents, so execute all
1811  * invalidations.
1812  */
1814  }
1815 
1816  break;
1817 
1819  elog(ERROR, "tuplecid value in changequeue");
1820  break;
1821  }
1822  }
1823 
1824  /*
1825  * There's a speculative insertion remaining, just clean in up, it
1826  * can't have been successful, otherwise we'd gotten a confirmation
1827  * record.
1828  */
1829  if (specinsert)
1830  {
1831  ReorderBufferReturnChange(rb, specinsert);
1832  specinsert = NULL;
1833  }
1834 
1835  /* clean up the iterator */
1836  ReorderBufferIterTXNFinish(rb, iterstate);
1837  iterstate = NULL;
1838 
1839  /* call commit callback */
1840  rb->commit(rb, txn, commit_lsn);
1841 
1842  /* this is just a sanity check against bad output plugin behaviour */
1844  elog(ERROR, "output plugin used XID %u",
1846 
1847  /* cleanup */
1848  TeardownHistoricSnapshot(false);
1849 
1850  /*
1851  * Aborting the current (sub-)transaction as a whole has the right
1852  * semantics. We want all locks acquired in here to be released, not
1853  * reassigned to the parent and we do not want any database access
1854  * have persistent effects.
1855  */
1857 
1858  /* make sure there's no cache pollution */
1860 
1861  if (using_subtxn)
1863 
1864  if (snapshot_now->copied)
1865  ReorderBufferFreeSnap(rb, snapshot_now);
1866 
1867  /* remove potential on-disk data, and deallocate */
1868  ReorderBufferCleanupTXN(rb, txn);
1869  }
1870  PG_CATCH();
1871  {
1872  /* TODO: Encapsulate cleanup from the PG_TRY and PG_CATCH blocks */
1873  if (iterstate)
1874  ReorderBufferIterTXNFinish(rb, iterstate);
1875 
1877 
1878  /*
1879  * Force cache invalidation to happen outside of a valid transaction
1880  * to prevent catalog access as we just caught an error.
1881  */
1883 
1884  /* make sure there's no cache pollution */
1886 
1887  if (using_subtxn)
1889 
1890  if (snapshot_now->copied)
1891  ReorderBufferFreeSnap(rb, snapshot_now);
1892 
1893  /* remove potential on-disk data, and deallocate */
1894  ReorderBufferCleanupTXN(rb, txn);
1895 
1896  PG_RE_THROW();
1897  }
1898  PG_END_TRY();
1899 }
static void ReorderBufferBuildTupleCidHash(ReorderBuffer *rb, ReorderBufferTXN *txn)
uint32 CommandId
Definition: c.h:528
void ReorderBufferReturnChange(ReorderBuffer *rb, ReorderBufferChange *change)
TimestampTz commit_time
void AbortCurrentTransaction(void)
Definition: xact.c:3162
bool IsToastRelation(Relation relation)
Definition: catalog.c:141
#define relpathperm(rnode, forknum)
Definition: relpath.h:83
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
Snapshot base_snapshot
static void ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
RepOriginId origin_id
bool copied
Definition: snapshot.h:185
struct ReorderBufferChange::@101::@102 tp
struct ReorderBufferChange::@101::@104 msg
Oid RelidByRelfilenode(Oid reltablespace, Oid relfilenode)
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4653
static void ReorderBufferIterTXNFinish(ReorderBuffer *rb, ReorderBufferIterTXNState *state)
void TeardownHistoricSnapshot(bool is_error)
Definition: snapmgr.c:2051
#define RelationIsLogicallyLogged(relation)
Definition: rel.h:594
Form_pg_class rd_rel
Definition: rel.h:83
unsigned int Oid
Definition: postgres_ext.h:31
enum ReorderBufferChangeType action
Definition: reorderbuffer.h:83
XLogRecPtr origin_lsn
#define FirstCommandId
Definition: c.h:530
#define ERROR
Definition: elog.h:43
#define RelationIsValid(relation)
Definition: rel.h:395
TransactionId GetCurrentTransactionId(void)
Definition: xact.c:422
void RollbackAndReleaseCurrentSubTransaction(void)
Definition: xact.c:4464
TransactionId GetCurrentTransactionIdIfAny(void)
Definition: xact.c:439
#define InvalidTransactionId
Definition: transam.h:31
XLogRecPtr final_lsn
void RelationClose(Relation relation)
Definition: relcache.c:2088
static void dlist_delete(dlist_node *node)
Definition: ilist.h:358
static Snapshot ReorderBufferCopySnap(ReorderBuffer *rb, Snapshot orig_snap, ReorderBufferTXN *txn, CommandId cid)
void * palloc0(Size size)
Definition: mcxt.c:980
#define InvalidCommandId
Definition: c.h:531
static void ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
static void ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
#define InvalidOid
Definition: postgres_ext.h:36
CommandId curcid
Definition: snapshot.h:187
static void ReorderBufferExecuteInvalidations(ReorderBuffer *rb, ReorderBufferTXN *txn)
#define PG_CATCH()
Definition: elog.h:332
#define Assert(condition)
Definition: c.h:739
union ReorderBufferChange::@101 data
static void ReorderBufferToastReset(ReorderBuffer *rb, ReorderBufferTXN *txn)
static ReorderBufferChange * ReorderBufferIterTXNNext(ReorderBuffer *rb, ReorderBufferIterTXNState *state)
XLogRecPtr end_lsn
void StartTransactionCommand(void)
Definition: xact.c:2797
void BeginInternalSubTransaction(const char *name)
Definition: xact.c:4359
#define PG_RE_THROW()
Definition: elog.h:363
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)
void SetupHistoricSnapshot(Snapshot historic_snapshot, HTAB *tuplecids)
Definition: snapmgr.c:2035
#define elog(elevel,...)
Definition: elog.h:228
int i
#define PG_TRY()
Definition: elog.h:322
static void ReorderBufferFreeSnap(ReorderBuffer *rb, Snapshot snap)
static ReorderBufferIterTXNState * ReorderBufferIterTXNInit(ReorderBuffer *rb, ReorderBufferTXN *txn)
Relation RelationIdGetRelation(Oid relationId)
Definition: relcache.c:1989
#define PG_END_TRY()
Definition: elog.h:347
struct ReorderBufferChange::@101::@103 truncate

◆ ReorderBufferCommitChild()

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

Definition at line 941 of file reorderbuffer.c.

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

Referenced by DecodeCommit().

944 {
945  ReorderBufferTXN *subtxn;
946 
947  subtxn = ReorderBufferTXNByXid(rb, subxid, false, NULL,
948  InvalidXLogRecPtr, false);
949 
950  /*
951  * No need to do anything if that subtxn didn't contain any changes
952  */
953  if (!subtxn)
954  return;
955 
956  subtxn->final_lsn = commit_lsn;
957  subtxn->end_lsn = end_lsn;
958 
959  /*
960  * Assign this subxact as a child of the toplevel xact (no-op if already
961  * done.)
962  */
964 }
#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)

◆ ReorderBufferForget()

void ReorderBufferForget ( ReorderBuffer ,
TransactionId  ,
XLogRecPtr  lsn 
)

Definition at line 1998 of file reorderbuffer.c.

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

Referenced by DecodeCommit().

1999 {
2000  ReorderBufferTXN *txn;
2001 
2002  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2003  false);
2004 
2005  /* unknown, nothing to forget */
2006  if (txn == NULL)
2007  return;
2008 
2009  /* cosmetic... */
2010  txn->final_lsn = lsn;
2011 
2012  /*
2013  * Process cache invalidation messages if there are any. Even if we're not
2014  * interested in the transaction's contents, it could have manipulated the
2015  * catalog and we need to update the caches according to that.
2016  */
2017  if (txn->base_snapshot != NULL && txn->ninvalidations > 0)
2019  txn->invalidations);
2020  else
2021  Assert(txn->ninvalidations == 0);
2022 
2023  /* remove potential on-disk data, and deallocate */
2024  ReorderBufferCleanupTXN(rb, txn);
2025 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
Snapshot base_snapshot
void ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations)
XLogRecPtr final_lsn
static void ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
#define Assert(condition)
Definition: c.h:739
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 334 of file reorderbuffer.c.

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

Referenced by FreeDecodingContext().

335 {
336  MemoryContext context = rb->context;
337 
338  /*
339  * We free separately allocated data by entirely scrapping reorderbuffer's
340  * memory context.
341  */
342  MemoryContextDelete(context);
343 
344  /* Free disk space used by unconsumed reorder buffers */
346 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
ReplicationSlotPersistentData data
Definition: slot.h:132
ReplicationSlot * MyReplicationSlot
Definition: slot.c:96
#define NameStr(name)
Definition: c.h:616
static void ReorderBufferCleanupSerializedTXNs(const char *slotname)

◆ ReorderBufferGetChange()

ReorderBufferChange* ReorderBufferGetChange ( ReorderBuffer )

Definition at line 402 of file reorderbuffer.c.

References ReorderBuffer::change_context, and MemoryContextAlloc().

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

403 {
404  ReorderBufferChange *change;
405 
406  change = (ReorderBufferChange *)
407  MemoryContextAlloc(rb->change_context, sizeof(ReorderBufferChange));
408 
409  memset(change, 0, sizeof(ReorderBufferChange));
410  return change;
411 }
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796

◆ ReorderBufferGetOldestTXN()

ReorderBufferTXN* ReorderBufferGetOldestTXN ( ReorderBuffer )

Definition at line 766 of file reorderbuffer.c.

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

Referenced by SnapBuildProcessRunningXacts().

767 {
768  ReorderBufferTXN *txn;
769 
770  AssertTXNLsnOrder(rb);
771 
772  if (dlist_is_empty(&rb->toplevel_by_lsn))
773  return NULL;
774 
775  txn = dlist_head_element(ReorderBufferTXN, node, &rb->toplevel_by_lsn);
776 
779  return txn;
780 }
XLogRecPtr first_lsn
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define dlist_head_element(type, membername, lhead)
Definition: ilist.h:487
static void AssertTXNLsnOrder(ReorderBuffer *rb)
#define Assert(condition)
Definition: c.h:739
static bool dlist_is_empty(dlist_head *head)
Definition: ilist.h:289

◆ ReorderBufferGetOldestXmin()

TransactionId ReorderBufferGetOldestXmin ( ReorderBuffer rb)

Definition at line 794 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().

795 {
796  ReorderBufferTXN *txn;
797 
798  AssertTXNLsnOrder(rb);
799 
801  return InvalidTransactionId;
802 
803  txn = dlist_head_element(ReorderBufferTXN, base_snapshot_node,
805  return txn->base_snapshot->xmin;
806 }
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:487
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 514 of file reorderbuffer.c.

References ReorderBuffer::context, and MemoryContextAlloc().

Referenced by DecodeTruncate(), and ReorderBufferRestoreChange().

515 {
516  Oid *relids;
517  Size alloc_len;
518 
519  alloc_len = sizeof(Oid) * nrelids;
520 
521  relids = (Oid *) MemoryContextAlloc(rb->context, alloc_len);
522 
523  return relids;
524 }
unsigned int Oid
Definition: postgres_ext.h:31
size_t Size
Definition: c.h:467
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796

◆ ReorderBufferGetTupleBuf()

ReorderBufferTupleBuf* ReorderBufferGetTupleBuf ( ReorderBuffer ,
Size  tuple_len 
)

Definition at line 478 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().

479 {
480  ReorderBufferTupleBuf *tuple;
481  Size alloc_len;
482 
483  alloc_len = tuple_len + SizeofHeapTupleHeader;
484 
485  tuple = (ReorderBufferTupleBuf *)
486  MemoryContextAlloc(rb->tup_context,
487  sizeof(ReorderBufferTupleBuf) +
488  MAXIMUM_ALIGNOF + alloc_len);
489  tuple->alloc_tuple_size = alloc_len;
490  tuple->tuple.t_data = ReorderBufferTupleBufData(tuple);
491 
492  return tuple;
493 }
#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:467
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:796

◆ ReorderBufferImmediateInvalidation()

void ReorderBufferImmediateInvalidation ( ReorderBuffer ,
uint32  ninvalidations,
SharedInvalidationMessage invalidations 
)

Definition at line 2034 of file reorderbuffer.c.

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

Referenced by DecodeStandbyOp(), and ReorderBufferForget().

2036 {
2037  bool use_subtxn = IsTransactionOrTransactionBlock();
2038  int i;
2039 
2040  if (use_subtxn)
2041  BeginInternalSubTransaction("replay");
2042 
2043  /*
2044  * Force invalidations to happen outside of a valid transaction - that way
2045  * entries will just be marked as invalid without accessing the catalog.
2046  * That's advantageous because we don't need to setup the full state
2047  * necessary for catalog access.
2048  */
2049  if (use_subtxn)
2051 
2052  for (i = 0; i < ninvalidations; i++)
2053  LocalExecuteInvalidationMessage(&invalidations[i]);
2054 
2055  if (use_subtxn)
2057 }
void AbortCurrentTransaction(void)
Definition: xact.c:3162
bool IsTransactionOrTransactionBlock(void)
Definition: xact.c:4653
void RollbackAndReleaseCurrentSubTransaction(void)
Definition: xact.c:4464
void BeginInternalSubTransaction(const char *name)
Definition: xact.c:4359
void LocalExecuteInvalidationMessage(SharedInvalidationMessage *msg)
Definition: inval.c:556
int i

◆ ReorderBufferProcessXid()

void ReorderBufferProcessXid ( ReorderBuffer ,
TransactionId  xid,
XLogRecPtr  lsn 
)

Definition at line 2070 of file reorderbuffer.c.

References InvalidTransactionId, and ReorderBufferTXNByXid().

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

2071 {
2072  /* many records won't have an xid assigned, centralize check here */
2073  if (xid != InvalidTransactionId)
2074  ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
2075 }
#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  
)

Definition at line 625 of file reorderbuffer.c.

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

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

627 {
628  ReorderBufferTXN *txn;
629 
630  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
631 
632  change->lsn = lsn;
633  change->txn = txn;
634 
635  Assert(InvalidXLogRecPtr != lsn);
636  dlist_push_tail(&txn->changes, &change->node);
637  txn->nentries++;
638  txn->nentries_mem++;
639 
640  /* update memory accounting information */
641  ReorderBufferChangeMemoryUpdate(rb, change, true);
642 
643  /* check the memory limits and evict something if needed */
645 }
#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)
static void ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
#define Assert(condition)
Definition: c.h:739
static ReorderBufferTXN * ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, bool *is_new, XLogRecPtr lsn, bool create_as_top)

◆ ReorderBufferQueueMessage()

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

Definition at line 651 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().

655 {
656  if (transactional)
657  {
658  MemoryContext oldcontext;
659  ReorderBufferChange *change;
660 
662 
663  oldcontext = MemoryContextSwitchTo(rb->context);
664 
665  change = ReorderBufferGetChange(rb);
667  change->data.msg.prefix = pstrdup(prefix);
668  change->data.msg.message_size = message_size;
669  change->data.msg.message = palloc(message_size);
670  memcpy(change->data.msg.message, message, message_size);
671 
672  ReorderBufferQueueChange(rb, xid, lsn, change);
673 
674  MemoryContextSwitchTo(oldcontext);
675  }
676  else
677  {
678  ReorderBufferTXN *txn = NULL;
679  volatile Snapshot snapshot_now = snapshot;
680 
681  if (xid != InvalidTransactionId)
682  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
683 
684  /* setup snapshot to allow catalog access */
685  SetupHistoricSnapshot(snapshot_now, NULL);
686  PG_TRY();
687  {
688  rb->message(rb, txn, lsn, false, prefix, message_size, message);
689 
691  }
692  PG_CATCH();
693  {
695  PG_RE_THROW();
696  }
697  PG_END_TRY();
698  }
699 }
struct ReorderBufferChange::@101::@104 msg
char * pstrdup(const char *in)
Definition: mcxt.c:1186
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void TeardownHistoricSnapshot(bool is_error)
Definition: snapmgr.c:2051
ReorderBufferChange * ReorderBufferGetChange(ReorderBuffer *rb)
enum ReorderBufferChangeType action
Definition: reorderbuffer.h:83
#define InvalidTransactionId
Definition: transam.h:31
#define PG_CATCH()
Definition: elog.h:332
#define Assert(condition)
Definition: c.h:739
union ReorderBufferChange::@101 data
#define PG_RE_THROW()
Definition: elog.h:363
void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, ReorderBufferChange *change)
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:949
void SetupHistoricSnapshot(Snapshot historic_snapshot, HTAB *tuplecids)
Definition: snapmgr.c:2035
#define PG_TRY()
Definition: elog.h:322
#define PG_END_TRY()
Definition: elog.h:347

◆ ReorderBufferReturnChange()

void ReorderBufferReturnChange ( ReorderBuffer ,
ReorderBufferChange  
)

Definition at line 417 of file reorderbuffer.c.

References ReorderBufferChange::action, ReorderBufferChange::data, 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_CONFIRM, REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT, REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID, REORDER_BUFFER_CHANGE_MESSAGE, REORDER_BUFFER_CHANGE_TRUNCATE, REORDER_BUFFER_CHANGE_UPDATE, ReorderBufferChangeMemoryUpdate(), ReorderBufferFreeSnap(), ReorderBufferReturnRelids(), ReorderBufferReturnTupleBuf(), ReorderBufferChange::snapshot, ReorderBufferChange::tp, and ReorderBufferChange::truncate.

Referenced by ReorderBufferCleanupTXN(), ReorderBufferCommit(), ReorderBufferIterTXNFinish(), ReorderBufferIterTXNNext(), ReorderBufferRestoreChanges(), ReorderBufferSerializeTXN(), and ReorderBufferToastReset().

418 {
419  /* update memory accounting info */
420  ReorderBufferChangeMemoryUpdate(rb, change, false);
421 
422  /* free contained data */
423  switch (change->action)
424  {
429  if (change->data.tp.newtuple)
430  {
431  ReorderBufferReturnTupleBuf(rb, change->data.tp.newtuple);
432  change->data.tp.newtuple = NULL;
433  }
434 
435  if (change->data.tp.oldtuple)
436  {
437  ReorderBufferReturnTupleBuf(rb, change->data.tp.oldtuple);
438  change->data.tp.oldtuple = NULL;
439  }
440  break;
442  if (change->data.msg.prefix != NULL)
443  pfree(change->data.msg.prefix);
444  change->data.msg.prefix = NULL;
445  if (change->data.msg.message != NULL)
446  pfree(change->data.msg.message);
447  change->data.msg.message = NULL;
448  break;
450  if (change->data.snapshot)
451  {
452  ReorderBufferFreeSnap(rb, change->data.snapshot);
453  change->data.snapshot = NULL;
454  }
455  break;
456  /* no data in addition to the struct itself */
458  if (change->data.truncate.relids != NULL)
459  {
460  ReorderBufferReturnRelids(rb, change->data.truncate.relids);
461  change->data.truncate.relids = NULL;
462  }
463  break;
467  break;
468  }
469 
470  pfree(change);
471 }
void pfree(void *pointer)
Definition: mcxt.c:1056
void ReorderBufferReturnRelids(ReorderBuffer *rb, Oid *relids)
static void ReorderBufferChangeMemoryUpdate(ReorderBuffer *rb, ReorderBufferChange *change, bool addition)
void ReorderBufferReturnTupleBuf(ReorderBuffer *rb, ReorderBufferTupleBuf *tuple)
static void ReorderBufferFreeSnap(ReorderBuffer *rb, Snapshot snap)

◆ ReorderBufferReturnRelids()

void ReorderBufferReturnRelids ( ReorderBuffer ,
Oid relids 
)

Definition at line 530 of file reorderbuffer.c.

References pfree().

Referenced by ReorderBufferReturnChange().

531 {
532  pfree(relids);
533 }
void pfree(void *pointer)
Definition: mcxt.c:1056

◆ ReorderBufferReturnTupleBuf()

void ReorderBufferReturnTupleBuf ( ReorderBuffer ,
ReorderBufferTupleBuf tuple 
)

Definition at line 499 of file reorderbuffer.c.

References pfree().

Referenced by ReorderBufferReturnChange().

500 {
501  pfree(tuple);
502 }
void pfree(void *pointer)
Definition: mcxt.c:1056

◆ ReorderBufferSetBaseSnapshot()

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

◆ ReorderBufferSetRestartPoint()

void ReorderBufferSetRestartPoint ( ReorderBuffer ,
XLogRecPtr  ptr 
)

Definition at line 809 of file reorderbuffer.c.

References ReorderBuffer::current_restart_decoding_lsn.

Referenced by SnapBuildRestore(), and SnapBuildSerialize().

810 {
811  rb->current_restart_decoding_lsn = ptr;
812 }

◆ ReorderBufferXidHasBaseSnapshot()

bool ReorderBufferXidHasBaseSnapshot ( ReorderBuffer ,
TransactionId  xid 
)

Definition at line 2286 of file reorderbuffer.c.

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

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

2287 {
2288  ReorderBufferTXN *txn;
2289 
2290  txn = ReorderBufferTXNByXid(rb, xid, false,
2291  NULL, InvalidXLogRecPtr, false);
2292 
2293  /* transaction isn't known yet, ergo no snapshot */
2294  if (txn == NULL)
2295  return false;
2296 
2297  /* a known subtxn? operate on top-level txn instead */
2298  if (txn->is_known_as_subxact)
2299  txn = ReorderBufferTXNByXid(rb, txn->toplevel_xid, false,
2300  NULL, InvalidXLogRecPtr, false);
2301 
2302  return txn->base_snapshot != NULL;
2303 }
#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)
TransactionId toplevel_xid

◆ ReorderBufferXidHasCatalogChanges()

bool ReorderBufferXidHasCatalogChanges ( ReorderBuffer ,
TransactionId  xid 
)

Definition at line 2269 of file reorderbuffer.c.

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

Referenced by SnapBuildCommitTxn().

2270 {
2271  ReorderBufferTXN *txn;
2272 
2273  txn = ReorderBufferTXNByXid(rb, xid, false, NULL, InvalidXLogRecPtr,
2274  false);
2275  if (txn == NULL)
2276  return false;
2277 
2278  return txn->has_catalog_changes;
2279 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
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 2254 of file reorderbuffer.c.

References ReorderBufferTXN::has_catalog_changes, ReorderBufferTXNByXid(), and ReorderBufferTXNByIdEnt::txn.

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

2256 {
2257  ReorderBufferTXN *txn;
2258 
2259  txn = ReorderBufferTXNByXid(rb, xid, true, NULL, lsn, true);
2260 
2261  txn->has_catalog_changes = true;
2262 }
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 3138 of file reorderbuffer.c.

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

Referenced by StartupXLOG().

3139 {
3140  DIR *logical_dir;
3141  struct dirent *logical_de;
3142 
3143  logical_dir = AllocateDir("pg_replslot");
3144  while ((logical_de = ReadDir(logical_dir, "pg_replslot")) != NULL)
3145  {
3146  if (strcmp(logical_de->d_name, ".") == 0 ||
3147  strcmp(logical_de->d_name, "..") == 0)
3148  continue;
3149 
3150  /* if it cannot be a slot, skip the directory */
3151  if (!ReplicationSlotValidateName(logical_de->d_name, DEBUG2))
3152  continue;
3153 
3154  /*
3155  * ok, has to be a surviving logical slot, iterate and delete
3156  * everything starting with xid-*
3157  */
3159  }
3160  FreeDir(logical_dir);
3161 }
Definition: dirent.h:9
bool ReplicationSlotValidateName(const char *name, int elevel)
Definition: slot.c:174
Definition: dirent.c:25
#define DEBUG2
Definition: elog.h:24
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2503
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2569
char d_name[MAX_PATH]
Definition: dirent.h:14
static void ReorderBufferCleanupSerializedTXNs(const char *slotname)
int FreeDir(DIR *dir)
Definition: fd.c:2621

Variable Documentation

◆ logical_decoding_work_mem

PGDLLIMPORT int logical_decoding_work_mem

Definition at line 185 of file reorderbuffer.c.

Referenced by ReorderBufferCheckMemoryLimit().