Debian Codegraph @

contrib/test_decoding/specs/twophase_snapshot.spec

raw
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', false, true);}
19 step "s1start" {SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'include-xids', 'false', 'skip-empty-xacts', '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"