mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
When constructing a historic snapshot for logical decoding,
reorderbuffer needs to keep track of movement of tuples in catalog
tables. For the most part this works correctly, except that when a
subtransaction that wrote a catalog tuple aborts, we failed to "forget"
about that change. There's no known reports of anything actually
breaking except assertion failures, but it is likely possible to
construct cases where historical snapshots produce bogus visibility
answers, potentially causing incorrect decoding output.
To fix, have the decode of a subtransaction abort go over the TUPLECID
list that has been accumulated on the ReorderBufferTXN for its topmost
parent transaction, and remove all the entries that were marked as
originating from the aborted subtransaction or its children. There are
some little details in which various devils lie, which the added code
comments explain (we hope).
Add a couple of isolation test cases that trip the assertions with the
original coding. They're not ideal test design, because they pass in
non-assert builds without the fix. But we'd rather have the fix be
verified in that limited scenario than nowhere at all, and they are
cheap enough.
This bug is sibling to the one fixed in commit 8c67d29fd5 and, like
that one, it goes all the way back to the introduction of
reorderbuffers, so backpatch to all live branches.
While reviewing this, I (Álvaro) was bothered by the snapmgr.c
tuplecid_data file-scoped variable, as it's easily confused with a
function parameter used widely in reorderbuffer.c. In branches 19 and
master, rename that to avoid confusion.
Reported-by: Arseny Sher <a.sher@postgrespro.ru>
Reported-by: Mark Dilger <mark.dilger@enterprisedb.com>
Reported-by: Alexander Kozhemyakin <a.kozhemyakin@postgrespro.ru>
Author: Bingshuai Li <lucian1412@outlook.com>
Author: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Author: Zhijie Hou <houzhijie22@gmail.com>
Backpatch-through: 14
Bug: #19555
Discussion: https://postgr.es/m/87r2c8xocq.fsf@ars-thinkpad
Discussion: https://postgr.es/m/CAHgHdKu5e3XY5e90Tuaxq_R4WrKxSV734Q%2BLwo5y39Omp2A-Gg@mail.gmail.com
Discussion: https://postgr.es/m/19555-3c700f40a13045cd@postgresql.org
33 lines
1.2 KiB
Plaintext
33 lines
1.2 KiB
Plaintext
Parsed test spec with 3 sessions
|
|
|
|
starting permutation: s1_init s0_begin s0_topwrite s0_outer s0_inner s0_catinsert1 s0_release_inner s0_rollback_outer s2_vacuum s0_catinsert2 s0_commit s1_get_changes
|
|
step s1_init: SELECT 'init' FROM pg_create_logical_replication_slot('tuplecid_nested_slot', 'test_decoding');
|
|
?column?
|
|
--------
|
|
init
|
|
(1 row)
|
|
|
|
step s0_begin: BEGIN;
|
|
step s0_topwrite: INSERT INTO tbl1 VALUES (0);
|
|
step s0_outer: SAVEPOINT outer_sp;
|
|
step s0_inner: SAVEPOINT inner_sp;
|
|
step s0_catinsert1: INSERT INTO user_cat VALUES (5, 'e');
|
|
step s0_release_inner: RELEASE SAVEPOINT inner_sp;
|
|
step s0_rollback_outer: ROLLBACK TO SAVEPOINT outer_sp;
|
|
step s2_vacuum: VACUUM user_cat;
|
|
step s0_catinsert2: INSERT INTO user_cat VALUES (6, 'f');
|
|
step s0_commit: COMMIT;
|
|
step s1_get_changes: SELECT data FROM pg_logical_slot_get_changes('tuplecid_nested_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0') WHERE data NOT LIKE '%user_cat%';
|
|
data
|
|
------------------------------------------
|
|
BEGIN
|
|
table public.tbl1: INSERT: val1[integer]:0
|
|
COMMIT
|
|
(3 rows)
|
|
|
|
?column?
|
|
--------
|
|
stop
|
|
(1 row)
|
|
|