instr_in_shmem_terminate.out 9.3 KB
Newer Older
W
Wang Hao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
-- start_ignore
-- Isolation test for instrumentation in shmem
-- One session executing a query then another session
-- try to cancel/terminate the query, instrumentation
-- slots in shmem should be recycled correctly.

DROP SCHEMA IF EXISTS QUERY_METRICS CASCADE;
DROP
CREATE SCHEMA QUERY_METRICS;
CREATE
SET SEARCH_PATH=QUERY_METRICS;
SET

CREATE EXTERNAL WEB TABLE __gp_localid ( localid    int ) EXECUTE E'echo $GP_SEGMENT_ID' FORMAT 'TEXT';
CREATE
GRANT SELECT ON TABLE __gp_localid TO public;
GRANT

CREATE EXTERNAL WEB TABLE __gp_masterid ( masterid    int ) EXECUTE E'echo $GP_SEGMENT_ID' ON MASTER FORMAT 'TEXT';
CREATE
GRANT SELECT ON TABLE __gp_masterid TO public;
GRANT

CREATE FUNCTION gp_instrument_shmem_detail_f() RETURNS SETOF RECORD AS '$libdir/gp_instrument_shmem', 'gp_instrument_shmem_detail' LANGUAGE C IMMUTABLE;
CREATE
GRANT EXECUTE ON FUNCTION gp_instrument_shmem_detail_f() TO public;
GRANT

29
CREATE VIEW gp_instrument_shmem_detail AS WITH all_entries AS ( SELECT C.* FROM __gp_localid, gp_instrument_shmem_detail_f() as C ( tmid int4,ssid int4,ccnt int4,segid int2,pid int4 ,nid int2,tuplecount int8,nloops int8,ntuples int8 ) UNION ALL SELECT C.* FROM __gp_masterid, gp_instrument_shmem_detail_f() as C ( tmid int4,ssid int4,ccnt int4,segid int2,pid int4 ,nid int2,tuplecount int8,nloops int8,ntuples int8 )) SELECT tmid, ssid, ccnt,segid, pid, nid, tuplecount, nloops, ntuples FROM all_entries ORDER BY segid;
W
Wang Hao 已提交
30 31
CREATE

32
CREATE TABLE a (id int, c char) DISTRIBUTED BY (id);
W
Wang Hao 已提交
33
CREATE
34
INSERT INTO a SELECT *, 'a' FROM generate_series(1, 50);
W
Wang Hao 已提交
35 36 37 38 39 40 41
INSERT 50
SET OPTIMIZER=OFF;
SET
ANALYZE a;
ANALYZE
-- end_ignore

42
-- test 1: pg_terminate_backend
W
Wang Hao 已提交
43 44
-- only this query in instrument slots, expected 1
SELECT count(*) FROM (SELECT 1 FROM gp_instrument_shmem_detail GROUP BY ssid, ccnt) t;
45 46 47
 count 
-------
 1     
W
Wang Hao 已提交
48 49 50 51 52
(1 row)

CREATE TABLE foo AS SELECT i a, i b FROM generate_series(1, 10) i;
CREATE 10

53
-- this query will be terminated by 'test pg_terminate_backend'
54
1&:EXPLAIN ANALYZE CREATE TEMP TABLE t1 AS SELECT count(*) FROM QUERY_METRICS.foo WHERE pg_sleep(200) IS NULL;  <waiting ...>
55
-- terminate above query
R
Richard Guo 已提交
56
SELECT pg_terminate_backend(pid, 'test pg_terminate_backend') FROM pg_stat_activity WHERE query LIKE 'EXPLAIN ANALYZE CREATE TEMP TABLE t1 AS SELECT%' ORDER BY pid LIMIT 1;
57 58 59
 pg_terminate_backend 
----------------------
 t                    
W
Wang Hao 已提交
60
(1 row)
61
-- start_ignore
W
Wang Hao 已提交
62 63 64 65 66 67
1<:  <... completed>
FATAL:  terminating connection due to administrator command: "test pg_terminate_backend"
server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
1q: ... <quitting>
68
-- end_ignore
W
Wang Hao 已提交
69

70 71
-- query backend to ensure no PANIC on postmaster and wait cleanup done
SELECT count(*) FROM foo, pg_sleep(2);
72 73 74
 count 
-------
 10    
W
Wang Hao 已提交
75 76
(1 row)

77
-- test 2: pg_cancel_backend
W
Wang Hao 已提交
78 79 80
-- Expected result is 1 row, means only current query in instrument slots,
-- If more than one row returned, means previous test has leaked slots.
SELECT count(*) FROM (SELECT 1 FROM gp_instrument_shmem_detail GROUP BY ssid, ccnt) t;
81 82 83
 count 
