Skip to content

Commit 5606374

Browse files
committed
do not create extra begin before commit_prepared
1 parent ab927a6 commit 5606374

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

reinit.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ reinit_master() {
2323
./install/bin/pg_ctl -sw -D ./install/data -l ./install/data/logfile start
2424
./install/bin/createdb stas
2525
./install/bin/psql -c "create table t(id int);"
26+
./install/bin/psql -c "SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'pglogical_output');"
27+
./install/bin/psql <<SQL
28+
begin;
29+
insert into t values (42);
30+
prepare transaction 'x';
31+
commit prepared 'x';
32+
SQL
2633
}
2734

2835
reinit_slave() {

src/backend/replication/logical/decode.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,12 @@ DecodeCommit(LogicalDecodingContext *ctx, XLogRecordBuffer *buf,
474474
commit_time = parsed->origin_timestamp;
475475
}
476476

477+
if (TransactionIdIsValid(parsed->twophase_xid)) {
478+
ReorderBufferCommitPrepared(ctx->reorder, xid, buf->origptr, buf->endptr,
479+
commit_time, origin_id, origin_lsn);
480+
return;
481+
}
482+
477483
/*
478484
* Process invalidation messages, even if we're not interested in the
479485
* transaction's contents, since the various caches need to always be
@@ -558,9 +564,7 @@ DecodePrepare(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
558564
RelFileNode *abortrels;
559565
SharedInvalidationMessage *invalmsgs;
560566

561-
562-
563-
// probably there are no origin
567+
// probably there are no origin -- origin stored in hdr
564568
// if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
565569
// {
566570
// origin_lsn = parsed->origin_lsn;

src/backend/replication/logical/reorderbuffer.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,26 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
16101610
PG_END_TRY();
16111611
}
16121612

1613+
void
1614+
ReorderBufferCommitPrepared(ReorderBuffer *rb, TransactionId xid,
1615+
XLogRecPtr commit_lsn, XLogRecPtr end_lsn,
1616+
TimestampTz commit_time,
1617+
RepOriginId origin_id, XLogRecPtr origin_lsn)
1618+
{
1619+
ReorderBufferTXN *txn;
1620+
1621+
txn = ReorderBufferTXNByXid(rb, xid, true, NULL, commit_lsn,
1622+
true);
1623+
1624+
txn->final_lsn = commit_lsn;
1625+
txn->end_lsn = end_lsn;
1626+
txn->commit_time = commit_time;
1627+
txn->origin_id = origin_id;
1628+
txn->origin_lsn = origin_lsn;
1629+
1630+
rb->commit(rb, txn, commit_lsn);
1631+
}
1632+
16131633
/*
16141634
* Abort a transaction that possibly has previous changes. Needs to be first
16151635
* called for subtransactions and then for the toplevel xid.

src/include/replication/reorderbuffer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ void ReorderBufferQueueChange(ReorderBuffer *, TransactionId, XLogRecPtr lsn, R
350350
void ReorderBufferCommit(ReorderBuffer *, TransactionId,
351351
XLogRecPtr commit_lsn, XLogRecPtr end_lsn,
352352
TimestampTz commit_time, RepOriginId origin_id, XLogRecPtr origin_lsn);
353+
void ReorderBufferCommitPrepared(ReorderBuffer *rb, TransactionId xid,
354+
XLogRecPtr commit_lsn, XLogRecPtr end_lsn,
355+
TimestampTz commit_time,
356+
RepOriginId origin_id, XLogRecPtr origin_lsn);
353357
void ReorderBufferAssignChild(ReorderBuffer *, TransactionId, TransactionId, XLogRecPtr commit_lsn);
354358
void ReorderBufferCommitChild(ReorderBuffer *, TransactionId, TransactionId,
355359
XLogRecPtr commit_lsn, XLogRecPtr end_lsn);

0 commit comments

Comments
 (0)