Skip to content

Commit a6a684b

Browse files
committed
add some tests
1 parent a5748fc commit a6a684b

File tree

3 files changed

+240
-0
lines changed

3 files changed

+240
-0
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
SET citus.enable_create_database_propagation TO ON;
2+
SET client_min_messages TO WARNING;
3+
SELECT citus.mitmproxy('conn.kill()');
4+
mitmproxy
5+
---------------------------------------------------------------------
6+
7+
(1 row)
8+
9+
CREATE DATABASE db1;
10+
ERROR: connection to the remote node postgres@localhost:xxxxx failed with the following error: connection not open
11+
SELECT citus.mitmproxy('conn.allow()');
12+
mitmproxy
13+
---------------------------------------------------------------------
14+
15+
(1 row)
16+
17+
CALL citus_cleanup_orphaned_resources();
18+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
19+
no_temp_databases_on_any_nodes
20+
---------------------------------------------------------------------
21+
t
22+
(1 row)
23+
24+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
25+
node_type | result
26+
---------------------------------------------------------------------
27+
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
28+
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
29+
(2 rows)
30+
31+
SELECT citus.mitmproxy('conn.onQuery(query="^CREATE DATABASE").cancel(' || pg_backend_pid() || ')');
32+
mitmproxy
33+
---------------------------------------------------------------------
34+
35+
(1 row)
36+
37+
CREATE DATABASE db1;
38+
WARNING: Commands that are not transaction-safe may result in partial failure, potentially leading to an inconsistent state.
39+
If the problematic command is a CREATE operation, consider using the 'IF EXISTS' syntax to drop the object,
40+
if applicable, and then re-attempt the original command.
41+
ERROR: canceling statement due to user request
42+
SELECT citus.mitmproxy('conn.allow()');
43+
mitmproxy
44+
---------------------------------------------------------------------
45+
46+
(1 row)
47+
48+
CALL citus_cleanup_orphaned_resources();
49+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
50+
no_temp_databases_on_any_nodes
51+
---------------------------------------------------------------------
52+
t
53+
(1 row)
54+
55+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
56+
node_type | result
57+
---------------------------------------------------------------------
58+
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
59+
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
60+
(2 rows)
61+
62+
SELECT citus.mitmproxy('conn.onQuery(query="^ALTER DATABASE").cancel(' || pg_backend_pid() || ')');
63+
mitmproxy
64+
---------------------------------------------------------------------
65+
66+
(1 row)
67+
68+
CREATE DATABASE db1;
69+
ERROR: canceling statement due to user request
70+
SELECT citus.mitmproxy('conn.allow()');
71+
mitmproxy
72+
---------------------------------------------------------------------
73+
74+
(1 row)
75+
76+
CALL citus_cleanup_orphaned_resources();
77+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
78+
no_temp_databases_on_any_nodes
79+
---------------------------------------------------------------------
80+
t
81+
(1 row)
82+
83+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
84+
node_type | result
85+
---------------------------------------------------------------------
86+
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
87+
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
88+
(2 rows)
89+
90+
SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()');
91+
mitmproxy
92+
---------------------------------------------------------------------
93+
94+
(1 row)
95+
96+
CREATE DATABASE db1;
97+
ERROR: connection to the remote node postgres@localhost:xxxxx failed with the following error: connection not open
98+
SELECT citus.mitmproxy('conn.allow()');
99+
mitmproxy
100+
---------------------------------------------------------------------
101+
102+
(1 row)
103+
104+
CALL citus_cleanup_orphaned_resources();
105+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
106+
no_temp_databases_on_any_nodes
107+
---------------------------------------------------------------------
108+
t
109+
(1 row)
110+
111+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
112+
node_type | result
113+
---------------------------------------------------------------------
114+
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
115+
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
116+
(2 rows)
117+
118+
SELECT citus.mitmproxy('conn.onQuery(query="^PREPARE TRANSACTION").kill()');
119+
mitmproxy
120+
---------------------------------------------------------------------
121+
122+
(1 row)
123+
124+
CREATE DATABASE db1;
125+
ERROR: connection not open
126+
CONTEXT: while executing command on localhost:xxxxx
127+
SELECT citus.mitmproxy('conn.allow()');
128+
mitmproxy
129+
---------------------------------------------------------------------
130+
131+
(1 row)
132+
133+
CALL citus_cleanup_orphaned_resources();
134+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
135+
no_temp_databases_on_any_nodes
136+
---------------------------------------------------------------------
137+
t
138+
(1 row)
139+
140+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
141+
node_type | result
142+
---------------------------------------------------------------------
143+
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
144+
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
145+
(2 rows)
146+
147+
SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT PREPARED").kill()');
148+
mitmproxy
149+
---------------------------------------------------------------------
150+
151+
(1 row)
152+
153+
CREATE DATABASE db1;
154+
WARNING: connection not open
155+
CONTEXT: while executing command on localhost:xxxxx
156+
WARNING: failed to commit transaction on localhost:xxxxx
157+
SELECT citus.mitmproxy('conn.allow()');
158+
mitmproxy
159+
---------------------------------------------------------------------
160+
161+
(1 row)
162+
163+
-- not call citus_cleanup_orphaned_resources() but recover the prepared transactions this time
164+
SELECT recover_prepared_transactions();
165+
recover_prepared_transactions
166+
---------------------------------------------------------------------
167+
1
168+
(1 row)
169+
170+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
171+
no_temp_databases_on_any_nodes
172+
---------------------------------------------------------------------
173+
t
174+
(1 row)
175+
176+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
177+
node_type | result
178+
---------------------------------------------------------------------
179+
worker node (remote) | {"database_properties": {"datacl": null, "datname": "db1", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "pg_default", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false}
180+
worker node (remote) | {"database_properties": {"datacl": null, "datname": "db1", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "pg_default", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": true, "stale_pg_dist_object_record_for_a_db_exists": false}
181+
(2 rows)
182+
183+
DROP DATABASE db1;
184+
RESET client_min_messages;

src/test/regress/failure_schedule

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ test: failure_mx_metadata_sync
3535
test: failure_mx_metadata_sync_multi_trans
3636
test: failure_connection_establishment
3737
test: failure_non_main_db_2pc
38+
test: failure_create_database
3839

3940
# this test syncs metadata to the workers
4041
test: failure_failover_to_local_execution
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
SET citus.enable_create_database_propagation TO ON;
2+
SET client_min_messages TO WARNING;
3+
4+
SELECT citus.mitmproxy('conn.kill()');
5+
CREATE DATABASE db1;
6+
SELECT citus.mitmproxy('conn.allow()');
7+
8+
CALL citus_cleanup_orphaned_resources();
9+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
10+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
11+
12+
SELECT citus.mitmproxy('conn.onQuery(query="^CREATE DATABASE").cancel(' || pg_backend_pid() || ')');
13+
CREATE DATABASE db1;
14+
SELECT citus.mitmproxy('conn.allow()');
15+
16+
CALL citus_cleanup_orphaned_resources();
17+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
18+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
19+
20+
SELECT citus.mitmproxy('conn.onQuery(query="^ALTER DATABASE").cancel(' || pg_backend_pid() || ')');
21+
CREATE DATABASE db1;
22+
SELECT citus.mitmproxy('conn.allow()');
23+
24+
CALL citus_cleanup_orphaned_resources();
25+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
26+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
27+
28+
SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").kill()');
29+
CREATE DATABASE db1;
30+
SELECT citus.mitmproxy('conn.allow()');
31+
32+
CALL citus_cleanup_orphaned_resources();
33+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
34+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
35+
36+
SELECT citus.mitmproxy('conn.onQuery(query="^PREPARE TRANSACTION").kill()');
37+
CREATE DATABASE db1;
38+
SELECT citus.mitmproxy('conn.allow()');
39+
40+
CALL citus_cleanup_orphaned_resources();
41+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
42+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
43+
44+
SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT PREPARED").kill()');
45+
CREATE DATABASE db1;
46+
SELECT citus.mitmproxy('conn.allow()');
47+
48+
-- not call citus_cleanup_orphaned_resources() but recover the prepared transactions this time
49+
SELECT recover_prepared_transactions();
50+
SELECT bool_and(result::boolean) AS no_temp_databases_on_any_nodes FROM run_command_on_all_nodes($$SELECT COUNT(*)=0 FROM pg_database WHERE datname LIKE 'citus_temp_database_%'$$);
51+
SELECT * FROM public.check_database_on_all_nodes($$db1$$) ORDER BY node_type, result;
52+
53+
DROP DATABASE db1;
54+
55+
RESET client_min_messages;

0 commit comments

Comments
 (0)