-------
 1     
W
Wang Hao 已提交
84 85
(1 row)

86
-- this query will be cancelled by 'test pg_cancel_backend'
87
2&:EXPLAIN ANALYZE CREATE TEMP TABLE t2 AS SELECT count(*) FROM QUERY_METRICS.foo WHERE pg_sleep(200) IS NULL;  <waiting ...>
88
-- cancel above query
R
Richard Guo 已提交
89
SELECT pg_cancel_backend(pid, 'test pg_cancel_backend') FROM pg_stat_activity WHERE query LIKE 'EXPLAIN ANALYZE CREATE TEMP TABLE t2 AS SELECT%' ORDER BY pid LIMIT 1;
90 91 92
 pg_cancel_backend 
-------------------
 t                 
W
Wang Hao 已提交
93
(1 row)
94
-- start_ignore
W
Wang Hao 已提交
95 96 97
2<:  <... completed>
ERROR:  canceling statement due to user request: "test pg_cancel_backend"
2q: ... <quitting>
98
-- end_ignore
W
Wang Hao 已提交
99

100 101
-- query backend to ensure no PANIC on postmaster and wait cleanup done
SELECT count(*) FROM foo, pg_sleep(2);
102 103 104
 count 
-------
 10    
W
Wang Hao 已提交
105 106
(1 row)

107 108 109 110 111 112 113 114 115 116
-- test 3: DML should expose plan_node_id for whole plan tree
-- Expected result is 1 row, means only current query in instrument slots,
-- If more than one row returned, means previous test has leaked slots.
SELECT count(*) FROM (SELECT 1 FROM gp_instrument_shmem_detail GROUP BY ssid, ccnt) t;
 count 
-------
 1     
(1 row)

-- this query will be cancelled by 'test pg_cancel_backend'
117
3&:SET OPTIMIZER TO off;EXPLAIN ANALYZE INSERT INTO QUERY_METRICS.a SELECT *, pg_sleep(20) FROM generate_series(1,10);  <waiting ...>
118 119

-- validate plan nodes exist in instrument solts
120 121 122 123 124
SELECT count(*) FROM pg_sleep(1);
 count 
-------
 1     
(1 row)
125 126 127 128 129 130
SELECT ro, CASE WHEN max(nid) > 2 THEN 'ok' ELSE 'wrong' END isok FROM ( SELECT CASE WHEN segid >= 0 THEN 's' ELSE 'm' END ro, nid FROM gp_instrument_shmem_detail WHERE ssid <> (SELECT setting FROM pg_settings WHERE name = 'gp_session_id')::int AND nid > 0 ) dt GROUP BY (ro) ORDER BY ro;
 ro | isok 
----+------
 m  | ok   
 s  | ok   
(2 rows)
131 132 133 134 135 136
-- validate no different tmid across segments
SELECT count(*) FROM (SELECT DISTINCT tmid FROM gp_instrument_shmem_detail) t;
 count 
-------
 1     
(1 row)
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
-- cancel the query
SELECT pg_cancel_backend(pid, 'test DML') FROM pg_stat_activity WHERE query LIKE 'SET OPTIMIZER TO off;EXPLAIN ANALYZE INSERT INTO QUERY_METRICS.a SELECT%' ORDER BY pid LIMIT 1;
 pg_cancel_backend 
-------------------
 t                 
(1 row)

-- start_ignore
3<:  <... completed>
ERROR:  canceling statement due to user request: "test DML"
3q: ... <quitting>
-- end_ignore

-- query backend to ensure no PANIC on postmaster and wait cleanup done
SELECT count(*) FROM foo, pg_sleep(2);
 count 
-------
 10    
(1 row)

-- test 4: Merge Append should expose plan_node_id for whole plan tree
CREATE TABLE QUERY_METRICS.mergeappend_test (a int, b int, x int) DISTRIBUTED BY (a,b);
CREATE
INSERT INTO QUERY_METRICS.mergeappend_test SELECT g/100, g/100, g FROM generate_series(1, 500) g;
INSERT 500
ANALYZE QUERY_METRICS.mergeappend_test;
ANALYZE

-- Expected result is 1 row, means only current query in instrument slots,
-- If more than one row returned, means previous test has leaked slots.
SELECT count(*) FROM (SELECT 1 FROM gp_instrument_shmem_detail GROUP BY ssid, ccnt) t;
 count 
-------
 1     
(1 row)

