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-2020, 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 when starting to stream a block of changes from in-progress
104  * transaction (may be called repeatedly, if it's streamed in multiple
105  * chunks).
106  */
108  ReorderBufferTXN *txn);
109 
110 /*
111  * Called when stopping to stream a block of changes from in-progress
112  * transaction to a remote node (may be called repeatedly, if it's streamed
113  * in multiple chunks).
114  */
116  ReorderBufferTXN *txn);
117 
118 /*
119  * Called to discard changes streamed to remote node from in-progress
120  * transaction.
121  */
123  ReorderBufferTXN *txn,
124  XLogRecPtr abort_lsn);
125 
126 /*
127  * Called to apply changes streamed to remote node from in-progress
128  * transaction.
129  */
131  ReorderBufferTXN *txn,
132  XLogRecPtr commit_lsn);
133 
134 /*
135  * Callback for streaming individual changes from in-progress transactions.
136  */
138  ReorderBufferTXN *txn,
139  Relation relation,
140  ReorderBufferChange *change);
141 
142 /*
143  * Callback for streaming generic logical decoding messages from in-progress
144  * transactions.
145  */
147  ReorderBufferTXN *txn,
148  XLogRecPtr message_lsn,
149  bool transactional,
150  const char *prefix,
151  Size message_size,
152  const char *message);
153 
154 /*
155  * Callback for streaming truncates from in-progress transactions.
156  */
158  ReorderBufferTXN *txn,
159  int nrelations,
160  Relation relations[],
161  ReorderBufferChange *change);
162 
163 /*
164  * Output plugin callbacks
165  */
166 typedef struct OutputPluginCallbacks
167 {
176  /* streaming of changes */
185 
186 /* Functions in replication/logical/logical.c */
187 extern void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write);
188 extern void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write);
189 extern void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx);
190 
191 #endif /* OUTPUT_PLUGIN_H */
LogicalDecodeTruncateCB truncate_cb
void(* LogicalDecodeStartupCB)(struct LogicalDecodingContext *ctx, OutputPluginOptions *options, bool is_init)
Definition: output_plugin.h:45
void(* LogicalDecodeStreamCommitCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, XLogRecPtr commit_lsn)
LogicalDecodeMessageCB message_cb
LogicalDecodeStreamMessageCB stream_message_cb
void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx)
Definition: logical.c:610
uint16 RepOriginId
Definition: xlogdefs.h:58
struct OutputPluginOptions OutputPluginOptions
LogicalDecodeStreamAbortCB stream_abort_cb
void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write)
Definition: logical.c:597
OutputPluginOutputType output_type
Definition: output_plugin.h:28
void(* LogicalDecodeStreamStartCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write)
Definition: logical.c:584
LogicalDecodeCommitCB commit_cb
void(* LogicalOutputPluginInit)(struct OutputPluginCallbacks *cb)
Definition: output_plugin.h:36
void(* LogicalDecodeTruncateCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, int nrelations, Relation relations[], ReorderBufferChange *change)
Definition: output_plugin.h:67
OutputPluginOutputType
Definition: output_plugin.h:17
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
LogicalDecodeChangeCB change_cb
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:473
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:324
void(* LogicalDecodeStreamChangeCB)(struct LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Relation relation, ReorderBufferChange *change)