1 | /*------------------------------------------------------------------------- |
2 | * output_plugin.h |
3 | * PostgreSQL Logical Decode Plugin Interface |
4 | * |
5 | * Copyright (c) 2012-2019, PostgreSQL Global Development Group |
6 | * |
7 | *------------------------------------------------------------------------- |
8 | */ |
9 | #ifndef OUTPUT_PLUGIN_H |
10 | #define OUTPUT_PLUGIN_H |
11 | |
12 | #include "replication/reorderbuffer.h" |
13 | |
14 | struct LogicalDecodingContext; |
15 | struct OutputPluginCallbacks; |
16 | |
17 | typedef enum OutputPluginOutputType |
18 | { |
19 | OUTPUT_PLUGIN_BINARY_OUTPUT, |
20 | OUTPUT_PLUGIN_TEXTUAL_OUTPUT |
21 | } OutputPluginOutputType; |
22 | |
23 | /* |
24 | * Options set by the output plugin, in the startup callback. |
25 | */ |
26 | typedef struct OutputPluginOptions |
27 | { |
28 | OutputPluginOutputType output_type; |
29 | bool receive_rewrites; |
30 | } OutputPluginOptions; |
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, |
46 | OutputPluginOptions *options, |
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 | */ |
94 | typedef bool (*LogicalDecodeFilterByOriginCB) (struct LogicalDecodingContext *ctx, |
95 | RepOriginId origin_id); |
96 | |
97 | /* |
98 | * Called to shutdown an output plugin. |
99 | */ |
100 | typedef void (*LogicalDecodeShutdownCB) (struct LogicalDecodingContext *ctx); |
101 | |
102 | /* |
103 | * Output plugin callbacks |
104 | */ |
105 | typedef struct OutputPluginCallbacks |
106 | { |
107 | LogicalDecodeStartupCB startup_cb; |
108 | LogicalDecodeBeginCB begin_cb; |
109 | LogicalDecodeChangeCB change_cb; |
110 | LogicalDecodeTruncateCB truncate_cb; |
111 | LogicalDecodeCommitCB commit_cb; |
112 | LogicalDecodeMessageCB message_cb; |
113 | LogicalDecodeFilterByOriginCB filter_by_origin_cb; |
114 | LogicalDecodeShutdownCB shutdown_cb; |
115 | } OutputPluginCallbacks; |
116 | |
117 | /* Functions in replication/logical/logical.c */ |
118 | extern void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write); |
119 | extern void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write); |
120 | extern void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx); |
121 | |
122 | #endif /* OUTPUT_PLUGIN_H */ |
123 | |