@@ -69,6 +69,7 @@ static void pg_decode_begin_txn(LogicalDecodingContext *ctx,
6969static void pg_decode_commit_txn (LogicalDecodingContext * ctx ,
7070 ReorderBufferTXN * txn , XLogRecPtr commit_lsn );
7171
72+ static void pg_decode_begin_prepare_txn (LogicalDecodingContext * ctx , ReorderBufferTXN * txn );
7273static void pg_decode_prepare_txn (LogicalDecodingContext * ctx , ReorderBufferTXN * txn ,
7374 XLogRecPtr lsn );
7475static void pg_decode_commit_prepared_txn (LogicalDecodingContext * ctx , ReorderBufferTXN * txn ,
@@ -135,6 +136,7 @@ _PG_output_plugin_init(OutputPluginCallbacks *cb)
135136 cb -> abort_cb = pg_decode_abort_txn ;
136137
137138 cb -> filter_prepare_cb = pg_filter_prepare ;
139+ cb -> begin_prepare_cb = pg_decode_begin_prepare_txn ;
138140 cb -> prepare_cb = pg_decode_prepare_txn ;
139141 cb -> commit_prepared_cb = pg_decode_commit_prepared_txn ;
140142 cb -> rollback_prepared_cb = pg_decode_abort_prepared_txn ;
@@ -482,6 +484,46 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
482484 }
483485}
484486
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+
485527void
486528pg_decode_prepare_txn (LogicalDecodingContext * ctx , ReorderBufferTXN * txn ,
487529 XLogRecPtr lsn )
0 commit comments