PostgreSQL Source Code: src/include/replication/reorderbuffer.h Source File

PostgreSQL Source Code git master
reorderbuffer.h
Go to the documentation of this file.
1/*
2 * reorderbuffer.h
3 * PostgreSQL logical replay/reorder buffer management.
4 *
5 * Copyright (c) 2012-2025, PostgreSQL Global Development Group
6 *
7 * src/include/replication/reorderbuffer.h
8 */
9#ifndef REORDERBUFFER_H
10#define REORDERBUFFER_H
11
12#include "access/htup_details.h"
13#include "lib/ilist.h"
14#include "lib/pairingheap.h"
15#include "storage/sinval.h"
16#include "utils/hsearch.h"
17#include "utils/relcache.h"
18#include "utils/snapshot.h"
19#include "utils/timestamp.h"
20
21/* paths for logical decoding data (relative to installation's $PGDATA) */
22 #define PG_LOGICAL_DIR "pg_logical"
23 #define PG_LOGICAL_MAPPINGS_DIR PG_LOGICAL_DIR "/mappings"
24 #define PG_LOGICAL_SNAPSHOTS_DIR PG_LOGICAL_DIR "/snapshots"
25
26/* GUC variables */
27extern PGDLLIMPORT int logical_decoding_work_mem;
28extern PGDLLIMPORT int debug_logical_replication_streaming;
29
30/* possible values for debug_logical_replication_streaming */
31 typedef enum
32{
33 DEBUG_LOGICAL_REP_STREAMING_BUFFERED,
34 DEBUG_LOGICAL_REP_STREAMING_IMMEDIATE,
35} DebugLogicalRepStreamingMode;
36
37/*
38 * Types of the change passed to a 'change' callback.
39 *
40 * For efficiency and simplicity reasons we want to keep Snapshots, CommandIds
41 * and ComboCids in the same list with the user visible INSERT/UPDATE/DELETE
42 * changes. Users of the decoding facilities will never see changes with
43 * *_INTERNAL_* actions.
44 *
45 * The INTERNAL_SPEC_INSERT and INTERNAL_SPEC_CONFIRM, and INTERNAL_SPEC_ABORT
46 * changes concern "speculative insertions", their confirmation, and abort
47 * respectively. They're used by INSERT .. ON CONFLICT .. UPDATE. Users of
48 * logical decoding don't have to care about these.
49 */
50 typedef enum ReorderBufferChangeType
51{
52 REORDER_BUFFER_CHANGE_INSERT,
53 REORDER_BUFFER_CHANGE_UPDATE,
54 REORDER_BUFFER_CHANGE_DELETE,
55 REORDER_BUFFER_CHANGE_MESSAGE,
56 REORDER_BUFFER_CHANGE_INVALIDATION,
57 REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT,
58 REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID,
59 REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID,
60 REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT,
61 REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM,
62 REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT,
63 REORDER_BUFFER_CHANGE_TRUNCATE,
64 } ReorderBufferChangeType;
65
66/* forward declaration */
67struct ReorderBufferTXN;
68
69/*
70 * a single 'change', can be an insert (with one tuple), an update (old, new),
71 * or a delete (old).
72 *
73 * The same struct is also used internally for other purposes but that should
74 * never be visible outside reorderbuffer.c.
75 */
76 typedef struct ReorderBufferChange
77{
78 XLogRecPtr lsn;
79
80 /* The type of change. */
81 ReorderBufferChangeType action;
82
83 /* Transaction this change belongs to. */
84 struct ReorderBufferTXN *txn;
85
86 RepOriginId origin_id;
87
88 /*
89 * Context data for the change. Which part of the union is valid depends
90 * on action.
91 */
92 union
93 {
94 /* Old, new tuples when action == *_INSERT|UPDATE|DELETE */
95 struct
96 {
97 /* relation that has been changed */
98 RelFileLocator rlocator;
99
100 /* no previously reassembled toast chunks are necessary anymore */
101 bool clear_toast_afterwards;
102
103 /* valid for DELETE || UPDATE */
104 HeapTuple oldtuple;
105 /* valid for INSERT || UPDATE */
106 HeapTuple newtuple;
107 } tp;
108
109 /*
110 * Truncate data for REORDER_BUFFER_CHANGE_TRUNCATE representing one
111 * set of relations to be truncated.
112 */
113 struct
114 {
115 Size nrelids;
116 bool cascade;
117 bool restart_seqs;
118 Oid *relids;
119 } truncate;
120
121 /* Message with arbitrary data. */
122 struct
123 {
124 char *prefix;
125 Size message_size;
126 char *message;
127 } msg;
128
129 /* New snapshot, set when action == *_INTERNAL_SNAPSHOT */
130 Snapshot snapshot;
131
132 /*
133 * New command id for existing snapshot in a catalog changing tx. Set
134 * when action == *_INTERNAL_COMMAND_ID.
135 */
136 CommandId command_id;
137
138 /*
139 * New cid mapping for catalog changing transaction, set when action
140 * == *_INTERNAL_TUPLECID.
141 */
142 struct
143 {
144 RelFileLocator locator;
145 ItemPointerData tid;
146 CommandId cmin;
147 CommandId cmax;
148 CommandId combocid;
149 } tuplecid;
150
151 /* Invalidation. */
152 struct
153 {
154 uint32 ninvalidations; /* Number of messages */
155 SharedInvalidationMessage *invalidations; /* invalidation message */
156 } inval;
157 } data;
158
159 /*
160 * While in use this is how a change is linked into a transactions,
161 * otherwise it's the preallocated list.
162 */
163 dlist_node node;
164 } ReorderBufferChange;
165
166/* ReorderBufferTXN txn_flags */
167 #define RBTXN_HAS_CATALOG_CHANGES 0x0001
168 #define RBTXN_IS_SUBXACT 0x0002
169 #define RBTXN_IS_SERIALIZED 0x0004
170 #define RBTXN_IS_SERIALIZED_CLEAR 0x0008
171 #define RBTXN_IS_STREAMED 0x0010
172 #define RBTXN_HAS_PARTIAL_CHANGE 0x0020
173 #define RBTXN_IS_PREPARED 0x0040
174 #define RBTXN_SKIPPED_PREPARE 0x0080
175 #define RBTXN_HAS_STREAMABLE_CHANGE 0x0100
176 #define RBTXN_SENT_PREPARE 0x0200
177 #define RBTXN_IS_COMMITTED 0x0400
178 #define RBTXN_IS_ABORTED 0x0800
179 #define RBTXN_DISTR_INVAL_OVERFLOWED 0x1000
180
181 #define RBTXN_PREPARE_STATUS_MASK (RBTXN_IS_PREPARED | RBTXN_SKIPPED_PREPARE | RBTXN_SENT_PREPARE)
182
183/* Does the transaction have catalog changes? */
184 #define rbtxn_has_catalog_changes(txn) \
185( \
186 ((txn)->txn_flags & RBTXN_HAS_CATALOG_CHANGES) != 0 \
187)
188
189/* Is the transaction known as a subxact? */
190 #define rbtxn_is_known_subxact(txn) \
191( \
192 ((txn)->txn_flags & RBTXN_IS_SUBXACT) != 0 \
193)
194
195/* Has this transaction been spilled to disk? */
196 #define rbtxn_is_serialized(txn) \
197( \
198 ((txn)->txn_flags & RBTXN_IS_SERIALIZED) != 0 \
199)
200
201/* Has this transaction ever been spilled to disk? */
202 #define rbtxn_is_serialized_clear(txn) \
203( \
204 ((txn)->txn_flags & RBTXN_IS_SERIALIZED_CLEAR) != 0 \
205)
206
207/* Does this transaction contain partial changes? */
208 #define rbtxn_has_partial_change(txn) \
209( \
210 ((txn)->txn_flags & RBTXN_HAS_PARTIAL_CHANGE) != 0 \
211)
212
213/* Does this transaction contain streamable changes? */
214 #define rbtxn_has_streamable_change(txn) \
215( \
216 ((txn)->txn_flags & RBTXN_HAS_STREAMABLE_CHANGE) != 0 \
217)
218
219/*
220 * Has this transaction been streamed to downstream?
221 *
222 * (It's not possible to deduce this from nentries and nentries_mem for
223 * various reasons. For example, all changes may be in subtransactions in
224 * which case we'd have nentries==0 for the toplevel one, which would say
225 * nothing about the streaming. So we maintain this flag, but only for the
226 * toplevel transaction.)
227 */
228 #define rbtxn_is_streamed(txn) \
229( \
230 ((txn)->txn_flags & RBTXN_IS_STREAMED) != 0 \
231)
232
233/*
234 * Is this a prepared transaction?
235 *
236 * Being true means that this transaction should be prepared instead of
237 * committed. To check whether a prepare or a stream_prepare has already
238 * been sent for this transaction, we need to use rbtxn_sent_prepare().
239 */
240 #define rbtxn_is_prepared(txn) \
241( \
242 ((txn)->txn_flags & RBTXN_IS_PREPARED) != 0 \
243)
244
245/* Has a prepare or stream_prepare already been sent? */
246 #define rbtxn_sent_prepare(txn) \
247( \
248 ((txn)->txn_flags & RBTXN_SENT_PREPARE) != 0 \
249)
250
251/* Is this transaction committed? */
252 #define rbtxn_is_committed(txn) \
253( \
254 ((txn)->txn_flags & RBTXN_IS_COMMITTED) != 0 \
255)
256
257/* Is this transaction aborted? */
258 #define rbtxn_is_aborted(txn) \
259( \
260 ((txn)->txn_flags & RBTXN_IS_ABORTED) != 0 \
261)
262
263/* prepare for this transaction skipped? */
264 #define rbtxn_skip_prepared(txn) \
265( \
266 ((txn)->txn_flags & RBTXN_SKIPPED_PREPARE) != 0 \
267)
268
269/* Is the array of distributed inval messages overflowed? */
270 #define rbtxn_distr_inval_overflowed(txn) \
271( \
272 ((txn)->txn_flags & RBTXN_DISTR_INVAL_OVERFLOWED) != 0 \
273)
274
275/* Is this a top-level transaction? */
276 #define rbtxn_is_toptxn(txn) \
277( \
278 (txn)->toptxn == NULL \
279)
280
281/* Is this a subtransaction? */
282 #define rbtxn_is_subtxn(txn) \
283( \
284 (txn)->toptxn != NULL \
285)
286
287/* Get the top-level transaction of this (sub)transaction. */
288 #define rbtxn_get_toptxn(txn) \
289( \
290 rbtxn_is_subtxn(txn) ? (txn)->toptxn : (txn) \
291)
292
293 typedef struct ReorderBufferTXN
294{
295 /* See above */
296 bits32 txn_flags;
297
298 /* The transaction's transaction id, can be a toplevel or sub xid. */
299 TransactionId xid;
300
301 /* Xid of top-level transaction, if known */
302 TransactionId toplevel_xid;
303
304 /*
305 * Global transaction id required for identification of prepared
306 * transactions.
307 */
308 char *gid;
309
310 /*
311 * LSN of the first data carrying, WAL record with knowledge about this
312 * xid. This is allowed to *not* be first record adorned with this xid, if
313 * the previous records aren't relevant for logical decoding.
314 */
315 XLogRecPtr first_lsn;
316
317 /* ----
318 * LSN of the record that lead to this xact to be prepared or committed or
319 * aborted. This can be a
320 * * plain commit record
321 * * plain commit record, of a parent transaction
322 * * prepared transaction
323 * * prepared transaction commit
324 * * plain abort record
325 * * prepared transaction abort
326 *
327 * This can also become set to earlier values than transaction end when
328 * a transaction is spilled to disk; specifically it's set to the LSN of
329 * the latest change written to disk so far.
330 * ----
331 */
332 XLogRecPtr final_lsn;
333
334 /*
335 * LSN pointing to the end of the commit record + 1.
336 */
337 XLogRecPtr end_lsn;
338
339 /* Toplevel transaction for this subxact (NULL for top-level). */
340 struct ReorderBufferTXN *toptxn;
341
342 /*
343 * LSN of the last lsn at which snapshot information reside, so we can
344 * restart decoding from there and fully recover this transaction from
345 * WAL.
346 */
347 XLogRecPtr restart_decoding_lsn;
348
349 /* origin of the change that caused this transaction */
350 RepOriginId origin_id;
351 XLogRecPtr origin_lsn;
352
353 /*
354 * Commit or Prepare time, only known when we read the actual commit or
355 * prepare record.
356 */
357 union
358 {
359 TimestampTz commit_time;
360 TimestampTz prepare_time;
361 TimestampTz abort_time;
362 };
363
364 /*
365 * The base snapshot is used to decode all changes until either this
366 * transaction modifies the catalog, or another catalog-modifying
367 * transaction commits.
368 */
369 Snapshot base_snapshot;
370 XLogRecPtr base_snapshot_lsn;
371 dlist_node base_snapshot_node; /* link in txns_by_base_snapshot_lsn */
372
373 /*
374 * Snapshot/CID from the previous streaming run. Only valid for already
375 * streamed transactions (NULL/InvalidCommandId otherwise).
376 */
377 Snapshot snapshot_now;
378 CommandId command_id;
379
380 /*
381 * How many ReorderBufferChange's do we have in this txn.
382 *
383 * Changes in subtransactions are *not* included but tracked separately.
384 */
385 uint64 nentries;
386
387 /*
388 * How many of the above entries are stored in memory in contrast to being
389 * spilled to disk.
390 */
391 uint64 nentries_mem;
392
393 /*
394 * List of ReorderBufferChange structs, including new Snapshots, new
395 * CommandIds and command invalidation messages.
396 */
397 dlist_head changes;
398
399 /*
400 * List of (relation, ctid) => (cmin, cmax) mappings for catalog tuples.
401 * Those are always assigned to the toplevel transaction. (Keep track of
402 * #entries to create a hash of the right size)
403 */
404 dlist_head tuplecids;
405 uint64 ntuplecids;
406
407 /*
408 * On-demand built hash for looking up the above values.
409 */
410 HTAB *tuplecid_hash;
411
412 /*
413 * Hash containing (potentially partial) toast entries. NULL if no toast
414 * tuples have been found for the current change.
415 */
416 HTAB *toast_hash;
417
418 /*
419 * non-hierarchical list of subtransactions that are *not* aborted. Only
420 * used in toplevel transactions.
421 */
422 dlist_head subtxns;
423 uint32 nsubtxns;
424
425 /*
426 * Stored cache invalidations. This is not a linked list because we get
427 * all the invalidations at once.
428 */
429 uint32 ninvalidations;
430 SharedInvalidationMessage *invalidations;
431
432 /*
433 * Stores cache invalidation messages distributed by other transactions.
434 */
435 uint32 ninvalidations_distributed;
436 SharedInvalidationMessage *invalidations_distributed;
437
438 /* ---
439 * Position in one of two lists:
440 * * list of subtransactions if we are *known* to be subxact
441 * * list of toplevel xacts (can be an as-yet unknown subxact)
442 * ---
443 */
444 dlist_node node;
445
446 /*
447 * A node in the list of catalog modifying transactions
448 */
449 dlist_node catchange_node;
450
451 /*
452 * A node in txn_heap
453 */
454 pairingheap_node txn_node;
455
456 /*
457 * Size of this transaction (changes currently in memory, in bytes).
458 */
459 Size size;
460
461 /* Size of top-transaction including sub-transactions. */
462 Size total_size;
463
464 /*
465 * Private data pointer of the output plugin.
466 */
467 void *output_plugin_private;
468 } ReorderBufferTXN;
469
470/* so we can define the callbacks used inside struct ReorderBuffer itself */
471 typedef struct ReorderBuffer ReorderBuffer;
472
473/* change callback signature */
474 typedef void (*ReorderBufferApplyChangeCB) (ReorderBuffer *rb,
475 ReorderBufferTXN *txn,
476 Relation relation,
477 ReorderBufferChange *change);
478
479/* truncate callback signature */
480 typedef void (*ReorderBufferApplyTruncateCB) (ReorderBuffer *rb,
481 ReorderBufferTXN *txn,
482 int nrelations,
483 Relation relations[],
484 ReorderBufferChange *change);
485
486/* begin callback signature */
487 typedef void (*ReorderBufferBeginCB) (ReorderBuffer *rb,
488 ReorderBufferTXN *txn);
489
490/* commit callback signature */
491 typedef void (*ReorderBufferCommitCB) (ReorderBuffer *rb,
492 ReorderBufferTXN *txn,
493 XLogRecPtr commit_lsn);
494
495/* message callback signature */
496 typedef void (*ReorderBufferMessageCB) (ReorderBuffer *rb,
497 ReorderBufferTXN *txn,
498 XLogRecPtr message_lsn,
499 bool transactional,
500 const char *prefix, Size sz,
501 const char *message);
502
503/* begin prepare callback signature */
504 typedef void (*ReorderBufferBeginPrepareCB) (ReorderBuffer *rb,
505 ReorderBufferTXN *txn);
506
507/* prepare callback signature */
508 typedef void (*ReorderBufferPrepareCB) (ReorderBuffer *rb,
509 ReorderBufferTXN *txn,
510 XLogRecPtr prepare_lsn);
511
512/* commit prepared callback signature */
513 typedef void (*ReorderBufferCommitPreparedCB) (ReorderBuffer *rb,
514 ReorderBufferTXN *txn,
515 XLogRecPtr commit_lsn);
516
517/* rollback prepared callback signature */
518 typedef void (*ReorderBufferRollbackPreparedCB) (ReorderBuffer *rb,
519 ReorderBufferTXN *txn,
520 XLogRecPtr prepare_end_lsn,
521 TimestampTz prepare_time);
522
523/* start streaming transaction callback signature */
524 typedef void (*ReorderBufferStreamStartCB) (ReorderBuffer *rb,
525 ReorderBufferTXN *txn,
526 XLogRecPtr first_lsn);
527
528/* stop streaming transaction callback signature */
529 typedef void (*ReorderBufferStreamStopCB) (ReorderBuffer *rb,
530 ReorderBufferTXN *txn,
531 XLogRecPtr last_lsn);
532
533/* discard streamed transaction callback signature */
534 typedef void (*ReorderBufferStreamAbortCB) (ReorderBuffer *rb,
535 ReorderBufferTXN *txn,
536 XLogRecPtr abort_lsn);
537
538/* prepare streamed transaction callback signature */
539 typedef void (*ReorderBufferStreamPrepareCB) (ReorderBuffer *rb,
540 ReorderBufferTXN *txn,
541 XLogRecPtr prepare_lsn);
542
543/* commit streamed transaction callback signature */
544 typedef void (*ReorderBufferStreamCommitCB) (ReorderBuffer *rb,
545 ReorderBufferTXN *txn,
546 XLogRecPtr commit_lsn);
547
548/* stream change callback signature */
549 typedef void (*ReorderBufferStreamChangeCB) (ReorderBuffer *rb,
550 ReorderBufferTXN *txn,
551 Relation relation,
552 ReorderBufferChange *change);
553
554/* stream message callback signature */
555 typedef void (*ReorderBufferStreamMessageCB) (ReorderBuffer *rb,
556 ReorderBufferTXN *txn,
557 XLogRecPtr message_lsn,
558 bool transactional,
559 const char *prefix, Size sz,
560 const char *message);
561
562/* stream truncate callback signature */
563 typedef void (*ReorderBufferStreamTruncateCB) (ReorderBuffer *rb,
564 ReorderBufferTXN *txn,
565 int nrelations,
566 Relation relations[],
567 ReorderBufferChange *change);
568
569/* update progress txn callback signature */
570 typedef void (*ReorderBufferUpdateProgressTxnCB) (ReorderBuffer *rb,
571 ReorderBufferTXN *txn,
572 XLogRecPtr lsn);
573
574 struct ReorderBuffer
575{
576 /*
577 * xid => ReorderBufferTXN lookup table
578 */
579 HTAB *by_txn;
580
581 /*
582 * Transactions that could be a toplevel xact, ordered by LSN of the first
583 * record bearing that xid.
584 */
585 dlist_head toplevel_by_lsn;
586
587 /*
588 * Transactions and subtransactions that have a base snapshot, ordered by
589 * LSN of the record which caused us to first obtain the base snapshot.
590 * This is not the same as toplevel_by_lsn, because we only set the base
591 * snapshot on the first logical-decoding-relevant record (eg. heap
592 * writes), whereas the initial LSN could be set by other operations.
593 */
594 dlist_head txns_by_base_snapshot_lsn;
595
596 /*
597 * Transactions and subtransactions that have modified system catalogs.
598 */
599 dclist_head catchange_txns;
600
601 /*
602 * one-entry sized cache for by_txn. Very frequently the same txn gets
603 * looked up over and over again.
604 */
605 TransactionId by_txn_last_xid;
606 ReorderBufferTXN *by_txn_last_txn;
607
608 /*
609 * Callbacks to be called when a transactions commits.
610 */
611 ReorderBufferBeginCB begin;
612 ReorderBufferApplyChangeCB apply_change;
613 ReorderBufferApplyTruncateCB apply_truncate;
614 ReorderBufferCommitCB commit;
615 ReorderBufferMessageCB message;
616
617 /*
618 * Callbacks to be called when streaming a transaction at prepare time.
619 */
620 ReorderBufferBeginCB begin_prepare;
621 ReorderBufferPrepareCB prepare;
622 ReorderBufferCommitPreparedCB commit_prepared;
623 ReorderBufferRollbackPreparedCB rollback_prepared;
624
625 /*
626 * Callbacks to be called when streaming a transaction.
627 */
628 ReorderBufferStreamStartCB stream_start;
629 ReorderBufferStreamStopCB stream_stop;
630 ReorderBufferStreamAbortCB stream_abort;
631 ReorderBufferStreamPrepareCB stream_prepare;
632 ReorderBufferStreamCommitCB stream_commit;
633 ReorderBufferStreamChangeCB stream_change;
634 ReorderBufferStreamMessageCB stream_message;
635 ReorderBufferStreamTruncateCB stream_truncate;
636
637 /*
638 * Callback to be called when updating progress during sending data of a
639 * transaction (and its subtransactions) to the output plugin.
640 */
641 ReorderBufferUpdateProgressTxnCB update_progress_txn;
642
643 /*
644 * Pointer that will be passed untouched to the callbacks.
645 */
646 void *private_data;
647
648 /*
649 * Saved output plugin option
650 */
651 bool output_rewrites;
652
653 /*
654 * Private memory context.
655 */
656 MemoryContext context;
657
658 /*
659 * Memory contexts for specific types objects
660 */
661 MemoryContext change_context;
662 MemoryContext txn_context;
663 MemoryContext tup_context;
664
665 XLogRecPtr current_restart_decoding_lsn;
666
667 /* buffer for disk<->memory conversions */
668 char *outbuf;
669 Size outbufsize;
670
671 /* memory accounting */
672 Size size;
673
674 /* Max-heap for sizes of all top-level and sub transactions */
675 pairingheap *txn_heap;
676
677 /*
678 * Statistics about transactions spilled to disk.
679 *
680 * A single transaction may be spilled repeatedly, which is why we keep
681 * two different counters. For spilling, the transaction counter includes
682 * both toplevel transactions and subtransactions.
683 */
684 int64 spillTxns; /* number of transactions spilled to disk */
685 int64 spillCount; /* spill-to-disk invocation counter */
686 int64 spillBytes; /* amount of data spilled to disk */
687
688 /* Statistics about transactions streamed to the decoding output plugin */
689 int64 streamTxns; /* number of transactions streamed */
690 int64 streamCount; /* streaming invocation counter */
691 int64 streamBytes; /* amount of data decoded */
692
693 /*
694 * Statistics about all the transactions sent to the decoding output
695 * plugin
696 */
697 int64 totalTxns; /* total number of transactions sent */
698 int64 totalBytes; /* total amount of data decoded */
699};
700
701
702extern ReorderBuffer *ReorderBufferAllocate(void);
703extern void ReorderBufferFree(ReorderBuffer *rb);
704
705extern HeapTuple ReorderBufferAllocTupleBuf(ReorderBuffer *rb, Size tuple_len);
706extern void ReorderBufferFreeTupleBuf(HeapTuple tuple);
707
708extern ReorderBufferChange *ReorderBufferAllocChange(ReorderBuffer *rb);
709extern void ReorderBufferFreeChange(ReorderBuffer *rb,
710 ReorderBufferChange *change, bool upd_mem);
711
712extern Oid *ReorderBufferAllocRelids(ReorderBuffer *rb, int nrelids);
713extern void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids);
714
715extern void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid,
716 XLogRecPtr lsn, ReorderBufferChange *change,
717 bool toast_insert);
718extern void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid,
719 Snapshot snap, XLogRecPtr lsn,
720 bool transactional, const char *prefix,
721 Size message_size, const char *message);
722extern void ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
723 XLogRecPtr commit_lsn, XLogRecPtr end_lsn,
724 TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn);
725extern void ReorderBufferFinishPrepared(ReorderBuffer *rb, TransactionId xid,
726 XLogRecPtr commit_lsn, XLogRecPtr end_lsn,
727 XLogRecPtr two_phase_at,
728 TimestampTz commit_time,
729 RepOriginId origin_id, XLogRecPtr origin_lsn,
730 char *gid, bool is_commit);
731extern void ReorderBufferAssignChild(ReorderBuffer *rb, TransactionId xid,
732 TransactionId subxid, XLogRecPtr lsn);
733extern void ReorderBufferCommitChild(ReorderBuffer *rb, TransactionId xid,
734 TransactionId subxid, XLogRecPtr commit_lsn,
735 XLogRecPtr end_lsn);
736extern void ReorderBufferAbort(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn,
737 TimestampTz abort_time);
738extern void ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid);
739extern void ReorderBufferForget(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn);
740extern void ReorderBufferInvalidate(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn);
741
742extern void ReorderBufferSetBaseSnapshot(ReorderBuffer *rb, TransactionId xid,
743 XLogRecPtr lsn, Snapshot snap);
744extern void ReorderBufferAddSnapshot(ReorderBuffer *rb, TransactionId xid,
745 XLogRecPtr lsn, Snapshot snap);
746extern void ReorderBufferAddNewCommandId(ReorderBuffer *rb, TransactionId xid,
747 XLogRecPtr lsn, CommandId cid);
748extern void ReorderBufferAddNewTupleCids(ReorderBuffer *rb, TransactionId xid,
749 XLogRecPtr lsn, RelFileLocator locator,
750 ItemPointerData tid,
751 CommandId cmin, CommandId cmax, CommandId combocid);
752extern void ReorderBufferAddInvalidations(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn,
753 Size nmsgs, SharedInvalidationMessage *msgs);
754extern void ReorderBufferAddDistributedInvalidations(ReorderBuffer *rb, TransactionId xid,
755 XLogRecPtr lsn, Size nmsgs,
756 SharedInvalidationMessage *msgs);
757extern void ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations,
758 SharedInvalidationMessage *invalidations);
759extern void ReorderBufferProcessXid(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn);
760
761extern void ReorderBufferXidSetCatalogChanges(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn);
762extern bool ReorderBufferXidHasCatalogChanges(ReorderBuffer *rb, TransactionId xid);
763extern bool ReorderBufferXidHasBaseSnapshot(ReorderBuffer *rb, TransactionId xid);
764
765extern bool ReorderBufferRememberPrepareInfo(ReorderBuffer *rb, TransactionId xid,
766 XLogRecPtr prepare_lsn, XLogRecPtr end_lsn,
767 TimestampTz prepare_time,
768 RepOriginId origin_id, XLogRecPtr origin_lsn);
769extern void ReorderBufferSkipPrepare(ReorderBuffer *rb, TransactionId xid);
770extern void ReorderBufferPrepare(ReorderBuffer *rb, TransactionId xid, char *gid);
771extern ReorderBufferTXN *ReorderBufferGetOldestTXN(ReorderBuffer *rb);
772extern TransactionId ReorderBufferGetOldestXmin(ReorderBuffer *rb);
773extern TransactionId *ReorderBufferGetCatalogChangesXacts(ReorderBuffer *rb);
774
775extern void ReorderBufferSetRestartPoint(ReorderBuffer *rb, XLogRecPtr ptr);
776
777extern uint32 ReorderBufferGetInvalidations(ReorderBuffer *rb,
778 TransactionId xid,
779 SharedInvalidationMessage **msgs);
780
781extern void StartupReorderBuffer(void);
782
783#endif
#define PGDLLIMPORT
Definition: c.h:1319
int64_t int64
Definition: c.h:535
uint32 bits32
Definition: c.h:547
uint64_t uint64
Definition: c.h:539
uint32_t uint32
Definition: c.h:538
uint32 CommandId
Definition: c.h:671
uint32 TransactionId
Definition: c.h:657
size_t Size
Definition: c.h:610
int64 TimestampTz
Definition: timestamp.h:39
unsigned int Oid
Definition: postgres_ext.h:32
void ReorderBufferFreeRelids(ReorderBuffer *rb, Oid *relids)
Definition: reorderbuffer.c:640
void ReorderBufferFreeChange(ReorderBuffer *rb, ReorderBufferChange *change, bool upd_mem)
Definition: reorderbuffer.c:521
void(* ReorderBufferCommitCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: reorderbuffer.h:491
PGDLLIMPORT int logical_decoding_work_mem
Definition: reorderbuffer.c:225
void ReorderBufferXidSetCatalogChanges(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
void ReorderBufferAddNewCommandId(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, CommandId cid)
PGDLLIMPORT int debug_logical_replication_streaming
Definition: reorderbuffer.c:229
void ReorderBufferAddNewTupleCids(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, RelFileLocator locator, ItemPointerData tid, CommandId cmin, CommandId cmax, CommandId combocid)
void ReorderBufferSetBaseSnapshot(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, Snapshot snap)
void ReorderBufferAbort(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, TimestampTz abort_time)
void(* ReorderBufferUpdateProgressTxnCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr lsn)
Definition: reorderbuffer.h:570
void(* ReorderBufferStreamCommitCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: reorderbuffer.h:544
bool ReorderBufferXidHasCatalogChanges(ReorderBuffer *rb, TransactionId xid)
void ReorderBufferInvalidate(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
TransactionId ReorderBufferGetOldestXmin(ReorderBuffer *rb)
void(* ReorderBufferStreamStartCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr first_lsn)
Definition: reorderbuffer.h:524
void(* ReorderBufferApplyChangeCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
Definition: reorderbuffer.h:474
struct ReorderBufferTXN ReorderBufferTXN
void(* ReorderBufferStreamPrepareCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
Definition: reorderbuffer.h:539
void(* ReorderBufferStreamChangeCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
Definition: reorderbuffer.h:549
void ReorderBufferFreeTupleBuf(HeapTuple tuple)
Definition: reorderbuffer.c:609
DebugLogicalRepStreamingMode
Definition: reorderbuffer.h:32
@ DEBUG_LOGICAL_REP_STREAMING_IMMEDIATE
Definition: reorderbuffer.h:34
@ DEBUG_LOGICAL_REP_STREAMING_BUFFERED
Definition: reorderbuffer.h:33
void ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, ReorderBufferChange *change, bool toast_insert)
Definition: reorderbuffer.c:809
void ReorderBufferPrepare(ReorderBuffer *rb, TransactionId xid, char *gid)
uint32 ReorderBufferGetInvalidations(ReorderBuffer *rb, TransactionId xid, SharedInvalidationMessage **msgs)
void(* ReorderBufferCommitPreparedCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: reorderbuffer.h:513
void(* ReorderBufferStreamMessageCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size sz, const char *message)
Definition: reorderbuffer.h:555
void ReorderBufferForget(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
void ReorderBufferCommitChild(ReorderBuffer *rb, TransactionId xid, TransactionId subxid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn)
TransactionId * ReorderBufferGetCatalogChangesXacts(ReorderBuffer *rb)
void(* ReorderBufferBeginCB)(ReorderBuffer *rb, ReorderBufferTXN *txn)
Definition: reorderbuffer.h:487
ReorderBuffer * ReorderBufferAllocate(void)
Definition: reorderbuffer.c:324
void ReorderBufferSkipPrepare(ReorderBuffer *rb, TransactionId xid)
void(* ReorderBufferMessageCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size sz, const char *message)
Definition: reorderbuffer.h:496
struct ReorderBufferChange ReorderBufferChange
void ReorderBufferAddInvalidations(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, Size nmsgs, SharedInvalidationMessage *msgs)
void(* ReorderBufferApplyTruncateCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
Definition: reorderbuffer.h:480
void ReorderBufferAddDistributedInvalidations(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, Size nmsgs, SharedInvalidationMessage *msgs)
void(* ReorderBufferBeginPrepareCB)(ReorderBuffer *rb, ReorderBufferTXN *txn)
Definition: reorderbuffer.h:504
void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid, Snapshot snap, XLogRecPtr lsn, bool transactional, const char *prefix, Size message_size, const char *message)
Definition: reorderbuffer.c:872
bool ReorderBufferXidHasBaseSnapshot(ReorderBuffer *rb, TransactionId xid)
void ReorderBufferAddSnapshot(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, Snapshot snap)
HeapTuple ReorderBufferAllocTupleBuf(ReorderBuffer *rb, Size tuple_len)
Definition: reorderbuffer.c:591
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(* ReorderBufferStreamAbortCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr abort_lsn)
Definition: reorderbuffer.h:534
ReorderBufferChange * ReorderBufferAllocChange(ReorderBuffer *rb)
Definition: reorderbuffer.c:506
void ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn)
void ReorderBufferSetRestartPoint(ReorderBuffer *rb, XLogRecPtr ptr)
void(* ReorderBufferPrepareCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
Definition: reorderbuffer.h:508
bool ReorderBufferRememberPrepareInfo(ReorderBuffer *rb, TransactionId xid, XLogRecPtr prepare_lsn, XLogRecPtr end_lsn, TimestampTz prepare_time, RepOriginId origin_id, XLogRecPtr origin_lsn)
void ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations)
Oid * ReorderBufferAllocRelids(ReorderBuffer *rb, int nrelids)
Definition: reorderbuffer.c:624
void(* ReorderBufferRollbackPreparedCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr prepare_end_lsn, TimestampTz prepare_time)
Definition: reorderbuffer.h:518
void ReorderBufferProcessXid(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
void ReorderBufferAssignChild(ReorderBuffer *rb, TransactionId xid, TransactionId subxid, XLogRecPtr lsn)
void ReorderBufferFree(ReorderBuffer *rb)
Definition: reorderbuffer.c:416
ReorderBufferChangeType
Definition: reorderbuffer.h:51
@ REORDER_BUFFER_CHANGE_INVALIDATION
Definition: reorderbuffer.h:56
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM
Definition: reorderbuffer.h:61
@ REORDER_BUFFER_CHANGE_INSERT
Definition: reorderbuffer.h:52
@ REORDER_BUFFER_CHANGE_MESSAGE
Definition: reorderbuffer.h:55
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT
Definition: reorderbuffer.h:62
@ REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID
Definition: reorderbuffer.h:58
@ REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID
Definition: reorderbuffer.h:59
@ REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT
Definition: reorderbuffer.h:60
@ REORDER_BUFFER_CHANGE_TRUNCATE
Definition: reorderbuffer.h:63
@ REORDER_BUFFER_CHANGE_DELETE
Definition: reorderbuffer.h:54
@ REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT
Definition: reorderbuffer.h:57
@ REORDER_BUFFER_CHANGE_UPDATE
Definition: reorderbuffer.h:53
void(* ReorderBufferStreamStopCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, XLogRecPtr last_lsn)
Definition: reorderbuffer.h:529
void StartupReorderBuffer(void)
void ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
ReorderBufferTXN * ReorderBufferGetOldestTXN(ReorderBuffer *rb)
void(* ReorderBufferStreamTruncateCB)(ReorderBuffer *rb, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
Definition: reorderbuffer.h:563
Definition: dynahash.c:222
Definition: rel.h:56
struct ReorderBufferChange::@114::@118 tuplecid
struct ReorderBufferChange::@114::@116 truncate
ReorderBufferChangeType action
Definition: reorderbuffer.h:81
RelFileLocator rlocator
Definition: reorderbuffer.h:98
CommandId command_id
Definition: reorderbuffer.h:136
ItemPointerData tid
Definition: reorderbuffer.h:145
HeapTuple newtuple
Definition: reorderbuffer.h:106
struct ReorderBufferChange::@114::@117 msg
struct ReorderBufferTXN * txn
Definition: reorderbuffer.h:84
RelFileLocator locator
Definition: reorderbuffer.h:144
RepOriginId origin_id
Definition: reorderbuffer.h:86
struct ReorderBufferChange::@114::@115 tp
union ReorderBufferChange::@114 data
CommandId combocid
Definition: reorderbuffer.h:148
XLogRecPtr lsn
Definition: reorderbuffer.h:78
HeapTuple oldtuple
Definition: reorderbuffer.h:104
SharedInvalidationMessage * invalidations
Definition: reorderbuffer.h:155
struct ReorderBufferChange::@114::@119 inval
CommandId command_id
Definition: reorderbuffer.h:378
XLogRecPtr restart_decoding_lsn
Definition: reorderbuffer.h:347
pairingheap_node txn_node
Definition: reorderbuffer.h:454
TimestampTz commit_time
Definition: reorderbuffer.h:359
uint32 ninvalidations
Definition: reorderbuffer.h:429
XLogRecPtr base_snapshot_lsn
Definition: reorderbuffer.h:370
Snapshot snapshot_now
Definition: reorderbuffer.h:377
TransactionId toplevel_xid
Definition: reorderbuffer.h:302
dlist_node catchange_node
Definition: reorderbuffer.h:449
Snapshot base_snapshot
Definition: reorderbuffer.h:369
SharedInvalidationMessage * invalidations
Definition: reorderbuffer.h:430
RepOriginId origin_id
Definition: reorderbuffer.h:350
struct ReorderBufferTXN * toptxn
Definition: reorderbuffer.h:340
dlist_head tuplecids
Definition: reorderbuffer.h:404
XLogRecPtr first_lsn
Definition: reorderbuffer.h:315
TimestampTz abort_time
Definition: reorderbuffer.h:361
XLogRecPtr final_lsn
Definition: reorderbuffer.h:332
void * output_plugin_private
Definition: reorderbuffer.h:467
XLogRecPtr end_lsn
Definition: reorderbuffer.h:337
uint32 ninvalidations_distributed
Definition: reorderbuffer.h:435
uint64 nentries_mem
Definition: reorderbuffer.h:391
XLogRecPtr origin_lsn
Definition: reorderbuffer.h:351
TimestampTz prepare_time
Definition: reorderbuffer.h:360
TransactionId xid
Definition: reorderbuffer.h:299
dlist_node base_snapshot_node
Definition: reorderbuffer.h:371
dlist_head changes
Definition: reorderbuffer.h:397
dlist_node node
Definition: reorderbuffer.h:444
SharedInvalidationMessage * invalidations_distributed
Definition: reorderbuffer.h:436
dlist_head subtxns
Definition: reorderbuffer.h:422
HTAB * tuplecid_hash
Definition: reorderbuffer.h:410
ReorderBufferStreamMessageCB stream_message
Definition: reorderbuffer.h:634
ReorderBufferStreamChangeCB stream_change
Definition: reorderbuffer.h:633
HTAB * by_txn
Definition: reorderbuffer.h:579
ReorderBufferBeginCB begin_prepare
Definition: reorderbuffer.h:620
int64 streamBytes
Definition: reorderbuffer.h:691
ReorderBufferStreamTruncateCB stream_truncate
Definition: reorderbuffer.h:635
bool output_rewrites
Definition: reorderbuffer.h:651
ReorderBufferCommitPreparedCB commit_prepared
Definition: reorderbuffer.h:622
ReorderBufferUpdateProgressTxnCB update_progress_txn
Definition: reorderbuffer.h:641
int64 streamCount
Definition: reorderbuffer.h:690
ReorderBufferMessageCB message
Definition: reorderbuffer.h:615
dlist_head txns_by_base_snapshot_lsn
Definition: reorderbuffer.h:594
MemoryContext context
Definition: reorderbuffer.h:656
int64 totalBytes
Definition: reorderbuffer.h:698
int64 streamTxns
Definition: reorderbuffer.h:689
char * outbuf
Definition: reorderbuffer.h:668
dclist_head catchange_txns
Definition: reorderbuffer.h:599
ReorderBufferRollbackPreparedCB rollback_prepared
Definition: reorderbuffer.h:623
ReorderBufferPrepareCB prepare
Definition: reorderbuffer.h:621
ReorderBufferStreamStopCB stream_stop
Definition: reorderbuffer.h:629
int64 spillCount
Definition: reorderbuffer.h:685
ReorderBufferApplyChangeCB apply_change
Definition: reorderbuffer.h:612
int64 spillBytes
Definition: reorderbuffer.h:686
MemoryContext change_context
Definition: reorderbuffer.h:661
ReorderBufferTXN * by_txn_last_txn
Definition: reorderbuffer.h:606
TransactionId by_txn_last_xid
Definition: reorderbuffer.h:605
ReorderBufferStreamPrepareCB stream_prepare
Definition: reorderbuffer.h:631
ReorderBufferStreamAbortCB stream_abort
Definition: reorderbuffer.h:630
MemoryContext tup_context
Definition: reorderbuffer.h:663
ReorderBufferCommitCB commit
Definition: reorderbuffer.h:614
ReorderBufferStreamStartCB stream_start
Definition: reorderbuffer.h:628
int64 totalTxns
Definition: reorderbuffer.h:697
ReorderBufferStreamCommitCB stream_commit
Definition: reorderbuffer.h:632
ReorderBufferApplyTruncateCB apply_truncate
Definition: reorderbuffer.h:613
dlist_head toplevel_by_lsn
Definition: reorderbuffer.h:585
pairingheap * txn_heap
Definition: reorderbuffer.h:675
ReorderBufferBeginCB begin
Definition: reorderbuffer.h:611
MemoryContext txn_context
Definition: reorderbuffer.h:662
XLogRecPtr current_restart_decoding_lsn
Definition: reorderbuffer.h:665
int64 spillTxns
Definition: reorderbuffer.h:684
void * private_data
Definition: reorderbuffer.h:646
Definition: ilist.h:152
Definition: ilist.h:138
uint16 RepOriginId
Definition: xlogdefs.h:68
uint64 XLogRecPtr
Definition: xlogdefs.h:21

AltStyle によって変換されたページ (->オリジナル) /