mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Avoid repeated decoding of prepared transactions after a restart.
In commit a271a1b50e
, we allowed decoding at prepare time and the prepare
was decoded again if there is a restart after decoding it. It was done
that way because we can't distinguish between the cases where we have not
decoded the prepare because it was prior to consistent snapshot or we have
decoded it earlier but restarted. To distinguish between these two cases,
we have introduced an initial_consistent_point at the slot level which is
an LSN at which we found a consistent point at the time of slot creation.
This is also the point where we have exported a snapshot for the initial
copy. So, prepare transaction prior to this point are sent along with
commit prepared.
This commit bumps SNAPBUILD_VERSION because of change in SnapBuild. It
will break existing slots which is fine in a major release.
Author: Ajin Cherian, based on idea by Andres Freund
Reviewed-by: Amit Kapila and Vignesh C
Discussion: https://postgr.es/m/d0f60d60-133d-bf8d-bd70-47784d8fabf3@enterprisedb.com
This commit is contained in:
@ -191,9 +191,6 @@ postgres=# COMMIT PREPARED 'test_prepared1';
|
||||
postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'two-phase-commit', '1');
|
||||
lsn | xid | data
|
||||
-----------+-----+--------------------------------------------
|
||||
0/1689DC0 | 529 | BEGIN 529
|
||||
0/1689DC0 | 529 | table public.data: INSERT: id[integer]:3 data[text]:'5'
|
||||
0/1689FC0 | 529 | PREPARE TRANSACTION 'test_prepared1', txid 529
|
||||
0/168A060 | 529 | COMMIT PREPARED 'test_prepared1', txid 529
|
||||
(4 row)
|
||||
|
||||
@ -822,10 +819,8 @@ typedef bool (*LogicalDecodeFilterPrepareCB) (struct LogicalDecodingContext *ctx
|
||||
<parameter>gid</parameter> field, which is part of the
|
||||
<parameter>txn</parameter> parameter, can be used in this callback to
|
||||
check if the plugin has already received this <command>PREPARE</command>
|
||||
in which case it can skip the remaining changes of the transaction.
|
||||
This can only happen if the user restarts the decoding after receiving
|
||||
the <command>PREPARE</command> for a transaction but before receiving
|
||||
the <command>COMMIT PREPARED</command>, say because of some error.
|
||||
in which case it can either error out or skip the remaining changes of
|
||||
the transaction.
|
||||
<programlisting>
|
||||
typedef void (*LogicalDecodeBeginPrepareCB) (struct LogicalDecodingContext *ctx,
|
||||
ReorderBufferTXN *txn);
|
||||
|
Reference in New Issue
Block a user