Skip to content

Commit 26dd028

Browse files
author
Amit Kapila
committed
Add BEGIN/COMMIT for transactional messages during decoding.
In test_decoding module, when skip_empty_xacts option was specified, add BEGIN/COMMIT for transactional messages. This makes the handling of transactional messages consistent irrespective of whether skip_empty_xacts option was specified. We decided not to backpatch this change because skip_empty_xacts is primarily used to have consistent test results across different runs and this change won't help with that. Author: Vignesh C Reviewed-by: Ashutosh Bapat, Hou Zhijie Discussion: https://postgr.es/m/CAExHW5ujRhbOz6_aTq_jQA8NjeFqq9d_8G9viShWvXx8gdSXiQ@mail.gmail.com
1 parent 4e9fa6d commit 26dd028

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

contrib/test_decoding/expected/messages.out

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,23 @@ SELECT 'ignorethis' FROM pg_logical_emit_message(true, 'test', 'czechtastic');
5858
ignorethis
5959
(1 row)
6060

61-
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'force-binary', '0', 'skip-empty-xacts', '1');
61+
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'force-binary', '0', 'skip-empty-xacts', '1', 'include-xids', '0');
6262
data
6363
--------------------------------------------------------------------
64+
BEGIN
6465
message: transactional: 1 prefix: test, sz: 4 content:msg1
66+
COMMIT
6567
message: transactional: 0 prefix: test, sz: 4 content:msg2
6668
message: transactional: 0 prefix: test, sz: 4 content:msg4
6769
message: transactional: 0 prefix: test, sz: 4 content:msg6
70+
BEGIN
6871
message: transactional: 1 prefix: test, sz: 4 content:msg5
6972
message: transactional: 1 prefix: test, sz: 4 content:msg7
73+
COMMIT
74+
BEGIN
7075
message: transactional: 1 prefix: test, sz: 11 content:czechtastic
71-
(7 rows)
76+
COMMIT
77+
(13 rows)
7278

7379
-- test db filtering
7480
\set prevdb :DBNAME

contrib/test_decoding/sql/messages.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ COMMIT;
1919

2020
SELECT 'ignorethis' FROM pg_logical_emit_message(true, 'test', 'czechtastic');
2121

22-
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'force-binary', '0', 'skip-empty-xacts', '1');
22+
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'force-binary', '0', 'skip-empty-xacts', '1', 'include-xids', '0');
2323

2424
-- test db filtering
2525
\set prevdb :DBNAME

contrib/test_decoding/test_decoding.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,18 @@ pg_decode_message(LogicalDecodingContext *ctx,
743743
ReorderBufferTXN *txn, XLogRecPtr lsn, bool transactional,
744744
const char *prefix, Size sz, const char *message)
745745
{
746+
TestDecodingData *data = ctx->output_plugin_private;
747+
TestDecodingTxnData *txndata;
748+
749+
txndata = transactional ? txn->output_plugin_private : NULL;
750+
751+
/* output BEGIN if we haven't yet for transactional messages */
752+
if (transactional && data->skip_empty_xacts && !txndata->xact_wrote_changes)
753+
pg_output_begin(ctx, data, txn, false);
754+
755+
if (transactional)
756+
txndata->xact_wrote_changes = true;
757+
746758
OutputPluginPrepareWrite(ctx, true);
747759
appendStringInfo(ctx->out, "message: transactional: %d prefix: %s, sz: %zu content:",
748760
transactional, prefix, sz);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy