@@ -69,6 +69,7 @@ static void pg_decode_begin_txn(LogicalDecodingContext *ctx,
69
69
static void pg_decode_commit_txn (LogicalDecodingContext * ctx ,
70
70
ReorderBufferTXN * txn , XLogRecPtr commit_lsn );
71
71
72
+ static void pg_decode_begin_prepare_txn (LogicalDecodingContext * ctx , ReorderBufferTXN * txn );
72
73
static void pg_decode_prepare_txn (LogicalDecodingContext * ctx , ReorderBufferTXN * txn ,
73
74
XLogRecPtr lsn );
74
75
static void pg_decode_commit_prepared_txn (LogicalDecodingContext * ctx , ReorderBufferTXN * txn ,
@@ -135,6 +136,7 @@ _PG_output_plugin_init(OutputPluginCallbacks *cb)
135
136
cb -> abort_cb = pg_decode_abort_txn ;
136
137
137
138
cb -> filter_prepare_cb = pg_filter_prepare ;
139
+ cb -> begin_prepare_cb = pg_decode_begin_prepare_txn ;
138
140
cb -> prepare_cb = pg_decode_prepare_txn ;
139
141
cb -> commit_prepared_cb = pg_decode_commit_prepared_txn ;
140
142
cb -> rollback_prepared_cb = pg_decode_abort_prepared_txn ;
@@ -482,6 +484,46 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
482
484
}
483
485
}
484
486
487
+ void
488
+ pg_decode_begin_prepare_txn (LogicalDecodingContext * ctx , ReorderBufferTXN * txn )
489
+ {
490
+ PGLogicalOutputData * data = (PGLogicalOutputData * ) ctx -> output_plugin_private ;
491
+ bool send_replication_origin = data -> forward_changeset_origins ;
492
+
493
+ if (!startup_message_sent )
494
+ send_startup_message (ctx , data , false /* can't be last message */ );
495
+
496
+ /* If the record didn't originate locally, send origin info */
497
+ send_replication_origin &= txn -> origin_id != InvalidRepOriginId ;
498
+
499
+ if (data -> api )
500
+ {
501
+ MtmOutputPluginPrepareWrite (ctx , !send_replication_origin , true);
502
+ data -> api -> write_begin (ctx -> out , data , txn );
503
+
504
+ if (send_replication_origin )
505
+ {
506
+ char * origin ;
507
+
508
+ /* Message boundary */
509
+ MtmOutputPluginWrite (ctx , false, false);
510
+ MtmOutputPluginPrepareWrite (ctx , true, false);
511
+
512
+ /*
513
+ * XXX: which behaviour we want here?
514
+ *
515
+ * Alternatives: - don't send origin message if origin name not
516
+ * found (that's what we do now) - throw error - that will break
517
+ * replication, not good - send some special "unknown" origin
518
+ */
519
+ if (data -> api -> write_origin &&
520
+ replorigin_by_oid (txn -> origin_id , true, & origin ))
521
+ data -> api -> write_origin (ctx -> out , origin , txn -> origin_lsn );
522
+ }
523
+ MtmOutputPluginWrite (ctx , true, false);
524
+ }
525
+ }
526
+
485
527
void
486
528
pg_decode_prepare_txn (LogicalDecodingContext * ctx , ReorderBufferTXN * txn ,
487
529
XLogRecPtr lsn )
0 commit comments