mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Generic Messages for Logical Decoding
API and mechanism to allow generic messages to be inserted into WAL that are intended to be read by logical decoding plugins. This commit adds an optional new callback to the logical decoding API. Messages are either text or bytea. Messages can be transactional, or not, and are identified by a prefix to allow multiple concurrent decoding plugins. (Not to be confused with Generic WAL records, which are intended to allow crash recovery of extensible objects.) Author: Petr Jelinek and Andres Freund Reviewers: Artur Zakirov, Tomas Vondra, Simon Riggs Discussion: 5685F999.6010202@2ndquadrant.com
This commit is contained in:
@@ -62,6 +62,9 @@ static void commit_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
|
||||
XLogRecPtr commit_lsn);
|
||||
static void change_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
|
||||
Relation relation, ReorderBufferChange *change);
|
||||
static void message_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
|
||||
XLogRecPtr message_lsn, bool transactional,
|
||||
const char *prefix, Size message_size, const char *message);
|
||||
|
||||
static void LoadOutputPlugin(OutputPluginCallbacks *callbacks, char *plugin);
|
||||
|
||||
@@ -178,6 +181,7 @@ StartupDecodingContext(List *output_plugin_options,
|
||||
ctx->reorder->begin = begin_cb_wrapper;
|
||||
ctx->reorder->apply_change = change_cb_wrapper;
|
||||
ctx->reorder->commit = commit_cb_wrapper;
|
||||
ctx->reorder->message = message_cb_wrapper;
|
||||
|
||||
ctx->out = makeStringInfo();
|
||||
ctx->prepare_write = prepare_write;
|
||||
@@ -702,6 +706,40 @@ filter_by_origin_cb_wrapper(LogicalDecodingContext *ctx, RepOriginId origin_id)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
message_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
|
||||
XLogRecPtr message_lsn, bool transactional,
|
||||
const char *prefix, Size message_size, const char *message)
|
||||
{
|
||||
LogicalDecodingContext *ctx = cache->private_data;
|
||||
LogicalErrorCallbackState state;
|
||||
ErrorContextCallback errcallback;
|
||||
|
||||
if (ctx->callbacks.message_cb == NULL)
|
||||
return;
|
||||
|
||||
/* Push callback + info on the error context stack */
|
||||
state.ctx = ctx;
|
||||
state.callback_name = "message";
|
||||
state.report_location = message_lsn;
|
||||
errcallback.callback = output_plugin_error_callback;
|
||||
errcallback.arg = (void *) &state;
|
||||
errcallback.previous = error_context_stack;
|
||||
error_context_stack = &errcallback;
|
||||
|
||||
/* set output state */
|
||||
ctx->accept_writes = true;
|
||||
ctx->write_xid = txn != NULL ? txn->xid : InvalidTransactionId;
|
||||
ctx->write_location = message_lsn;
|
||||
|
||||
/* do the actual work: call callback */
|
||||
ctx->callbacks.message_cb(ctx, txn, message_lsn, transactional, prefix,
|
||||
message_size, message);
|
||||
|
||||
/* Pop the error context stack */
|
||||
error_context_stack = errcallback.previous;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the required catalog xmin horizon for historic snapshots in the current
|
||||
* replication slot.
|
||||
|
||||
Reference in New Issue
Block a user