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

Commit 278cdea

Browse files
committed
Add isolation test for errors during logical slot creation.
I didn't include this test in 2f6501f, because I was not sure the error messages for the terminated connection is stable across platforms. But it sounds like it is, and if not, we'd want to do something about the instability anyway... Discussion: https://postgr.es/m/CAD21AoDAeEpAbZEyYJsPZJUmSPaRicVSBObaL7sPaofnKz+9zg@mail.gmail.com
1 parent a4e1deb commit 278cdea

File tree

3 files changed

+155
-1
lines changed

3 files changed

+155
-1
lines changed

contrib/test_decoding/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ REGRESS = ddl xact rewrite toast permissions decoding_in_xact \
99
sequence
1010
ISOLATION = mxact delayed_startup ondisk_startup concurrent_ddl_dml \
1111
oldest_xmin snapshot_transfer subxact_without_top concurrent_stream \
12-
twophase_snapshot
12+
twophase_snapshot slot_creation_error
1313

1414
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/test_decoding/logical.conf
1515
ISOLATION_OPTS = --temp-config $(top_srcdir)/contrib/test_decoding/logical.conf
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
Parsed test spec with 2 sessions
2+
3+
starting permutation: s1_b s1_xid s2_init s1_view_slot s1_cancel_s2 s1_view_slot s1_c
4+
step s1_b: BEGIN;
5+
step s1_xid: SELECT 'xid' FROM txid_current();
6+
?column?
7+
--------
8+
xid
9+
(1 row)
10+
11+
step s2_init:
12+
SELECT 'init' FROM pg_create_logical_replication_slot('slot_creation_error', 'test_decoding');
13+
<waiting ...>
14+
step s1_view_slot:
15+
SELECT slot_name, slot_type, active FROM pg_replication_slots WHERE slot_name = 'slot_creation_error'
16+
17+
slot_name |slot_type|active
18+
-------------------+---------+------
19+
slot_creation_error|logical |t
20+
(1 row)
21+
22+
step s1_cancel_s2:
23+
SELECT pg_cancel_backend(pid)
24+
FROM pg_stat_activity
25+
WHERE application_name = 'isolation/slot_creation_error/s2';
26+
27+
pg_cancel_backend
28+
-----------------
29+
t
30+
(1 row)
31+
32+
step s2_init: <... completed>
33+
ERROR: canceling statement due to user request
34+
step s1_view_slot:
35+
SELECT slot_name, slot_type, active FROM pg_replication_slots WHERE slot_name = 'slot_creation_error'
36+
37+
slot_name|slot_type|active
38+
---------+---------+------
39+
(0 rows)
40+
41+
step s1_c: COMMIT;
42+
43+
starting permutation: s1_b s1_xid s2_init s1_c s1_view_slot s1_drop_slot
44+
step s1_b: BEGIN;
45+
step s1_xid: SELECT 'xid' FROM txid_current();
46+
?column?
47+
--------
48+
xid
49+
(1 row)
50+
51+
step s2_init:
52+
SELECT 'init' FROM pg_create_logical_replication_slot('slot_creation_error', 'test_decoding');
53+
<waiting ...>
54+
step s1_c: COMMIT;
55+
step s2_init: <... completed>
56+
?column?
57+
--------
58+
init
59+
(1 row)
60+
61+
step s1_view_slot:
62+
SELECT slot_name, slot_type, active FROM pg_replication_slots WHERE slot_name = 'slot_creation_error'
63+
64+
slot_name |slot_type|active
65+
-------------------+---------+------
66+
slot_creation_error|logical |f
67+
(1 row)
68+
69+
step s1_drop_slot:
70+
SELECT pg_drop_replication_slot('slot_creation_error');
71+
72+
pg_drop_replication_slot
73+
------------------------
74+
75+
(1 row)
76+
77+
78+
starting permutation: s1_b s1_xid s2_init s1_terminate_s2 s1_c s1_view_slot
79+
step s1_b: BEGIN;
80+
step s1_xid: SELECT 'xid' FROM txid_current();
81+
?column?
82+
--------
83+
xid
84+
(1 row)
85+
86+
step s2_init:
87+
SELECT 'init' FROM pg_create_logical_replication_slot('slot_creation_error', 'test_decoding');
88+
<waiting ...>
89+
step s1_terminate_s2:
90+
SELECT pg_terminate_backend(pid)
91+
FROM pg_stat_activity
92+
WHERE application_name = 'isolation/slot_creation_error/s2';
93+
94+
pg_terminate_backend
95+
--------------------
96+
t
97+
(1 row)
98+
99+
step s2_init: <... completed>
100+
FATAL: terminating connection due to administrator command
101+
FATAL: terminating connection due to administrator command
102+
server closed the connection unexpectedly
103+
This probably means the server terminated abnormally
104+
before or while processing the request.
105+
106+
step s1_c: COMMIT;
107+
step s1_view_slot:
108+
SELECT slot_name, slot_type, active FROM pg_replication_slots WHERE slot_name = 'slot_creation_error'
109+
110+
slot_name|slot_type|active
111+
---------+---------+------
112+
(0 rows)
113+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Test that erroring out during logical slot creation is handled properly
2+
3+
session "s1"
4+
setup { SET synchronous_commit=on; }
5+
6+
step s1_b { BEGIN; }
7+
step s1_xid { SELECT 'xid' FROM txid_current(); }
8+
step s1_c { COMMIT; }
9+
step s1_cancel_s2 {
10+
SELECT pg_cancel_backend(pid)
11+
FROM pg_stat_activity
12+
WHERE application_name = 'isolation/slot_creation_error/s2';
13+
}
14+
15+
step s1_terminate_s2 {
16+
SELECT pg_terminate_backend(pid)
17+
FROM pg_stat_activity
18+
WHERE application_name = 'isolation/slot_creation_error/s2';
19+
}
20+
21+
step s1_view_slot {
22+
SELECT slot_name, slot_type, active FROM pg_replication_slots WHERE slot_name = 'slot_creation_error'
23+
}
24+
25+
step s1_drop_slot {
26+
SELECT pg_drop_replication_slot('slot_creation_error');
27+
}
28+
29+
session s2
30+
setup { SET synchronous_commit=on; }
31+
step s2_init {
32+
SELECT 'init' FROM pg_create_logical_replication_slot('slot_creation_error', 'test_decoding');
33+
}
34+
35+
# The tests first start a transaction with an xid assigned in s1, then create
36+
# a slot in s2. The slot creation waits for s1's transaction to end. Instead
37+
# we cancel / terminate s2.
38+
permutation s1_b s1_xid s2_init s1_view_slot s1_cancel_s2 s1_view_slot s1_c
39+
permutation s1_b s1_xid s2_init s1_c s1_view_slot s1_drop_slot # check slot creation still works
40+
permutation s1_b s1_xid s2_init s1_terminate_s2 s1_c s1_view_slot
41+
# can't run tests after this, due to s2's connection failure

0 commit comments

Comments
 (0)