PostgreSQL Source Code  git master
output_plugin.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  * output_plugin.h
3  * PostgreSQL Logical Decode Plugin Interface
4  *
5  * Copyright (c) 2012-2021, PostgreSQL Global Development Group
6  *
7  *-------------------------------------------------------------------------
8  */
9 #ifndef OUTPUT_PLUGIN_H
10 #define OUTPUT_PLUGIN_H
11 
13 
16 
18 {
22 
23 /*
24  * Options set by the output plugin, in the startup callback.
25  */
26 typedef struct OutputPluginOptions
27 {
31 
32 /*
33  * Type of the shared library symbol _PG_output_plugin_init that is looked up
34  * when loading an output plugin shared library.
35  */
36 typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb);
37 
38 /*
39  * Callback that gets called in a user-defined plugin. ctx->private_data can
40  * be set to some private data.
41  *
42  * "is_init" will be set to "true" if the decoding slot just got defined. When
43  * the same slot is used from there one, it will be "false".
44  */
45 typedef void (*LogicalDecodeStartupCB) (struct LogicalDecodingContext *ctx,
47  bool is_init);
48 
49 /*
50  * Callback called for every (explicit or implicit) BEGIN of a successful
51  * transaction.
52  */
53 typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
54  ReorderBufferTXN *txn);
55 
56 /*
57  * Callback for every individual change in a successful transaction.
58  */
59 typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
60  ReorderBufferTXN *txn,
61  Relation relation,
62  ReorderBufferChange *change);
63 
64 /*
65  * Callback for every TRUNCATE in a successful transaction.
66  */
67 typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,
68  ReorderBufferTXN *txn,
69  int nrelations,
70  Relation relations[],
71  ReorderBufferChange *change);
72 
73 /*
74  * Called for every (explicit or implicit) COMMIT of a successful transaction.
75  */
76 typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
77  ReorderBufferTXN *txn,
78  XLogRecPtr commit_lsn);
79 
80 /*
81  * Called for the generic logical decoding messages.
82  */
83 typedef void (*LogicalDecodeMessageCB) (struct LogicalDecodingContext *ctx,
84  ReorderBufferTXN *txn,
85  XLogRecPtr message_lsn,
86  bool transactional,
87  const char *prefix,
88  Size message_size,
89  const char *message);
90 
91 /*
92  * Filter changes by origin.
93  */
95  RepOriginId origin_id);
96 
97 /*
98  * Called to shutdown an output plugin.
99  */
100 typedef void (*LogicalDecodeShutdownCB) (struct LogicalDecodingContext *ctx);
101 
102 /*
103  * Called before decoding of PREPARE record to decide whether this
104  * transaction should be decoded with separate calls to prepare and
105  * commit_prepared/rollback_prepared callbacks or wait till COMMIT PREPARED
106  * and sent as usual transaction.
107  */
109  TransactionId xid,
110  const char *gid);
111 
112 /*
113  * Callback called for every BEGIN of a prepared trnsaction.
114  */
116  ReorderBufferTXN *txn);
117 
118 /*
119  * Called for PREPARE record unless it was filtered by filter_prepare()
120  * callback.
121  */
122 typedef void (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,
123  ReorderBufferTXN *txn,
124  XLogRecPtr prepare_lsn);
125 
126 /*
127  * Called for COMMIT PREPARED.
128  */
130  ReorderBufferTXN *txn,
131  XLogRecPtr commit_lsn);
132 
133 /*
134  * Called for ROLLBACK PREPARED.
135  */
137  ReorderBufferTXN *txn,
138  XLogRecPtr prepare_end_lsn,
139  TimestampTz prepare_time);
140 
141 
142 /*
143  * Called when starting to stream a block of changes from in-progress
144  * transaction (may be called repeatedly, if it's streamed in multiple
145  * chunks).
146  */
148  ReorderBufferTXN *txn);
149 
150 /*
151  * Called when stopping to stream a block of changes from in-progress
152  * transaction to a remote node (may be called repeatedly, if it's streamed
153  * in multiple chunks).
154  */
156  ReorderBufferTXN *txn);
157 
158 /*
159  * Called to discard changes streamed to remote node from in-progress
160  * transaction.
161  */
163  ReorderBufferTXN *txn,
164  XLogRecPtr abort_lsn);
165 
166 /*
167  * Called to prepare changes streamed to remote node from in-progress
168  * transaction. This is called as part of a two-phase commit.
169  */
171  ReorderBufferTXN *txn,
172  XLogRecPtr prepare_lsn);
173 
174 /*
175  * Called to apply changes streamed to remote node from in-progress
176  * transaction.
177  */
179  ReorderBufferTXN *txn,
180  XLogRecPtr commit_lsn);
181 
182 /*
183  * Callback for streaming individual changes from in-progress transactions.
184  */
186  ReorderBufferTXN *txn,
187  Relation relation,
188  ReorderBufferChange *change);
189 
190 /*
191  * Callback for streaming generic logical decoding messages from in-progress
192  * transactions.
193  */
195  ReorderBufferTXN *txn,
196  XLogRecPtr message_lsn,
197  bool transactional,
198  const char *prefix,
199  Size message_size,
200  const char *message);
201 
202 /*
203  * Callback for streaming truncates from in-progress transactions.
204  */
206  ReorderBufferTXN *txn,
207  int nrelations,
208  Relation relations[],
209  ReorderBufferChange *change);
210 
211 /*
212  * Output plugin callbacks
213  */
214 typedef struct OutputPluginCallbacks
215 {
224 
225  /* streaming of changes at prepare time */
231 
232  /* streaming of changes */
242 
243 /* Functions in replication/logical/logical.c */
244 extern void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write);
245 extern void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write);
246 extern void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx);
247 
248 #endif /* OUTPUT_PLUGIN_H */
LogicalDecodeTruncateCB truncate_cb
void(* LogicalDecodeStartupCB)(struct LogicalDecodingContext *ctx, OutputPluginOptions *options, bool is_init)
Definition: output_plugin.h:45
void(* LogicalDecodeBeginPrepareCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
uint32 TransactionId
Definition: c.h:587
void(* LogicalDecodeStreamCommitCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
LogicalDecodeStreamPrepareCB stream_prepare_cb
void(* LogicalDecodeRollbackPreparedCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr prepare_end_lsn, TimestampTz prepare_time)
int64 TimestampTz
Definition: timestamp.h:39
LogicalDecodeMessageCB message_cb
LogicalDecodeStreamMessageCB stream_message_cb
void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx)
Definition: logical.c:674
uint16 RepOriginId
Definition: xlogdefs.h:65
struct OutputPluginOptions OutputPluginOptions
LogicalDecodeStreamAbortCB stream_abort_cb
void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
Definition: logical.c:661
LogicalDecodeBeginPrepareCB begin_prepare_cb
OutputPluginOutputType output_type
Definition: output_plugin.h:28
LogicalDecodePrepareCB prepare_cb
void(* LogicalDecodeStreamStartCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write)
Definition: logical.c:648
LogicalDecodeCommitCB commit_cb
void(* LogicalOutputPluginInit)(struct OutputPluginCallbacks *cb)
Definition: output_plugin.h:36
void(* LogicalDecodePrepareCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
void(* LogicalDecodeTruncateCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
Definition: output_plugin.h:67
bool(* LogicalDecodeFilterPrepareCB)(struct LogicalDecodingContext *ctx, TransactionId xid, const char *gid)
OutputPluginOutputType
Definition: output_plugin.h:17
LogicalDecodeRollbackPreparedCB rollback_prepared_cb
LogicalDecodeCommitPreparedCB commit_prepared_cb
bool(* LogicalDecodeFilterByOriginCB)(struct LogicalDecodingContext *ctx, RepOriginId origin_id)
Definition: output_plugin.h:94
void(* LogicalDecodeStreamMessageCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size message_size, const char *message)
static char ** options
void(* LogicalDecodeStreamStopCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
struct OutputPluginCallbacks OutputPluginCallbacks
void(* LogicalDecodeStreamPrepareCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr prepare_lsn)
LogicalDecodeChangeCB change_cb
LogicalDecodeFilterPrepareCB filter_prepare_cb
void(* LogicalDecodeCommitPreparedCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
LogicalDecodeStreamTruncateCB stream_truncate_cb
uint64 XLogRecPtr
Definition: xlogdefs.h:21
void(* LogicalDecodeMessageCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr message_lsn, bool transactional, const char *prefix, Size message_size, const char *message)
Definition: output_plugin.h:83
size_t Size
Definition: c.h:540
LogicalDecodeShutdownCB shutdown_cb
LogicalDecodeStreamCommitCB stream_commit_cb
void(* LogicalDecodeStreamAbortCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr abort_lsn)
LogicalDecodeStartupCB startup_cb
void(* LogicalDecodeBeginCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
Definition: output_plugin.h:53
void(* LogicalDecodeShutdownCB)(struct LogicalDecodingContext *ctx)
LogicalDecodeStreamStartCB stream_start_cb
void(* LogicalDecodeStreamTruncateCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
void(* LogicalDecodeCommitCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
Definition: output_plugin.h:76
LogicalDecodeBeginCB begin_cb
LogicalDecodeStreamStopCB stream_stop_cb
void(* LogicalDecodeChangeCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)
Definition: output_plugin.h:59
LogicalDecodeFilterByOriginCB filter_by_origin_cb
LogicalDecodeStreamChangeCB stream_change_cb
unsigned char bool
Definition: c.h:391
void(* LogicalDecodeStreamChangeCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)