-- this query will be cancelled by 'test pg_cancel_backend'
174
4&:SET OPTIMIZER TO off;SELECT a, b, array_dims(array_agg(x)) FROM QUERY_METRICS.mergeappend_test r GROUP BY a, b UNION ALL SELECT NULL, NULL, array_dims(array_agg(x)) FROM QUERY_METRICS.mergeappend_test r, pg_sleep(200) ORDER BY 1,2;  <waiting ...>
175 176

-- validate plan nodes exist in instrument solts
177 178 179 180 181
SELECT count(*) FROM pg_sleep(1);
 count 
-------
 1     
(1 row)
182 183 184 185 186 187
SELECT ro, CASE WHEN max(nid) > 5 THEN 'ok' ELSE 'wrong' END isok FROM ( SELECT CASE WHEN segid >= 0 THEN 's' ELSE 'm' END ro, nid FROM gp_instrument_shmem_detail WHERE ssid <> (SELECT setting FROM pg_settings WHERE name = 'gp_session_id')::int AND nid > 0 ) dt GROUP BY (ro) ORDER BY ro;
 ro | isok 
----+------
 m  | ok   
 s  | ok   
(2 rows)
188 189 190 191 192 193
-- validate no different tmid across segments
SELECT count(*) FROM (SELECT DISTINCT tmid FROM gp_instrument_shmem_detail) t;
 count 
-------
 1     
(1 row)
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
-- cancel the query
SELECT pg_cancel_backend(pid, 'test MergeAppend') FROM pg_stat_activity WHERE query LIKE 'SET OPTIMIZER TO off;SELECT a, b, array_dims(array_agg(x)) FROM QUERY_METRICS.mergeappend_test%' ORDER BY pid LIMIT 1;
 pg_cancel_backend 
-------------------
 t                 
(1 row)

-- start_ignore
4<:  <... completed>
ERROR:  canceling statement due to user request: "test MergeAppend"
4q: ... <quitting>
-- end_ignore

-- query backend to ensure no PANIC on postmaster and wait cleanup done
SELECT count(*) FROM foo, pg_sleep(2);
 count 
-------
 10    
(1 row)

214 215 216 217 218 219 220 221 222 223
-- test 5: entrydb
-- Expected result is 1 row, means only current query in instrument slots,
-- If more than one row returned, means previous test has leaked slots.
SELECT count(*) FROM (SELECT 1 FROM gp_instrument_shmem_detail GROUP BY ssid, ccnt) t;
 count 
-------
 1     
(1 row)

-- this query will be cancelled by 'test pg_cancel_backend'
224
5&:SET OPTIMIZER TO off;EXPLAIN ANALYZE INSERT INTO QUERY_METRICS.a(id) SELECT oid FROM pg_class, pg_sleep(200);  <waiting ...>
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262

-- validate QD and entrydb have instrumentations on each backend process
SELECT count(*) FROM pg_sleep(1);
 count 
-------
 1     
(1 row)
SELECT count(DISTINCT pid) FROM gp_instrument_shmem_detail WHERE ssid <> (SELECT setting FROM pg_settings WHERE name = 'gp_session_id')::int AND segid < 0 AND nid >= 5;
 count 
-------
 2     
(1 row)
-- validate no different tmid across segments
SELECT count(*) FROM (SELECT DISTINCT tmid FROM gp_instrument_shmem_detail) t;
 count 
-------
 1     
(1 row)
-- cancel the query
SELECT pg_cancel_backend(pid, 'test entrydb') FROM pg_stat_activity WHERE query LIKE 'SET OPTIMIZER TO off;EXPLAIN ANALYZE INSERT INTO QUERY_METRICS.a(id) SELECT%' ORDER BY pid LIMIT 1;
 pg_cancel_backend 
-------------------
 t                 
(1 row)

-- start_ignore
5<:  <... completed>
ERROR:  canceling statement due to user request: "test entrydb"
5q: ... <quitting>
-- end_ignore

-- query backend to ensure no PANIC on postmaster and wait cleanup done
SELECT count(*) FROM foo, pg_sleep(2);
 count 
-------
 10    
(1 row)

W
Wang Hao 已提交
263 264 265
-- Expected result is 1 row, means only current query in instrument slots,
-- If more than one row returned, means previous test has leaked slots.
SELECT count(*) FROM (SELECT 1 FROM gp_instrument_shmem_detail GROUP BY ssid, ccnt) t;
266 267 268
 count 
-------
 1     
W
Wang Hao 已提交
269 270 271 272 273 274
(1 row)

-- start_ignore
DROP SCHEMA IF EXISTS QUERY_METRICS CASCADE;
DROP
-- end_ignore