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

PostgreSQL Source Code git master
logical.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 * logical.h
3 * PostgreSQL logical decoding coordination
4 *
5 * Copyright (c) 2012-2025, PostgreSQL Global Development Group
6 *
7 *-------------------------------------------------------------------------
8 */
9#ifndef LOGICAL_H
10#define LOGICAL_H
11
12#include "access/xlog.h"
13#include "access/xlogreader.h"
14#include "replication/output_plugin.h"
15#include "replication/slot.h"
16
17struct LogicalDecodingContext;
18
19 typedef void (*LogicalOutputPluginWriterWrite) (struct LogicalDecodingContext *lr,
20 XLogRecPtr Ptr,
21 TransactionId xid,
22 bool last_write
23);
24
25 typedef LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite;
26
27 typedef void (*LogicalOutputPluginWriterUpdateProgress) (struct LogicalDecodingContext *lr,
28 XLogRecPtr Ptr,
29 TransactionId xid,
30 bool skipped_xact
31);
32
33 typedef struct LogicalDecodingContext
34{
35 /* memory context this is all allocated in */
36 MemoryContext context;
37
38 /* The associated replication slot */
39 ReplicationSlot *slot;
40
41 /* infrastructure pieces for decoding */
42 XLogReaderState *reader;
43 struct ReorderBuffer *reorder;
44 struct SnapBuild *snapshot_builder;
45
46 /*
47 * Marks the logical decoding context as fast forward decoding one. Such a
48 * context does not have plugin loaded so most of the following properties
49 * are unused.
50 */
51 bool fast_forward;
52
53 OutputPluginCallbacks callbacks;
54 OutputPluginOptions options;
55
56 /*
57 * User specified options
58 */
59 List *output_plugin_options;
60
61 /*
62 * User-Provided callback for writing/streaming out data.
63 */
64 LogicalOutputPluginWriterPrepareWrite prepare_write;
65 LogicalOutputPluginWriterWrite write;
66 LogicalOutputPluginWriterUpdateProgress update_progress;
67
68 /*
69 * Output buffer.
70 */
71 StringInfo out;
72
73 /*
74 * Private data pointer of the output plugin.
75 */
76 void *output_plugin_private;
77
78 /*
79 * Private data pointer for the data writer.
80 */
81 void *output_writer_private;
82
83 /*
84 * Does the output plugin support streaming, and is it enabled?
85 */
86 bool streaming;
87
88 /*
89 * Does the output plugin support two-phase decoding, and is it enabled?
90 */
91 bool twophase;
92
93 /*
94 * Is two-phase option given by output plugin?
95 *
96 * This flag indicates that the plugin passed in the two-phase option as
97 * part of the START_STREAMING command. We can't rely solely on the
98 * twophase flag which only tells whether the plugin provided all the
99 * necessary two-phase callbacks.
100 */
101 bool twophase_opt_given;
102
103 /*
104 * State for writing output.
105 */
106 bool accept_writes;
107 bool prepared_write;
108 XLogRecPtr write_location;
109 TransactionId write_xid;
110 /* Are we processing the end LSN of a transaction? */
111 bool end_xact;
112
113 /* Do we need to process any change in fast_forward mode? */
114 bool processing_required;
115 } LogicalDecodingContext;
116
117
118extern void CheckLogicalDecodingRequirements(void);
119
120extern LogicalDecodingContext *CreateInitDecodingContext(const char *plugin,
121 List *output_plugin_options,
122 bool need_full_snapshot,
123 XLogRecPtr restart_lsn,
124 XLogReaderRoutine *xl_routine,
125 LogicalOutputPluginWriterPrepareWrite prepare_write,
126 LogicalOutputPluginWriterWrite do_write,
127 LogicalOutputPluginWriterUpdateProgress update_progress);
128extern LogicalDecodingContext *CreateDecodingContext(XLogRecPtr start_lsn,
129 List *output_plugin_options,
130 bool fast_forward,
131 XLogReaderRoutine *xl_routine,
132 LogicalOutputPluginWriterPrepareWrite prepare_write,
133 LogicalOutputPluginWriterWrite do_write,
134 LogicalOutputPluginWriterUpdateProgress update_progress);
135extern void DecodingContextFindStartpoint(LogicalDecodingContext *ctx);
136extern bool DecodingContextReady(LogicalDecodingContext *ctx);
137extern void FreeDecodingContext(LogicalDecodingContext *ctx);
138
139extern void LogicalIncreaseXminForSlot(XLogRecPtr current_lsn,
140 TransactionId xmin);
141extern void LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn,
142 XLogRecPtr restart_lsn);
143extern void LogicalConfirmReceivedLocation(XLogRecPtr lsn);
144
145extern bool filter_prepare_cb_wrapper(LogicalDecodingContext *ctx,
146 TransactionId xid, const char *gid);
147extern bool filter_by_origin_cb_wrapper(LogicalDecodingContext *ctx, RepOriginId origin_id);
148extern void ResetLogicalStreamingState(void);
149extern void UpdateDecodingStats(LogicalDecodingContext *ctx);
150
151extern bool LogicalReplicationSlotHasPendingWal(XLogRecPtr end_of_wal);
152extern XLogRecPtr LogicalSlotAdvanceAndCheckSnapState(XLogRecPtr moveto,
153 bool *found_consistent_snapshot);
154
155#endif
uint32 TransactionId
Definition: c.h:657
void(* LogicalOutputPluginWriterUpdateProgress)(struct LogicalDecodingContext *lr, XLogRecPtr Ptr, TransactionId xid, bool skipped_xact)
Definition: logical.h:27
XLogRecPtr LogicalSlotAdvanceAndCheckSnapState(XLogRecPtr moveto, bool *found_consistent_snapshot)
Definition: logical.c:2081
void LogicalConfirmReceivedLocation(XLogRecPtr lsn)
Definition: logical.c:1820
void FreeDecodingContext(LogicalDecodingContext *ctx)
Definition: logical.c:677
bool LogicalReplicationSlotHasPendingWal(XLogRecPtr end_of_wal)
Definition: logical.c:1999
struct LogicalDecodingContext LogicalDecodingContext
LogicalDecodingContext * CreateDecodingContext(XLogRecPtr start_lsn, List *output_plugin_options, bool fast_forward, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
Definition: logical.c:498
void(* LogicalOutputPluginWriterWrite)(struct LogicalDecodingContext *lr, XLogRecPtr Ptr, TransactionId xid, bool last_write)
Definition: logical.h:19
void DecodingContextFindStartpoint(LogicalDecodingContext *ctx)
Definition: logical.c:633
bool DecodingContextReady(LogicalDecodingContext *ctx)
Definition: logical.c:624
LogicalDecodingContext * CreateInitDecodingContext(const char *plugin, List *output_plugin_options, bool need_full_snapshot, XLogRecPtr restart_lsn, XLogReaderRoutine *xl_routine, LogicalOutputPluginWriterPrepareWrite prepare_write, LogicalOutputPluginWriterWrite do_write, LogicalOutputPluginWriterUpdateProgress update_progress)
Definition: logical.c:332
void UpdateDecodingStats(LogicalDecodingContext *ctx)
Definition: logical.c:1952
void LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart_lsn)
Definition: logical.c:1744
LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite
Definition: logical.h:25
void ResetLogicalStreamingState(void)
Definition: logical.c:1942
void LogicalIncreaseXminForSlot(XLogRecPtr current_lsn, TransactionId xmin)
Definition: logical.c:1676
bool filter_prepare_cb_wrapper(LogicalDecodingContext *ctx, TransactionId xid, const char *gid)
Definition: logical.c:1167
void CheckLogicalDecodingRequirements(void)
Definition: logical.c:111
bool filter_by_origin_cb_wrapper(LogicalDecodingContext *ctx, RepOriginId origin_id)
Definition: logical.c:1199
static const char * plugin
Definition: pg_recvlogical.c:61
Definition: pg_list.h:54
OutputPluginOptions options
Definition: logical.h:54
XLogReaderState * reader
Definition: logical.h:42
MemoryContext context
Definition: logical.h:36
bool processing_required
Definition: logical.h:114
struct SnapBuild * snapshot_builder
Definition: logical.h:44
void * output_writer_private
Definition: logical.h:81
StringInfo out
Definition: logical.h:71
XLogRecPtr write_location
Definition: logical.h:108
LogicalOutputPluginWriterPrepareWrite prepare_write
Definition: logical.h:64
OutputPluginCallbacks callbacks
Definition: logical.h:53
void * output_plugin_private
Definition: logical.h:76
TransactionId write_xid
Definition: logical.h:109
List * output_plugin_options
Definition: logical.h:59
ReplicationSlot * slot
Definition: logical.h:39
LogicalOutputPluginWriterWrite write
Definition: logical.h:65
struct ReorderBuffer * reorder
Definition: logical.h:43
bool twophase_opt_given
Definition: logical.h:101
LogicalOutputPluginWriterUpdateProgress update_progress
Definition: logical.h:66
TransactionId xmin
uint16 RepOriginId
Definition: xlogdefs.h:68
uint64 XLogRecPtr
Definition: xlogdefs.h:21

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