Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b77048

Browse files
author
Amit Kapila
committed
Fix catalog lookup due to wrong snapshot for subtransactions during decoding.
In commit272248a, we fixed the catalog lookup due to the wrong snapshotfor transactions and subtransactions during decoding. We failed toconsider the case where top-level xact is already marked as containingcatalog change but its subtransaction is not yet marked as containingcatalog change even though it contained such a change.This can happen when during decoding, none of the WAL records from thesubtransaction was decoded and top-level xact contains a DDL.We fix it by marking the transaction and all its subtransactions ascontaining catalog changes if the top-level xact contains any catalogchange and it is present in the initial running xacts array.This fix is required only for 14 and 15 because in prior branches wealready always mark the transaction and all its subtransactions ascontaining catalog changes in the same case. In 16 and above, we preservethe list of transaction IDs and sub-transaction IDs, that have modifiedcatalogs and are running during snapshot serialization, to the serializedsnapshot (see commit7f13ac8).Author: Fei ChanghongReviewed-by: Amit Kapila, Hayato Kuroda, Andy FanDiscussion:https://postgr.es/m/18280-4c8060178cb41750@postgresql.org
1 parent3eb8a87 commit6b77048

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

‎contrib/test_decoding/expected/catalog_change_snapshot.out

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,47 @@ COMMIT
132132
stop
133133
(1 row)
134134

135+
136+
starting permutation: s0_init s0_begin s0_savepoint s0_create_part1 s0_savepoint_release s1_checkpoint s0_create_part2 s0_commit s0_begin s0_truncate s1_checkpoint s1_get_changes s0_insert_part s1_get_changes s0_commit s1_get_changes
137+
step s0_init: SELECT 'init' FROM pg_create_logical_replication_slot('isolation_slot', 'test_decoding');
138+
?column?
139+
--------
140+
init
141+
(1 row)
142+
143+
step s0_begin: BEGIN;
144+
step s0_savepoint: SAVEPOINT sp1;
145+
step s0_create_part1: CREATE TABLE tbl1_part_p1 PARTITION OF tbl1_part FOR VALUES FROM (0) TO (10);
146+
step s0_savepoint_release: RELEASE SAVEPOINT sp1;
147+
step s1_checkpoint: CHECKPOINT;
148+
step s0_create_part2: CREATE TABLE tbl1_part_p2 PARTITION OF tbl1_part FOR VALUES FROM (10) TO (20);
149+
step s0_commit: COMMIT;
150+
step s0_begin: BEGIN;
151+
step s0_truncate: TRUNCATE tbl1;
152+
step s1_checkpoint: CHECKPOINT;
153+
step s1_get_changes: SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0');
154+
data
155+
----
156+
(0 rows)
157+
158+
step s0_insert_part: INSERT INTO tbl1_part VALUES (1);
159+
step s1_get_changes: SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0');
160+
data
161+
----
162+
(0 rows)
163+
164+
step s0_commit: COMMIT;
165+
step s1_get_changes: SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0');
166+
data
167+
--------------------------------------------------
168+
BEGIN
169+
table public.tbl1: TRUNCATE: (no-flags)
170+
table public.tbl1_part_p1: INSERT: val1[integer]:1
171+
COMMIT
172+
(4 rows)
173+
174+
?column?
175+
--------
176+
stop
177+
(1 row)
178+

‎contrib/test_decoding/specs/catalog_change_snapshot.spec

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
setup
44
{
55
DROPTABLEIFEXISTStbl1;
6+
DROPTABLEIFEXISTStbl1_part;
67
CREATETABLEtbl1(val1integer,val2integer);
8+
CREATETABLEtbl1_part(val1integer)PARTITIONBYRANGE(val1);
79
CREATETABLEuser_cat(val1integer)WITH(user_catalog_table=true);
810
}
911

1012
teardown
1113
{
1214
DROPTABLEtbl1;
15+
DROPTABLEtbl1_part;
1316
DROPTABLEuser_cat;
1417
SELECT'stop'FROMpg_drop_replication_slot('isolation_slot');
1518
}
@@ -19,9 +22,13 @@ setup { SET synchronous_commit=on; }
1922
step"s0_init"{SELECT'init'FROMpg_create_logical_replication_slot('isolation_slot','test_decoding');}
2023
step"s0_begin"{ BEGIN;}
2124
step"s0_savepoint"{SAVEPOINTsp1;}
25+
step"s0_savepoint_release"{RELEASESAVEPOINTsp1;}
2226
step"s0_truncate"{TRUNCATEtbl1;}
2327
step"s0_insert"{INSERTINTOtbl1VALUES(1);}
2428
step"s0_insert2"{INSERTINTOuser_catVALUES(1);}
29+
step"s0_insert_part"{INSERTINTOtbl1_partVALUES(1);}
30+
step"s0_create_part1"{CREATETABLEtbl1_part_p1PARTITIONOFtbl1_partFORVALUESFROM(0)TO(10);}
31+
step"s0_create_part2"{CREATETABLEtbl1_part_p2PARTITIONOFtbl1_partFORVALUESFROM(10)TO(20);}
2532
step"s0_commit"{COMMIT;}
2633

2734
session"s1"
@@ -60,3 +67,11 @@ permutation "s0_init" "s0_begin" "s0_savepoint" "s0_insert" "s1_checkpoint" "s1_
6067
# to skip this xact but ensure that corresponding invalidation messages
6168
# get processed.
6269
permutation"s0_init""s0_begin""s0_savepoint""s0_insert""s1_checkpoint""s1_get_changes""s0_truncate""s0_commit""s0_begin""s0_insert""s1_checkpoint""s1_get_changes""s0_commit""s1_get_changes"
70+
71+
# The last decoding restarts from the first checkpoint and doesn't decode
72+
# any WAL records generated by the subtransaction that performed s0_create_part1.
73+
# While processing the commit record for the corresponding top-level transaction
74+
# which will be marked as containing catalog change even before commit, we ensure
75+
# that the corresponding substransaction is also marked as containing a catalog
76+
# modifying change.
77+
permutation"s0_init""s0_begin""s0_savepoint""s0_create_part1""s0_savepoint_release""s1_checkpoint""s0_create_part2""s0_commit""s0_begin""s0_truncate""s1_checkpoint""s1_get_changes""s0_insert_part""s1_get_changes""s0_commit""s1_get_changes"

‎src/backend/replication/logical/snapbuild.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,11 +2119,13 @@ SnapBuildXidSetCatalogChanges(SnapBuild *builder, TransactionId xid, int subxcnt
21192119
TransactionId*subxacts,XLogRecPtrlsn)
21202120
{
21212121
/*
2122-
* Skip if there is no initial running xacts information or the
2123-
* transaction is already marked as containing catalog changes.
2122+
* Skip if there is no initial running xacts information.
2123+
*
2124+
* Even if the transaction has been marked as containing catalog
2125+
* changes, it cannot be skipped because its subtransactions that
2126+
* modified the catalog may not be marked.
21242127
*/
2125-
if (NInitialRunningXacts==0||
2126-
ReorderBufferXidHasCatalogChanges(builder->reorder,xid))
2128+
if (NInitialRunningXacts==0)
21272129
return;
21282130

21292131
if (bsearch(&xid,InitialRunningXacts,NInitialRunningXacts,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp