mirror of https://github.com/citusdata/citus.git
Fix flaky insert_select_connection_leak (#7302)
Sometimes in CI insert_select_connection_leak would fail like this: ```diff END; SELECT worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections AS leaked_worker_1_connections, worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections AS leaked_worker_2_connections; leaked_worker_1_connections | leaked_worker_2_connections -----------------------------+----------------------------- - 0 | 0 + -1 | 0 (1 row) -- ROLLBACK BEGIN; INSERT INTO target_table SELECT * FROM source_table; INSERT INTO target_table SELECT * FROM source_table; ROLLBACK; SELECT worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections AS leaked_worker_1_connections, worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections AS leaked_worker_2_connections; leaked_worker_1_connections | leaked_worker_2_connections -----------------------------+----------------------------- - 0 | 0 + -1 | 0 (1 row) \set VERBOSITY TERSE -- Error on constraint failure BEGIN; INSERT INTO target_table SELECT * FROM source_table; SELECT worker_connection_count(:worker_1_port) AS worker_1_connections, worker_connection_count(:worker_2_port) AS worker_2_connections \gset SAVEPOINT s1; INSERT INTO target_table SELECT a, CASE WHEN a < 50 THEN b ELSE null END FROM source_table; @@ -89,15 +89,15 @@ leaked_worker_1_connections | leaked_worker_2_connections -----------------------------+----------------------------- 0 | 0 (1 row) END; SELECT worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections AS leaked_worker_1_connections, worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections AS leaked_worker_2_connections; leaked_worker_1_connections | leaked_worker_2_connections -----------------------------+----------------------------- - 0 | 0 + -1 | 0 (1 row) ``` Source: https://github.com/citusdata/citus/actions/runs/6718401194/attempts/1#summary-18258258387 A negative amount of leaked connectios is obviously not possible. For some reason there was a connection open when we checked the initial amount of connections that was closed afterwards. This could be the from the maintenance daemon or maybe from the previous test that had not fully closed its connections just yet. The change in this PR doesnt't actually fix the cause of the negative connection, but it simply considers it good as well, by changing the result to zero for negative values. With this fix we might sometimes miss a leak, because the negative number can cancel out the leak and still result in a 0. But since the negative number only occurs sometimes, we'll still find the leak often enough.pull/7321/head^2
parent
0678a2fd89
commit
b47c8b3fb0
|
@ -47,16 +47,16 @@ INSERT INTO target_table SELECT * FROM source_table;
|
||||||
INSERT INTO target_table SELECT * FROM source_table;
|
INSERT INTO target_table SELECT * FROM source_table;
|
||||||
INSERT INTO target_table SELECT * FROM source_table;
|
INSERT INTO target_table SELECT * FROM source_table;
|
||||||
INSERT INTO target_table SELECT * FROM source_table;
|
INSERT INTO target_table SELECT * FROM source_table;
|
||||||
SELECT worker_connection_count(:worker_1_port) - :worker_1_connections AS leaked_worker_1_connections,
|
SELECT GREATEST(0, worker_connection_count(:worker_1_port) - :worker_1_connections) AS leaked_worker_1_connections,
|
||||||
worker_connection_count(:worker_2_port) - :worker_2_connections AS leaked_worker_2_connections;
|
GREATEST(0, worker_connection_count(:worker_2_port) - :worker_2_connections) AS leaked_worker_2_connections;
|
||||||
leaked_worker_1_connections | leaked_worker_2_connections
|
leaked_worker_1_connections | leaked_worker_2_connections
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
0 | 0
|
0 | 0
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
END;
|
END;
|
||||||
SELECT worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections AS leaked_worker_1_connections,
|
SELECT GREATEST(0, worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections) AS leaked_worker_1_connections,
|
||||||
worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections AS leaked_worker_2_connections;
|
GREATEST(0, worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections) AS leaked_worker_2_connections;
|
||||||
leaked_worker_1_connections | leaked_worker_2_connections
|
leaked_worker_1_connections | leaked_worker_2_connections
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
0 | 0
|
0 | 0
|
||||||
|
@ -67,8 +67,8 @@ BEGIN;
|
||||||
INSERT INTO target_table SELECT * FROM source_table;
|
INSERT INTO target_table SELECT * FROM source_table;
|
||||||
INSERT INTO target_table SELECT * FROM source_table;
|
INSERT INTO target_table SELECT * FROM source_table;
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
SELECT worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections AS leaked_worker_1_connections,
|
SELECT GREATEST(0, worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections) AS leaked_worker_1_connections,
|
||||||
worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections AS leaked_worker_2_connections;
|
GREATEST(0, worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections) AS leaked_worker_2_connections;
|
||||||
leaked_worker_1_connections | leaked_worker_2_connections
|
leaked_worker_1_connections | leaked_worker_2_connections
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
0 | 0
|
0 | 0
|
||||||
|
@ -84,16 +84,16 @@ SAVEPOINT s1;
|
||||||
INSERT INTO target_table SELECT a, CASE WHEN a < 50 THEN b ELSE null END FROM source_table;
|
INSERT INTO target_table SELECT a, CASE WHEN a < 50 THEN b ELSE null END FROM source_table;
|
||||||
ERROR: null value in column "b" violates not-null constraint
|
ERROR: null value in column "b" violates not-null constraint
|
||||||
ROLLBACK TO SAVEPOINT s1;
|
ROLLBACK TO SAVEPOINT s1;
|
||||||
SELECT worker_connection_count(:worker_1_port) - :worker_1_connections AS leaked_worker_1_connections,
|
SELECT GREATEST(0, worker_connection_count(:worker_1_port) - :worker_1_connections) AS leaked_worker_1_connections,
|
||||||
worker_connection_count(:worker_2_port) - :worker_2_connections AS leaked_worker_2_connections;
|
GREATEST(0, worker_connection_count(:worker_2_port) - :worker_2_connections) AS leaked_worker_2_connections;
|
||||||
leaked_worker_1_connections | leaked_worker_2_connections
|
leaked_worker_1_connections | leaked_worker_2_connections
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
0 | 0
|
0 | 0
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
END;
|
END;
|
||||||
SELECT worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections AS leaked_worker_1_connections,
|
SELECT GREATEST(0, worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections) AS leaked_worker_1_connections,
|
||||||
worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections AS leaked_worker_2_connections;
|
GREATEST(0, worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections) AS leaked_worker_2_connections;
|
||||||
leaked_worker_1_connections | leaked_worker_2_connections
|
leaked_worker_1_connections | leaked_worker_2_connections
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
0 | 0
|
0 | 0
|
||||||
|
|
|
@ -33,12 +33,12 @@ INSERT INTO target_table SELECT * FROM source_table;
|
||||||
INSERT INTO target_table SELECT * FROM source_table;
|
INSERT INTO target_table SELECT * FROM source_table;
|
||||||
INSERT INTO target_table SELECT * FROM source_table;
|
INSERT INTO target_table SELECT * FROM source_table;
|
||||||
INSERT INTO target_table SELECT * FROM source_table;
|
INSERT INTO target_table SELECT * FROM source_table;
|
||||||
SELECT worker_connection_count(:worker_1_port) - :worker_1_connections AS leaked_worker_1_connections,
|
SELECT GREATEST(0, worker_connection_count(:worker_1_port) - :worker_1_connections) AS leaked_worker_1_connections,
|
||||||
worker_connection_count(:worker_2_port) - :worker_2_connections AS leaked_worker_2_connections;
|
GREATEST(0, worker_connection_count(:worker_2_port) - :worker_2_connections) AS leaked_worker_2_connections;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
SELECT worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections AS leaked_worker_1_connections,
|
SELECT GREATEST(0, worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections) AS leaked_worker_1_connections,
|
||||||
worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections AS leaked_worker_2_connections;
|
GREATEST(0, worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections) AS leaked_worker_2_connections;
|
||||||
|
|
||||||
-- ROLLBACK
|
-- ROLLBACK
|
||||||
BEGIN;
|
BEGIN;
|
||||||
|
@ -46,8 +46,8 @@ INSERT INTO target_table SELECT * FROM source_table;
|
||||||
INSERT INTO target_table SELECT * FROM source_table;
|
INSERT INTO target_table SELECT * FROM source_table;
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
|
|
||||||
SELECT worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections AS leaked_worker_1_connections,
|
SELECT GREATEST(0, worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections) AS leaked_worker_1_connections,
|
||||||
worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections AS leaked_worker_2_connections;
|
GREATEST(0, worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections) AS leaked_worker_2_connections;
|
||||||
|
|
||||||
\set VERBOSITY TERSE
|
\set VERBOSITY TERSE
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ SELECT worker_connection_count(:worker_1_port) AS worker_1_connections,
|
||||||
SAVEPOINT s1;
|
SAVEPOINT s1;
|
||||||
INSERT INTO target_table SELECT a, CASE WHEN a < 50 THEN b ELSE null END FROM source_table;
|
INSERT INTO target_table SELECT a, CASE WHEN a < 50 THEN b ELSE null END FROM source_table;
|
||||||
ROLLBACK TO SAVEPOINT s1;
|
ROLLBACK TO SAVEPOINT s1;
|
||||||
SELECT worker_connection_count(:worker_1_port) - :worker_1_connections AS leaked_worker_1_connections,
|
SELECT GREATEST(0, worker_connection_count(:worker_1_port) - :worker_1_connections) AS leaked_worker_1_connections,
|
||||||
worker_connection_count(:worker_2_port) - :worker_2_connections AS leaked_worker_2_connections;
|
GREATEST(0, worker_connection_count(:worker_2_port) - :worker_2_connections) AS leaked_worker_2_connections;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
SELECT worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections AS leaked_worker_1_connections,
|
SELECT GREATEST(0, worker_connection_count(:worker_1_port) - :pre_xact_worker_1_connections) AS leaked_worker_1_connections,
|
||||||
worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections AS leaked_worker_2_connections;
|
GREATEST(0, worker_connection_count(:worker_2_port) - :pre_xact_worker_2_connections) AS leaked_worker_2_connections;
|
||||||
|
|
||||||
SET client_min_messages TO WARNING;
|
SET client_min_messages TO WARNING;
|
||||||
DROP SCHEMA insert_select_connection_leak CASCADE;
|
DROP SCHEMA insert_select_connection_leak CASCADE;
|
||||||
|
|
Loading…
Reference in New Issue