Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5a3574d

Browse files
author
Amit Kapila
committed
Test decoding of two-phase transactions during the build of a consistent snapshot.
Commit a271a1b added the capability to allow decoding at prepare time. This adds an isolation testcase to test that decoding happens at commit time when the consistent snapshot state is reached after prepare but before commit prepared. Author: Ajin Cherian Reviewed-by: Amit Kapila Discussion: https://postgr.es/m/02DA5F5E-CECE-4D9C-8B4B-418077E2C010@postgrespro.ru https://postgr.es/m/CAMGcDxeqEpWj3fTXwqhSwBdXd2RS9jzwWscO-XbeCfso6ts3+Q@mail.gmail.com
1 parent 854434c commit 5a3574d

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

contrib/test_decoding/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ REGRESS = ddl xact rewrite toast permissions decoding_in_xact \
77
decoding_into_rel binary prepared replorigin time messages \
88
spill slot truncate stream stats twophase twophase_stream
99
ISOLATION = mxact delayed_startup ondisk_startup concurrent_ddl_dml \
10-
oldest_xmin snapshot_transfer subxact_without_top concurrent_stream
10+
oldest_xmin snapshot_transfer subxact_without_top concurrent_stream \
11+
twophase_snapshot
1112

1213
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/test_decoding/logical.conf
1314
ISOLATION_OPTS = --temp-config $(top_srcdir)/contrib/test_decoding/logical.conf
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Parsed test spec with 3 sessions
2+
3+
starting permutation: s2b s2txid s1init s3b s3txid s2c s2b s2insert s2p s3c s1insert s1start s2cp s1start
4+
step s2b: BEGIN;
5+
step s2txid: SELECT pg_current_xact_id() IS NULL;
6+
?column?
7+
8+
f
9+
step s1init: SELECT 'init' FROM pg_create_logical_replication_slot('isolation_slot', 'test_decoding'); <waiting ...>
10+
step s3b: BEGIN;
11+
step s3txid: SELECT pg_current_xact_id() IS NULL;
12+
?column?
13+
14+
f
15+
step s2c: COMMIT;
16+
step s2b: BEGIN;
17+
step s2insert: INSERT INTO do_write DEFAULT VALUES;
18+
step s2p: PREPARE TRANSACTION 'test1';
19+
step s3c: COMMIT;
20+
step s1init: <... completed>
21+
?column?
22+
23+
init
24+
step s1insert: INSERT INTO do_write DEFAULT VALUES;
25+
step s1start: SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'include-xids', 'false', 'two-phase-commit', '1');
26+
data
27+
28+
BEGIN
29+
table public.do_write: INSERT: id[integer]:2
30+
COMMIT
31+
step s2cp: COMMIT PREPARED 'test1';
32+
step s1start: SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'include-xids', 'false', 'two-phase-commit', '1');
33+
data
34+
35+
BEGIN
36+
table public.do_write: INSERT: id[integer]:1
37+
PREPARE TRANSACTION 'test1'
38+
COMMIT PREPARED 'test1'
39+
?column?
40+
41+
stop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Test decoding of two-phase transactions during the build of a consistent snapshot.
2+
setup
3+
{
4+
DROP TABLE IF EXISTS do_write;
5+
CREATE TABLE do_write(id serial primary key);
6+
}
7+
8+
teardown
9+
{
10+
DROP TABLE do_write;
11+
SELECT 'stop' FROM pg_drop_replication_slot('isolation_slot');
12+
}
13+
14+
15+
session "s1"
16+
setup { SET synchronous_commit=on; }
17+
18+
step "s1init" {SELECT 'init' FROM pg_create_logical_replication_slot('isolation_slot', 'test_decoding');}
19+
step "s1start" {SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'include-xids', 'false', 'two-phase-commit', '1');}
20+
step "s1insert" { INSERT INTO do_write DEFAULT VALUES; }
21+
22+
session "s2"
23+
setup { SET synchronous_commit=on; }
24+
25+
step "s2b" { BEGIN; }
26+
step "s2txid" { SELECT pg_current_xact_id() IS NULL; }
27+
step "s2c" { COMMIT; }
28+
step "s2insert" { INSERT INTO do_write DEFAULT VALUES; }
29+
step "s2p" { PREPARE TRANSACTION 'test1'; }
30+
step "s2cp" { COMMIT PREPARED 'test1'; }
31+
32+
33+
session "s3"
34+
setup { SET synchronous_commit=on; }
35+
36+
step "s3b" { BEGIN; }
37+
step "s3txid" { SELECT pg_current_xact_id() IS NULL; }
38+
step "s3c" { COMMIT; }
39+
40+
# Force building of a consistent snapshot between a PREPARE and COMMIT PREPARED
41+
# and ensure that the whole transaction is decoded at the time of COMMIT
42+
# PREPARED.
43+
#
44+
# 's1init' step will initialize the replication slot and cause logical decoding
45+
# to wait in initial starting point till the in-progress transaction in s2 is
46+
# committed. 's2c' step will cause logical decoding to go to initial consistent
47+
# point and wait for in-progress transaction s3 to commit. 's3c' step will cause
48+
# logical decoding to find a consistent point while the transaction s2 is
49+
# prepared and not yet committed. This will cause the first s1start to skip
50+
# prepared transaction s2 as that will be before consistent point. The second
51+
# s1start will allow decoding of skipped prepare along with commit prepared done
52+
# as part of s2cp.
53+
permutation "s2b" "s2txid" "s1init" "s3b" "s3txid" "s2c" "s2b" "s2insert" "s2p" "s3c" "s1insert" "s1start" "s2cp" "s1start"

0 commit comments

Comments
 (0)