Don't advance origin during apply failure.

The logical replication parallel apply worker could incorrectly advance
the origin progress during an error or failed apply. This behavior risks
transaction loss because such transactions will not be resent by the
server.

Commit 3f28b2fcac addressed a similar issue for both the apply worker and
the table sync worker by registering a before_shmem_exit callback to reset
origin information. This prevents the worker from advancing the origin
during transaction abortion on shutdown. This patch applies the same fix
to the parallel apply worker, ensuring consistent behavior across all
worker types.

As with 3f28b2fcac, we are backpatching through version 16, since parallel
apply mode was introduced there and the issue only occurs when changes are
applied before the transaction end record (COMMIT or ABORT) is received.

Author: Hou Zhijie <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Backpatch-through: 16
Discussion: 
https://postgr.es/m/ty4pr01mb169078771fb31b395ab496a6b94...@ty4pr01mb16907.jpnprd01.prod.outlook.com
Discussion: 
https://postgr.es/m/tyapr01mb5692fac23be40c69da8ed4aff5...@tyapr01mb5692.jpnprd01.prod.outlook.com

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0ed8f1afb15f5913458b0363c0eb818e758f97bd

Modified Files
--------------
src/backend/replication/logical/worker.c       | 30 +++++++++--------
src/test/subscription/t/023_twophase_stream.pl | 45 ++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 13 deletions(-)

Reply via email to