codekingpro/portable-devtools
115k
1/*-------------------------------------------------------------------------2 * output_plugin.h3 * PostgreSQL Logical Decode Plugin Interface4 *5 * Copyright (c) 2012-2023, PostgreSQL Global Development Group6 *7 *-------------------------------------------------------------------------8 */9#ifndef OUTPUT_PLUGIN_H10#define OUTPUT_PLUGIN_H11 12#include "replication/reorderbuffer.h"13 14struct LogicalDecodingContext;15struct OutputPluginCallbacks;16 17typedef enum OutputPluginOutputType18{19 OUTPUT_PLUGIN_BINARY_OUTPUT,20 OUTPUT_PLUGIN_TEXTUAL_OUTPUT21} OutputPluginOutputType;22 23/*24 * Options set by the output plugin, in the startup callback.25 */26typedef struct OutputPluginOptions27{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 up34 * when loading an output plugin shared library.35 */36typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb);37 38extern PGDLLEXPORT void _PG_output_plugin_init(struct OutputPluginCallbacks *cb);39 40/*41 * Callback that gets called in a user-defined plugin. ctx->private_data can42 * be set to some private data.43 *44 * "is_init" will be set to "true" if the decoding slot just got defined. When45 * the same slot is used from there one, it will be "false".46 */47typedef void (*LogicalDecodeStartupCB) (struct LogicalDecodingContext *ctx,48 OutputPluginOptions *options,49 bool is_init);50 51/*52 * Callback called for every (explicit or implicit) BEGIN of a successful53 * transaction.54 */55typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,56 ReorderBufferTXN *txn);57 58/*59 * Callback for every individual change in a successful transaction.60 */61typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,62 ReorderBufferTXN *txn,63 Relation relation,64 ReorderBufferChange *change);65 66/*67 * Callback for every TRUNCATE in a successful transaction.68 */69typedef void (*LogicalDecodeTruncateCB) (struct LogicalDecodingContext *ctx,70 ReorderBufferTXN *txn,71 int nrelations,72 Relation relations[],73 ReorderBufferChange *change);74 75/*76 * Called for every (explicit or implicit) COMMIT of a successful transaction.77 */78typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,79 ReorderBufferTXN *txn,80 XLogRecPtr commit_lsn);81 82/*83 * Called for the generic logical decoding messages.84 */85typedef void (*LogicalDecodeMessageCB) (struct LogicalDecodingContext *ctx,86 ReorderBufferTXN *txn,87 XLogRecPtr message_lsn,88 bool transactional,89 const char *prefix,90 Size message_size,91 const char *message);92 93/*94 * Filter changes by origin.95 */96typedef bool (*LogicalDecodeFilterByOriginCB) (struct LogicalDecodingContext *ctx,97 RepOriginId origin_id);98 99/*100 * Called to shutdown an output plugin.101 */102typedef void (*LogicalDecodeShutdownCB) (struct LogicalDecodingContext *ctx);103 104/*105 * Called before decoding of PREPARE record to decide whether this106 * transaction should be decoded with separate calls to prepare and107 * commit_prepared/rollback_prepared callbacks or wait till COMMIT PREPARED108 * and sent as usual transaction.109 */110typedef bool (*LogicalDecodeFilterPrepareCB) (struct LogicalDecodingContext *ctx,111 TransactionId xid,112 const char *gid);113 114/*115 * Callback called for every BEGIN of a prepared transaction.116 */117typedef void (*LogicalDecodeBeginPrepareCB) (struct LogicalDecodingContext *ctx,118 ReorderBufferTXN *txn);119 120/*121 * Called for PREPARE record unless it was filtered by filter_prepare()122 * callback.123 */124typedef void (*LogicalDecodePrepareCB) (struct LogicalDecodingContext *ctx,125 ReorderBufferTXN *txn,126 XLogRecPtr prepare_lsn);127 128/*129 * Called for COMMIT PREPARED.130 */131typedef void (*LogicalDecodeCommitPreparedCB) (struct LogicalDecodingContext *ctx,132 ReorderBufferTXN *txn,133 XLogRecPtr commit_lsn);134 135/*136 * Called for ROLLBACK PREPARED.137 */138typedef void (*LogicalDecodeRollbackPreparedCB) (struct LogicalDecodingContext *ctx,139 ReorderBufferTXN *txn,140 XLogRecPtr prepare_end_lsn,141 TimestampTz prepare_time);142 143 144/*145 * Called when starting to stream a block of changes from in-progress146 * transaction (may be called repeatedly, if it's streamed in multiple147 * chunks).148 */149typedef void (*LogicalDecodeStreamStartCB) (struct LogicalDecodingContext *ctx,150 ReorderBufferTXN *txn);151 152/*153 * Called when stopping to stream a block of changes from in-progress154 * transaction to a remote node (may be called repeatedly, if it's streamed155 * in multiple chunks).156 */157typedef void (*LogicalDecodeStreamStopCB) (struct LogicalDecodingContext *ctx,158 ReorderBufferTXN *txn);159 160/*161 * Called to discard changes streamed to remote node from in-progress162 * transaction.163 */164typedef void (*LogicalDecodeStreamAbortCB) (struct LogicalDecodingContext *ctx,165 ReorderBufferTXN *txn,166 XLogRecPtr abort_lsn);167 168/*169 * Called to prepare changes streamed to remote node from in-progress170 * transaction. This is called as part of a two-phase commit.171 */172typedef void (*LogicalDecodeStreamPrepareCB) (struct LogicalDecodingContext *ctx,173 ReorderBufferTXN *txn,174 XLogRecPtr prepare_lsn);175 176/*177 * Called to apply changes streamed to remote node from in-progress178 * transaction.179 */180typedef void (*LogicalDecodeStreamCommitCB) (struct LogicalDecodingContext *ctx,181 ReorderBufferTXN *txn,182 XLogRecPtr commit_lsn);183 184/*185 * Callback for streaming individual changes from in-progress transactions.186 */187typedef void (*LogicalDecodeStreamChangeCB) (struct LogicalDecodingContext *ctx,188 ReorderBufferTXN *txn,189 Relation relation,190 ReorderBufferChange *change);191 192/*193 * Callback for streaming generic logical decoding messages from in-progress194 * transactions.195 */196typedef void (*LogicalDecodeStreamMessageCB) (struct LogicalDecodingContext *ctx,197 ReorderBufferTXN *txn,198 XLogRecPtr message_lsn,199 bool transactional,200 const char *prefix,201 Size message_size,202 const char *message);203 204/*205 * Callback for streaming truncates from in-progress transactions.206 */207typedef void (*LogicalDecodeStreamTruncateCB) (struct LogicalDecodingContext *ctx,208 ReorderBufferTXN *txn,209 int nrelations,210 Relation relations[],211 ReorderBufferChange *change);212 213/*214 * Output plugin callbacks215 */216typedef struct OutputPluginCallbacks217{218 LogicalDecodeStartupCB startup_cb;219 LogicalDecodeBeginCB begin_cb;220 LogicalDecodeChangeCB change_cb;221 LogicalDecodeTruncateCB truncate_cb;222 LogicalDecodeCommitCB commit_cb;223 LogicalDecodeMessageCB message_cb;224 LogicalDecodeFilterByOriginCB filter_by_origin_cb;225 LogicalDecodeShutdownCB shutdown_cb;226 227 /* streaming of changes at prepare time */228 LogicalDecodeFilterPrepareCB filter_prepare_cb;229 LogicalDecodeBeginPrepareCB begin_prepare_cb;230 LogicalDecodePrepareCB prepare_cb;231 LogicalDecodeCommitPreparedCB commit_prepared_cb;232 LogicalDecodeRollbackPreparedCB rollback_prepared_cb;233 234 /* streaming of changes */235 LogicalDecodeStreamStartCB stream_start_cb;236 LogicalDecodeStreamStopCB stream_stop_cb;237 LogicalDecodeStreamAbortCB stream_abort_cb;238 LogicalDecodeStreamPrepareCB stream_prepare_cb;239 LogicalDecodeStreamCommitCB stream_commit_cb;240 LogicalDecodeStreamChangeCB stream_change_cb;241 LogicalDecodeStreamMessageCB stream_message_cb;242 LogicalDecodeStreamTruncateCB stream_truncate_cb;243} OutputPluginCallbacks;244 245/* Functions in replication/logical/logical.c */246extern void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write);247extern void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write);248extern void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx, bool skipped_xact);249 250#endif /* OUTPUT_PLUGIN_H */251 