postgresql/src/include/replication
Amit Kapila 68dcce247f Fix catalog lookup with the wrong snapshot during logical decoding.
Previously, we relied on HEAP2_NEW_CID records and XACT_INVALIDATION
records to know if the transaction has modified the catalog, and that
information is not serialized to snapshot. Therefore, after the restart,
if the logical decoding decodes only the commit record of the transaction
that has actually modified a catalog, we will miss adding its XID to the
snapshot. Thus, we will end up looking at catalogs with the wrong
snapshot.

To fix this problem, this changes the snapshot builder so that it
remembers the last-running-xacts list of the decoded RUNNING_XACTS record
after restoring the previously serialized snapshot. Then, we mark the
transaction as containing catalog changes if it's in the list of initial
running transactions and its commit record has XACT_XINFO_HAS_INVALS. To
avoid ABI breakage, we store the array of the initial running transactions
in the static variables InitialRunningXacts and NInitialRunningXacts,
instead of storing those in SnapBuild or ReorderBuffer.

This approach has a false positive; we could end up adding the transaction
that didn't change catalog to the snapshot since we cannot distinguish
whether the transaction has catalog changes only by checking the COMMIT
record. It doesn't have the information on which (sub) transaction has
catalog changes, and XACT_XINFO_HAS_INVALS doesn't necessarily indicate
that the transaction has catalog change. But that won't be a problem since
we use snapshot built during decoding only to read system catalogs.

On the master branch, we took a more future-proof approach by writing
catalog modifying transactions to the serialized snapshot which avoids the
above false positive. But we cannot backpatch it because of a change in
the SnapBuild.

Reported-by: Mike Oh
Author: Masahiko Sawada
Reviewed-by: Amit Kapila, Shi yu, Takamichi Osumi, Kyotaro Horiguchi, Bertrand Drouvot, Ahsan Hadi
Backpatch-through: 10
Discussion: https://postgr.es/m/81D0D8B0-E7C4-4999-B616-1E5004DBDCD2%40amazon.com
2022-08-11 09:45:04 +05:30
..
backup_manifest.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
basebackup.h Code review for server's handling of "tablespace map" files. 2021-03-17 16:18:46 -04:00
decode.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
logical.h Fix the logical replication timeout during large transactions. 2022-05-11 10:51:04 +05:30
logicallauncher.h Allow multiple xacts during table sync in logical replication. 2021-02-12 07:41:51 +05:30
logicalproto.h Allow pgoutput to send logical decoding messages. 2021-04-06 08:40:47 +05:30
logicalrelation.h Fix data inconsistency between publisher and subscriber. 2022-06-16 08:32:10 +05:30
logicalworker.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
message.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
origin.h Add some const decorations 2021-06-10 16:21:48 +02:00
output_plugin.h Add a xid argument to the filter_prepare callback for output plugins. 2021-03-30 10:34:43 +05:30
pgoutput.h Allow pgoutput to send logical decoding messages. 2021-04-06 08:40:47 +05:30
reorderbuffer.h Fix decoding of speculative aborts. 2021-06-15 08:28:36 +05:30
slot.h Advance old-segment horizon properly after slot invalidation 2021-07-16 12:07:30 -04:00
snapbuild.h Fix catalog lookup with the wrong snapshot during logical decoding. 2022-08-11 09:45:04 +05:30
syncrep.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
walreceiver.h Add condition variable for walreceiver shutdown. 2021-03-12 19:45:42 +13:00
walsender.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
walsender_private.h Fix limitations on what SQL commands can be issued to a walsender. 2022-01-24 15:33:34 -05:00
worker_internal.h Rename the logical replication global "wrconn" 2021-05-12 19:13:54 -04:00