reorderbuffer.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * reorderbuffer.h
  3. * PostgreSQL logical replay/reorder buffer management.
  4. *
  5. * Copyright (c) 2012-2022, PostgreSQL Global Development Group
  6. *
  7. * src/include/replication/reorderbuffer.h
  8. */
  9. #ifndef REORDERBUFFER_H
  10. #define REORDERBUFFER_H
  11. #include "access/htup_details.h"
  12. #include "lib/ilist.h"
  13. #include "storage/sinval.h"
  14. #include "utils/hsearch.h"
  15. #include "utils/relcache.h"
  16. #include "utils/snapshot.h"
  17. #include "utils/timestamp.h"
  18. extern PGDLLIMPORT int logical_decoding_work_mem;
  19. /* an individual tuple, stored in one chunk of memory */
  20. typedef struct ReorderBufferTupleBuf
  21. {
  22. /* position in preallocated list */
  23. slist_node node;
  24. /* tuple header, the interesting bit for users of logical decoding */
  25. HeapTupleData tuple;
  26. /* pre-allocated size of tuple buffer, different from tuple size */
  27. Size alloc_tuple_size;
  28. /* actual tuple data follows */
  29. } ReorderBufferTupleBuf;
  30. /* pointer to the data stored in a TupleBuf */
  31. #define ReorderBufferTupleBufData(p) \
  32. ((HeapTupleHeader) MAXALIGN(((char *) p) + sizeof(ReorderBufferTupleBuf)))
  33. /*
  34. * Types of the change passed to a 'change' callback.
  35. *
  36. * For efficiency and simplicity reasons we want to keep Snapshots, CommandIds
  37. * and ComboCids in the same list with the user visible INSERT/UPDATE/DELETE
  38. * changes. Users of the decoding facilities will never see changes with
  39. * *_INTERNAL_* actions.
  40. *
  41. * The INTERNAL_SPEC_INSERT and INTERNAL_SPEC_CONFIRM, and INTERNAL_SPEC_ABORT
  42. * changes concern "speculative insertions", their confirmation, and abort
  43. * respectively. They're used by INSERT .. ON CONFLICT .. UPDATE. Users of
  44. * logical decoding don't have to care about these.
  45. */
  46. typedef enum ReorderBufferChangeType
  47. {
  48. REORDER_BUFFER_CHANGE_INSERT,
  49. REORDER_BUFFER_CHANGE_UPDATE,
  50. REORDER_BUFFER_CHANGE_DELETE,
  51. REORDER_BUFFER_CHANGE_MESSAGE,
  52. REORDER_BUFFER_CHANGE_INVALIDATION,
  53. REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT,
  54. REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID,
  55. REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID,
  56. REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT,
  57. REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM,
  58. REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT,
  59. REORDER_BUFFER_CHANGE_TRUNCATE
  60. } ReorderBufferChangeType;
  61. /* forward declaration */
  62. struct ReorderBufferTXN;
  63. /*
  64. * a single 'change', can be an insert (with one tuple), an update (old, new),
  65. * or a delete (old).
  66. *
  67. * The same struct is also used internally for other purposes but that should
  68. * never be visible outside reorderbuffer.c.
  69. */
  70. typedef struct ReorderBufferChange
  71. {
  72. XLogRecPtr lsn;
  73. /* The type of change. */
  74. ReorderBufferChangeType action;
  75. /* Transaction this change belongs to. */
  76. struct ReorderBufferTXN *txn;
  77. RepOriginId origin_id;
  78. /*
  79. * Context data for the change. Which part of the union is valid depends
  80. * on action.
  81. */
  82. union
  83. {
  84. /* Old, new tuples when action == *_INSERT|UPDATE|DELETE */
  85. struct
  86. {
  87. /* relation that has been changed */
  88. RelFileNode relnode;
  89. /* no previously reassembled toast chunks are necessary anymore */
  90. bool clear_toast_afterwards;
  91. /* valid for DELETE || UPDATE */
  92. ReorderBufferTupleBuf *oldtuple;
  93. /* valid for INSERT || UPDATE */
  94. ReorderBufferTupleBuf *newtuple;
  95. } tp;
  96. /*
  97. * Truncate data for REORDER_BUFFER_CHANGE_TRUNCATE representing one
  98. * set of relations to be truncated.
  99. */
  100. struct
  101. {
  102. Size nrelids;
  103. bool cascade;
  104. bool restart_seqs;
  105. Oid *relids;
  106. } truncate;
  107. /* Message with arbitrary data. */
  108. struct
  109. {
  110. char *prefix;
  111. Size message_size;
  112. char *message;
  113. } msg;
  114. /* New snapshot, set when action == *_INTERNAL_SNAPSHOT */
  115. Snapshot snapshot;
  116. /*
  117. * New command id for existing snapshot in a catalog changing tx. Set
  118. * when action == *_INTERNAL_COMMAND_ID.
  119. */
  120. CommandId command_id;
  121. /*
  122. * New cid mapping for catalog changing transaction, set when action
  123. * == *_INTERNAL_TUPLECID.
  124. */
  125. struct
  126. {
  127. RelFileNode node;
  128. ItemPointerData tid;
  129. CommandId cmin;
  130. CommandId cmax;
  131. CommandId combocid;
  132. } tuplecid;
  133. /* Invalidation. */
  134. struct
  135. {
  136. uint32 ninvalidations; /* Number of messages */
  137. SharedInvalidationMessage *invalidations; /* invalidation message */
  138. } inval;
  139. } data;
  140. /*
  141. * While in use this is how a change is linked into a transactions,
  142. * otherwise it's the preallocated list.
  143. */
  144. dlist_node node;
  145. } ReorderBufferChange;
  146. /* ReorderBufferTXN txn_flags */
  147. #define RBTXN_HAS_CATALOG_CHANGES 0x0001
  148. #define RBTXN_IS_SUBXACT 0x0002
  149. #define RBTXN_IS_SERIALIZED 0x0004
  150. #define RBTXN_IS_SERIALIZED_CLEAR 0x0008
  151. #define RBTXN_IS_STREAMED 0x0010
  152. #define RBTXN_HAS_PARTIAL_CHANGE 0x0020
  153. #define RBTXN_PREPARE 0x0040
  154. #define RBTXN_SKIPPED_PREPARE 0x0080
  155. /* Does the transaction have catalog changes? */
  156. #define rbtxn_has_catalog_changes(txn) \
  157. ( \
  158. ((txn)->txn_flags & RBTXN_HAS_CATALOG_CHANGES) != 0 \
  159. )
  160. /* Is the transaction known as a subxact? */
  161. #define rbtxn_is_known_subxact(txn) \
  162. ( \
  163. ((txn)->txn_flags & RBTXN_IS_SUBXACT) != 0 \
  164. )
  165. /* Has this transaction been spilled to disk? */
  166. #define rbtxn_is_serialized(txn) \
  167. ( \
  168. ((txn)->txn_flags & RBTXN_IS_SERIALIZED) != 0 \
  169. )
  170. /* Has this transaction ever been spilled to disk? */
  171. #define rbtxn_is_serialized_clear(txn) \
  172. ( \
  173. ((txn)->txn_flags & RBTXN_IS_SERIALIZED_CLEAR) != 0 \
  174. )
  175. /* Has this transaction contains partial changes? */
  176. #define rbtxn_has_partial_change(txn) \
  177. ( \
  178. ((txn)->txn_flags & RBTXN_HAS_PARTIAL_CHANGE) != 0 \
  179. )
  180. /*
  181. * Has this transaction been streamed to downstream?
  182. *
  183. * (It's not possible to deduce this from nentries and nentries_mem for
  184. * various reasons. For example, all changes may be in subtransactions in
  185. * which case we'd have nentries==0 for the toplevel one, which would say
  186. * nothing about the streaming. So we maintain this flag, but only for the
  187. * toplevel transaction.)
  188. */
  189. #define rbtxn_is_streamed(txn) \
  190. ( \
  191. ((txn)->txn_flags & RBTXN_IS_STREAMED) != 0 \
  192. )
  193. /* Has this transaction been prepared? */
  194. #define rbtxn_prepared(txn) \
  195. ( \
  196. ((txn)->txn_flags & RBTXN_PREPARE) != 0 \
  197. )
  198. /* prepare for this transaction skipped? */
  199. #define rbtxn_skip_prepared(txn) \
  200. ( \
  201. ((txn)->txn_flags & RBTXN_SKIPPED_PREPARE) != 0 \
  202. )
  203. typedef struct ReorderBufferTXN
  204. {
  205. /* See above */
  206. bits32 txn_flags;
  207. /* The transaction's transaction id, can be a toplevel or sub xid. */
  208. TransactionId xid;
  209. /* Xid of top-level transaction, if known */
  210. TransactionId toplevel_xid;
  211. /*
  212. * Global transaction id required for identification of prepared
  213. * transactions.
  214. */
  215. char *gid;
  216. /*
  217. * LSN of the first data carrying, WAL record with knowledge about this
  218. * xid. This is allowed to *not* be first record adorned with this xid, if
  219. * the previous records aren't relevant for logical decoding.
  220. */
  221. XLogRecPtr first_lsn;
  222. /* ----
  223. * LSN of the record that lead to this xact to be prepared or committed or
  224. * aborted. This can be a
  225. * * plain commit record
  226. * * plain commit record, of a parent transaction
  227. * * prepared tansaction
  228. * * prepared transaction commit
  229. * * plain abort record
  230. * * prepared transaction abort
  231. *
  232. * This can also become set to earlier values than transaction end when
  233. * a transaction is spilled to disk; specifically it's set to the LSN of
  234. * the latest change written to disk so far.
  235. * ----
  236. */
  237. XLogRecPtr final_lsn;
  238. /*
  239. * LSN pointing to the end of the commit record + 1.
  240. */
  241. XLogRecPtr end_lsn;
  242. /* Toplevel transaction for this subxact (NULL for top-level). */
  243. struct ReorderBufferTXN *toptxn;
  244. /*
  245. * LSN of the last lsn at which snapshot information reside, so we can
  246. * restart decoding from there and fully recover this transaction from
  247. * WAL.
  248. */
  249. XLogRecPtr restart_decoding_lsn;
  250. /* origin of the change that caused this transaction */
  251. RepOriginId origin_id;
  252. XLogRecPtr origin_lsn;
  253. /*
  254. * Commit or Prepare time, only known when we read the actual commit or
  255. * prepare record.
  256. */
  257. union
  258. {
  259. TimestampTz commit_time;
  260. TimestampTz prepare_time;
  261. } xact_time;
  262. /*
  263. * The base snapshot is used to decode all changes until either this
  264. * transaction modifies the catalog, or another catalog-modifying
  265. * transaction commits.
  266. */
  267. Snapshot base_snapshot;
  268. XLogRecPtr base_snapshot_lsn;
  269. dlist_node base_snapshot_node; /* link in txns_by_base_snapshot_lsn */
  270. /*
  271. * Snapshot/CID from the previous streaming run. Only valid for already
  272. * streamed transactions (NULL/InvalidCommandId otherwise).
  273. */
  274. Snapshot snapshot_now;
  275. CommandId command_id;
  276. /*
  277. * How many ReorderBufferChange's do we have in this txn.
  278. *
  279. * Changes in subtransactions are *not* included but tracked separately.
  280. */
  281. uint64 nentries;
  282. /*
  283. * How many of the above entries are stored in memory in contrast to being
  284. * spilled to disk.
  285. */
  286. uint64 nentries_mem;
  287. /*
  288. * List of ReorderBufferChange structs, including new Snapshots, new
  289. * CommandIds and command invalidation messages.
  290. */
  291. dlist_head changes;
  292. /*
  293. * List of (relation, ctid) => (cmin, cmax) mappings for catalog tuples.
  294. * Those are always assigned to the toplevel transaction. (Keep track of
  295. * #entries to create a hash of the right size)
  296. */
  297. dlist_head tuplecids;
  298. uint64 ntuplecids;
  299. /*
  300. * On-demand built hash for looking up the above values.
  301. */
  302. HTAB *tuplecid_hash;
  303. /*
  304. * Hash containing (potentially partial) toast entries. NULL if no toast
  305. * tuples have been found for the current change.
  306. */
  307. HTAB *toast_hash;
  308. /*
  309. * non-hierarchical list of subtransactions that are *not* aborted. Only
  310. * used in toplevel transactions.
  311. */
  312. dlist_head subtxns;
  313. uint32 nsubtxns;
  314. /*
  315. * Stored cache invalidations. This is not a linked list because we get
  316. * all the invalidations at once.
  317. */
  318. uint32 ninvalidations;
  319. SharedInvalidationMessage *invalidations;
  320. /* ---
  321. * Position in one of three lists:
  322. * * list of subtransactions if we are *known* to be subxact
  323. * * list of toplevel xacts (can be an as-yet unknown subxact)
  324. * * list of preallocated ReorderBufferTXNs (if unused)
  325. * ---
  326. */
  327. dlist_node node;
  328. /*
  329. * Size of this transaction (changes currently in memory, in bytes).
  330. */
  331. Size size;
  332. /* Size of top-transaction including sub-transactions. */
  333. Size total_size;
  334. /* If we have detected concurrent abort then ignore future changes. */
  335. bool concurrent_abort;
  336. /*
  337. * Private data pointer of the output plugin.
  338. */
  339. void *output_plugin_private;
  340. } ReorderBufferTXN;
  341. /* so we can define the callbacks used inside struct ReorderBuffer itself */
  342. typedef struct ReorderBuffer ReorderBuffer;
  343. /* change callback signature */
  344. typedef void (*ReorderBufferApplyChangeCB) (ReorderBuffer *rb,
  345. ReorderBufferTXN *txn,
  346. Relation relation,
  347. ReorderBufferChange *change);
  348. /* truncate callback signature */
  349. typedef void (*ReorderBufferApplyTruncateCB) (ReorderBuffer *rb,
  350. ReorderBufferTXN *txn,
  351. int nrelations,
  352. Relation relations[],
  353. ReorderBufferChange *change);
  354. /* begin callback signature */
  355. typedef void (*ReorderBufferBeginCB) (ReorderBuffer *rb,
  356. ReorderBufferTXN *txn);
  357. /* commit callback signature */
  358. typedef void (*ReorderBufferCommitCB) (ReorderBuffer *rb,
  359. ReorderBufferTXN *txn,
  360. XLogRecPtr commit_lsn);
  361. /* message callback signature */
  362. typedef void (*ReorderBufferMessageCB) (ReorderBuffer *rb,
  363. ReorderBufferTXN *txn,
  364. XLogRecPtr message_lsn,
  365. bool transactional,
  366. const char *prefix, Size sz,
  367. const char *message);
  368. /* begin prepare callback signature */
  369. typedef void (*ReorderBufferBeginPrepareCB) (ReorderBuffer *rb,
  370. ReorderBufferTXN *txn);
  371. /* prepare callback signature */
  372. typedef void (*ReorderBufferPrepareCB) (ReorderBuffer *rb,
  373. ReorderBufferTXN *txn,
  374. XLogRecPtr prepare_lsn);
  375. /* commit prepared callback signature */
  376. typedef void (*ReorderBufferCommitPreparedCB) (ReorderBuffer *rb,
  377. ReorderBufferTXN *txn,
  378. XLogRecPtr commit_lsn);
  379. /* rollback prepared callback signature */
  380. typedef void (*ReorderBufferRollbackPreparedCB) (ReorderBuffer *rb,
  381. ReorderBufferTXN *txn,
  382. XLogRecPtr prepare_end_lsn,
  383. TimestampTz prepare_time);
  384. /* start streaming transaction callback signature */
  385. typedef void (*ReorderBufferStreamStartCB) (
  386. ReorderBuffer *rb,
  387. ReorderBufferTXN *txn,
  388. XLogRecPtr first_lsn);
  389. /* stop streaming transaction callback signature */
  390. typedef void (*ReorderBufferStreamStopCB) (
  391. ReorderBuffer *rb,
  392. ReorderBufferTXN *txn,
  393. XLogRecPtr last_lsn);
  394. /* discard streamed transaction callback signature */
  395. typedef void (*ReorderBufferStreamAbortCB) (
  396. ReorderBuffer *rb,
  397. ReorderBufferTXN *txn,
  398. XLogRecPtr abort_lsn);
  399. /* prepare streamed transaction callback signature */
  400. typedef void (*ReorderBufferStreamPrepareCB) (
  401. ReorderBuffer *rb,
  402. ReorderBufferTXN *txn,
  403. XLogRecPtr prepare_lsn);
  404. /* commit streamed transaction callback signature */
  405. typedef void (*ReorderBufferStreamCommitCB) (
  406. ReorderBuffer *rb,
  407. ReorderBufferTXN *txn,
  408. XLogRecPtr commit_lsn);
  409. /* stream change callback signature */
  410. typedef void (*ReorderBufferStreamChangeCB) (
  411. ReorderBuffer *rb,
  412. ReorderBufferTXN *txn,
  413. Relation relation,
  414. ReorderBufferChange *change);
  415. /* stream message callback signature */
  416. typedef void (*ReorderBufferStreamMessageCB) (
  417. ReorderBuffer *rb,
  418. ReorderBufferTXN *txn,
  419. XLogRecPtr message_lsn,
  420. bool transactional,
  421. const char *prefix, Size sz,
  422. const char *message);
  423. /* stream truncate callback signature */
  424. typedef void (*ReorderBufferStreamTruncateCB) (
  425. ReorderBuffer *rb,
  426. ReorderBufferTXN *txn,
  427. int nrelations,
  428. Relation relations[],
  429. ReorderBufferChange *change);
  430. struct ReorderBuffer
  431. {
  432. /*
  433. * xid => ReorderBufferTXN lookup table
  434. */
  435. HTAB *by_txn;
  436. /*
  437. * Transactions that could be a toplevel xact, ordered by LSN of the first
  438. * record bearing that xid.
  439. */
  440. dlist_head toplevel_by_lsn;
  441. /*
  442. * Transactions and subtransactions that have a base snapshot, ordered by
  443. * LSN of the record which caused us to first obtain the base snapshot.
  444. * This is not the same as toplevel_by_lsn, because we only set the base
  445. * snapshot on the first logical-decoding-relevant record (eg. heap
  446. * writes), whereas the initial LSN could be set by other operations.
  447. */
  448. dlist_head txns_by_base_snapshot_lsn;
  449. /*
  450. * one-entry sized cache for by_txn. Very frequently the same txn gets
  451. * looked up over and over again.
  452. */
  453. TransactionId by_txn_last_xid;
  454. ReorderBufferTXN *by_txn_last_txn;
  455. /*
  456. * Callbacks to be called when a transactions commits.
  457. */
  458. ReorderBufferBeginCB begin;
  459. ReorderBufferApplyChangeCB apply_change;
  460. ReorderBufferApplyTruncateCB apply_truncate;
  461. ReorderBufferCommitCB commit;
  462. ReorderBufferMessageCB message;
  463. /*
  464. * Callbacks to be called when streaming a transaction at prepare time.
  465. */
  466. ReorderBufferBeginCB begin_prepare;
  467. ReorderBufferPrepareCB prepare;
  468. ReorderBufferCommitPreparedCB commit_prepared;
  469. ReorderBufferRollbackPreparedCB rollback_prepared;
  470. /*
  471. * Callbacks to be called when streaming a transaction.
  472. */
  473. ReorderBufferStreamStartCB stream_start;
  474. ReorderBufferStreamStopCB stream_stop;
  475. ReorderBufferStreamAbortCB stream_abort;
  476. ReorderBufferStreamPrepareCB stream_prepare;
  477. ReorderBufferStreamCommitCB stream_commit;
  478. ReorderBufferStreamChangeCB stream_change;
  479. ReorderBufferStreamMessageCB stream_message;
  480. ReorderBufferStreamTruncateCB stream_truncate;
  481. /*
  482. * Pointer that will be passed untouched to the callbacks.
  483. */
  484. void *private_data;
  485. /*
  486. * Saved output plugin option
  487. */
  488. bool output_rewrites;
  489. /*
  490. * Private memory context.
  491. */
  492. MemoryContext context;
  493. /*
  494. * Memory contexts for specific types objects
  495. */
  496. MemoryContext change_context;
  497. MemoryContext txn_context;
  498. MemoryContext tup_context;
  499. XLogRecPtr current_restart_decoding_lsn;
  500. /* buffer for disk<->memory conversions */
  501. char *outbuf;
  502. Size outbufsize;
  503. /* memory accounting */
  504. Size size;
  505. /*
  506. * Statistics about transactions spilled to disk.
  507. *
  508. * A single transaction may be spilled repeatedly, which is why we keep
  509. * two different counters. For spilling, the transaction counter includes
  510. * both toplevel transactions and subtransactions.
  511. */
  512. int64 spillTxns; /* number of transactions spilled to disk */
  513. int64 spillCount; /* spill-to-disk invocation counter */
  514. int64 spillBytes; /* amount of data spilled to disk */
  515. /* Statistics about transactions streamed to the decoding output plugin */
  516. int64 streamTxns; /* number of transactions streamed */
  517. int64 streamCount; /* streaming invocation counter */
  518. int64 streamBytes; /* amount of data decoded */
  519. /*
  520. * Statistics about all the transactions sent to the decoding output
  521. * plugin
  522. */
  523. int64 totalTxns; /* total number of transactions sent */
  524. int64 totalBytes; /* total amount of data decoded */
  525. };
  526. extern ReorderBuffer *ReorderBufferAllocate(void);
  527. extern void ReorderBufferFree(ReorderBuffer *);
  528. extern ReorderBufferTupleBuf *ReorderBufferGetTupleBuf(ReorderBuffer *, Size tuple_len);
  529. extern void ReorderBufferReturnTupleBuf(ReorderBuffer *, ReorderBufferTupleBuf *tuple);
  530. extern ReorderBufferChange *ReorderBufferGetChange(ReorderBuffer *);
  531. extern void ReorderBufferReturnChange(ReorderBuffer *, ReorderBufferChange *, bool);
  532. extern Oid *ReorderBufferGetRelids(ReorderBuffer *, int nrelids);
  533. extern void ReorderBufferReturnRelids(ReorderBuffer *, Oid *relids);
  534. extern void ReorderBufferQueueChange(ReorderBuffer *, TransactionId,
  535. XLogRecPtr lsn, ReorderBufferChange *,
  536. bool toast_insert);
  537. extern void ReorderBufferQueueMessage(ReorderBuffer *, TransactionId, Snapshot snapshot, XLogRecPtr lsn,
  538. bool transactional, const char *prefix,
  539. Size message_size, const char *message);
  540. extern void ReorderBufferCommit(ReorderBuffer *, TransactionId,
  541. XLogRecPtr commit_lsn, XLogRecPtr end_lsn,
  542. TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn);
  543. extern void ReorderBufferFinishPrepared(ReorderBuffer *rb, TransactionId xid,
  544. XLogRecPtr commit_lsn, XLogRecPtr end_lsn,
  545. XLogRecPtr two_phase_at,
  546. TimestampTz commit_time,
  547. RepOriginId origin_id, XLogRecPtr origin_lsn,
  548. char *gid, bool is_commit);
  549. extern void ReorderBufferAssignChild(ReorderBuffer *, TransactionId, TransactionId, XLogRecPtr commit_lsn);
  550. extern void ReorderBufferCommitChild(ReorderBuffer *, TransactionId, TransactionId,
  551. XLogRecPtr commit_lsn, XLogRecPtr end_lsn);
  552. extern void ReorderBufferAbort(ReorderBuffer *, TransactionId, XLogRecPtr lsn);
  553. extern void ReorderBufferAbortOld(ReorderBuffer *, TransactionId xid);
  554. extern void ReorderBufferForget(ReorderBuffer *, TransactionId, XLogRecPtr lsn);
  555. extern void ReorderBufferInvalidate(ReorderBuffer *, TransactionId, XLogRecPtr lsn);
  556. extern void ReorderBufferSetBaseSnapshot(ReorderBuffer *, TransactionId, XLogRecPtr lsn, struct SnapshotData *snap);
  557. extern void ReorderBufferAddSnapshot(ReorderBuffer *, TransactionId, XLogRecPtr lsn, struct SnapshotData *snap);
  558. extern void ReorderBufferAddNewCommandId(ReorderBuffer *, TransactionId, XLogRecPtr lsn,
  559. CommandId cid);
  560. extern void ReorderBufferAddNewTupleCids(ReorderBuffer *, TransactionId, XLogRecPtr lsn,
  561. RelFileNode node, ItemPointerData pt,
  562. CommandId cmin, CommandId cmax, CommandId combocid);
  563. extern void ReorderBufferAddInvalidations(ReorderBuffer *, TransactionId, XLogRecPtr lsn,
  564. Size nmsgs, SharedInvalidationMessage *msgs);
  565. extern void ReorderBufferImmediateInvalidation(ReorderBuffer *, uint32 ninvalidations,
  566. SharedInvalidationMessage *invalidations);
  567. extern void ReorderBufferProcessXid(ReorderBuffer *, TransactionId xid, XLogRecPtr lsn);
  568. extern void ReorderBufferXidSetCatalogChanges(ReorderBuffer *, TransactionId xid, XLogRecPtr lsn);
  569. extern bool ReorderBufferXidHasCatalogChanges(ReorderBuffer *, TransactionId xid);
  570. extern bool ReorderBufferXidHasBaseSnapshot(ReorderBuffer *, TransactionId xid);
  571. extern bool ReorderBufferRememberPrepareInfo(ReorderBuffer *rb, TransactionId xid,
  572. XLogRecPtr prepare_lsn, XLogRecPtr end_lsn,
  573. TimestampTz prepare_time,
  574. RepOriginId origin_id, XLogRecPtr origin_lsn);
  575. extern void ReorderBufferSkipPrepare(ReorderBuffer *rb, TransactionId xid);
  576. extern void ReorderBufferPrepare(ReorderBuffer *rb, TransactionId xid, char *gid);
  577. extern ReorderBufferTXN *ReorderBufferGetOldestTXN(ReorderBuffer *);
  578. extern TransactionId ReorderBufferGetOldestXmin(ReorderBuffer *rb);
  579. extern void ReorderBufferSetRestartPoint(ReorderBuffer *, XLogRecPtr ptr);
  580. extern void StartupReorderBuffer(void);
  581. #endif