From 6e897fab2ce393ff5bdb32d3f380e331316a4959 Mon Sep 17 00:00:00 2001 From: Ajin Cherian Date: Mon, 8 Mar 2021 03:09:46 -0500 Subject: [PATCH] Make stream_prepare_cb an optional callback. Previously stream_prepare_cb was a required callback. Change documentation and code to make it an optional callback. This allows plugins to not allow the enabling of streaming and two_phase at the same time in logical replication. Author: Ajin Cherian --- doc/src/sgml/logicaldecoding.sgml | 16 ++++++++-------- src/backend/replication/logical/logical.c | 9 +++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml index 80eb96d..a63fa2d 100644 --- a/doc/src/sgml/logicaldecoding.sgml +++ b/doc/src/sgml/logicaldecoding.sgml @@ -468,9 +468,9 @@ typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb); An output plugin may also define functions to support streaming of large, in-progress transactions. The stream_start_cb, stream_stop_cb, stream_abort_cb, - stream_commit_cb, stream_change_cb, - and stream_prepare_cb - are required, while stream_message_cb and + stream_commit_cb, and stream_change_cb, + are required, while stream_prepare_cb, + stream_message_cb and stream_truncate_cb are optional. @@ -478,9 +478,9 @@ typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb); An output plugin may also define functions to support two-phase commits, which allows actions to be decoded on the PREPARE TRANSACTION. The begin_prepare_cb, prepare_cb, - stream_prepare_cb, commit_prepared_cb and rollback_prepared_cb - callbacks are required, while filter_prepare_cb is optional. + callbacks are required, while stream_prepare_cb and + filter_prepare_cb are optional. @@ -1195,9 +1195,9 @@ stream_commit_cb(...); <-- commit of the streamed transaction provide additional callbacks. There are multiple two-phase commit callbacks that are required, (begin_prepare_cb, prepare_cb, commit_prepared_cb, - rollback_prepared_cb and - stream_prepare_cb) and an optional callback - (filter_prepare_cb). + rollback_prepared_cb) and + optional callbacks, (stream_prepare_cb and + filter_prepare_cb). diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index 37b75de..5324851 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -1326,6 +1326,9 @@ stream_prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, Assert(ctx->streaming); Assert(ctx->twophase); + if (ctx->callbacks.stream_prepare_cb == NULL) + return; + /* Push callback + info on the error context stack */ state.ctx = ctx; state.callback_name = "stream_prepare"; @@ -1340,12 +1343,6 @@ stream_prepare_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn, ctx->write_xid = txn->xid; ctx->write_location = txn->end_lsn; - /* in streaming mode with two-phase commits, stream_prepare_cb is required */ - if (ctx->callbacks.stream_prepare_cb == NULL) - ereport(ERROR, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("logical streaming at prepare time requires a stream_prepare_cb callback"))); - ctx->callbacks.stream_prepare_cb(ctx, txn, prepare_lsn); /* Pop the error context stack */ -- 1.8.3.1