blob: f05bed21e10c8456dddbd62b280aef268f79eefc [file] [log] [blame]
-- @Description Tests the state for pg_endpoints AND gp_get_segment_endpoints(), focus in nowait mode
-- need to fault injection to gp_wait_parallel_retrieve_cursor()
--
DROP TABLE IF EXISTS t1;
DROP
CREATE TABLE t1 (a INT) DISTRIBUTED by (a);
CREATE
insert into t1 select generate_series(1,100);
INSERT 100
--------- Test1: Basic test for parallel retrieve interface & close cursor
1: BEGIN;
BEGIN
1: DECLARE c1 PARALLEL RETRIEVE CURSOR FOR SELECT * FROM t1;
DECLARE
1: @post_run 'parse_endpoint_info 1 1 2 3 4' : SELECT endpointname,auth_token,hostname,port,state FROM gp_get_endpoints() WHERE cursorname='c1';
endpoint_id1 | token_id | host_id | port_id | READY
endpoint_id1 | token_id | host_id | port_id | READY
endpoint_id1 | token_id | host_id | port_id | READY
(3 rows)
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c1', 0);
finished
----------
f
(1 row)
*U: @pre_run 'set_endpoint_variable @ENDPOINT1': SELECT state FROM gp_get_segment_endpoints() WHERE endpointname='@ENDPOINT1';
state
-------
(0 rows)
state
-------
READY
(1 row)
state
-------
READY
(1 row)
state
-------
READY
(1 row)
*R: @pre_run 'set_endpoint_variable @ENDPOINT1': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT1";
#-1retrieve> connection to server at "host_id", port port_id failed: FATAL: retrieve auth token is invalid
a
----
2
3
4
7
8
16
18
19
22
24
27
29
34
37
39
41
42
45
51
53
54
55
59
60
65
66
70
75
77
80
81
84
90
92
93
94
97
99
(38 rows)
a
----
1
12
15
20
23
26
30
31
35
36
38
40
44
46
47
48
49
50
57
61
64
68
69
71
72
74
76
78
79
83
86
87
88
89
91
95
98
(37 rows)
a
-----
5
6
9
10
11
13
14
17
21
25
28
32
33
43
52
56
58
62
63
67
73
82
85
96
100
(25 rows)
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c1', 0);
finished
----------
t
(1 row)
1: CLOSE c1;
CLOSE
-- check no endpoint info
1: SELECT auth_token,state FROM gp_get_endpoints() WHERE cursorname='c1';
auth_token | state
------------+-------
(0 rows)
-- check no token info on QE after close PARALLEL RETRIEVE CURSOR
*U: SELECT * FROM gp_get_segment_endpoints() WHERE cursorname='c1';
auth_token | databaseid | senderpid | receiverpid | state | gp_segment_id | sessionid | username | endpointname | cursorname
------------+------------+-----------+-------------+-------+---------------+-----------+----------+--------------+------------
(0 rows)
auth_token | databaseid | senderpid | receiverpid | state | gp_segment_id | sessionid | username | endpointname | cursorname
------------+------------+-----------+-------------+-------+---------------+-----------+----------+--------------+------------
(0 rows)
auth_token | databaseid | senderpid | receiverpid | state | gp_segment_id | sessionid | username | endpointname | cursorname
------------+------------+-----------+-------------+-------+---------------+-----------+----------+--------------+------------
(0 rows)
auth_token | databaseid | senderpid | receiverpid | state | gp_segment_id | sessionid | username | endpointname | cursorname
------------+------------+-----------+-------------+-------+---------------+-----------+----------+--------------+------------
(0 rows)
-- error out for closed cursor
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c1', 0);
ERROR: cursor "c1" does not exist
1: ROLLBACK;
ROLLBACK
---------- Test2: enhanced test for parallel retrieve interface state & cursor auto closed when transaction closed
1: BEGIN;
BEGIN
1: DECLARE c2 PARALLEL RETRIEVE CURSOR FOR SELECT * FROM t1;
DECLARE
1: @post_run 'parse_endpoint_info 2 1 2 3 4' : SELECT endpointname,auth_token,hostname,port,state FROM gp_get_endpoints() WHERE cursorname='c2';
endpoint_id2 | token_id | host_id | port_id | READY
endpoint_id2 | token_id | host_id | port_id | READY
endpoint_id2 | token_id | host_id | port_id | READY
(3 rows)
-- test RETRIEVE success on seg1
0R: @pre_run 'set_endpoint_variable @ENDPOINT2': RETRIEVE 10 FROM ENDPOINT "@ENDPOINT2";
a
----
2
3
4
7
8
16
18
19
22
24
(10 rows)
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c2', 0);
finished
----------
f
(1 row)
-- check initial state after "CHECK PARALLEL RETRIEVE CURSOR"
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c2';
state
----------
ATTACHED
READY
READY
(3 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c2';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+----------
t | t | ATTACHED
(1 row)
?column? | ?column? | state
----------+----------+-------
t | f | READY
(1 row)
?column? | ?column? | state
----------+----------+-------
t | f | READY
(1 row)
-- check state if some endpoint retrieve partial results, some endpoint finished retrieving, some endpoint not start retrieving
0R: @pre_run 'set_endpoint_variable @ENDPOINT2': RETRIEVE 10 FROM ENDPOINT "@ENDPOINT2";
a
----
27
29
34
37
39
41
42
45
51
53
(10 rows)
1R: @pre_run 'set_endpoint_variable @ENDPOINT2': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT2";
a
----
1
12
15
20
23
26
30
31
35
36
38
40
44
46
47
48
49
50
57
61
64
68
69
71
72
74
76
78
79
83
86
87
88
89
91
95
98
(37 rows)
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c2';
state
----------
ATTACHED
FINISHED
READY
(3 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c2';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+----------
t | t | ATTACHED
(1 row)
?column? | ?column? | state
----------+----------+----------
f | t | FINISHED
(1 row)
?column? | ?column? | state
----------+----------+-------
t | f | READY
(1 row)
-- return 0 row instead of reporting error if finished retrieving data from this endpoint, while other endpoint have not finished retrieving.
1R: @pre_run 'set_endpoint_variable @ENDPOINT2': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT2";
a
---
(0 rows)
-- finished retrieving all endpoints and check state
*R: @pre_run 'set_endpoint_variable @ENDPOINT2': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT2";
#-1retrieve> connection to server at "host_id", port port_id failed: FATAL: retrieve auth token is invalid
a
----
54
55
59
60
65
66
70
75
77
80
81
84
90
92
93
94
97
99
(18 rows)
a
---
(0 rows)
a
-----
5
6
9
10
11
13
14
17
21
25
28
32
33
43
52
56
58
62
63
67
73
82
85
96
100
(25 rows)
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c2';
state
----------
FINISHED
FINISHED
FINISHED
(3 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c2';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+----------
f | t | FINISHED
(1 row)
?column? | ?column? | state
----------+----------+----------
f | t | FINISHED
(1 row)
?column? | ?column? | state
----------+----------+----------
f | t | FINISHED
(1 row)
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c2', 0);
finished
----------
t
(1 row)
1: COMMIT;
COMMIT
-- check the cursor auto closed when transaction closed
-- check no endpoint info
1: SELECT state FROM gp_get_endpoints() WHERE cursorname='c2';
state
-------
(0 rows)
-- check no token info on QE after close PARALLEL RETRIEVE CURSOR
*U: SELECT * FROM gp_get_segment_endpoints() WHERE cursorname='c2';
auth_token | databaseid | senderpid | receiverpid | state | gp_segment_id | sessionid | username | endpointname | cursorname
------------+------------+-----------+-------------+-------+---------------+-----------+----------+--------------+------------
(0 rows)
auth_token | databaseid | senderpid | receiverpid | state | gp_segment_id | sessionid | username | endpointname | cursorname
------------+------------+-----------+-------------+-------+---------------+-----------+----------+--------------+------------
(0 rows)
auth_token | databaseid | senderpid | receiverpid | state | gp_segment_id | sessionid | username | endpointname | cursorname
------------+------------+-----------+-------------+-------+---------------+-----------+----------+--------------+------------
(0 rows)
auth_token | databaseid | senderpid | receiverpid | state | gp_segment_id | sessionid | username | endpointname | cursorname
------------+------------+-----------+-------------+-------+---------------+-----------+----------+--------------+------------
(0 rows)
-- error out for closed cursor
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c2', 0);
ERROR: cursor "c2" does not exist
1: ROLLBACK;
ROLLBACK
---------- Test3: 2 retrieving sessions connect to the same endpoint report error & cancel QE exec backend
1: BEGIN;
BEGIN
1: DECLARE c3 PARALLEL RETRIEVE CURSOR FOR SELECT * FROM t1;
DECLARE
1: @post_run 'parse_endpoint_info 3 1 2 3 4' : SELECT endpointname,auth_token,hostname,port,state FROM gp_get_endpoints() WHERE cursorname='c3';
endpoint_id3 | token_id | host_id | port_id | READY
endpoint_id3 | token_id | host_id | port_id | READY
endpoint_id3 | token_id | host_id | port_id | READY
(3 rows)
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c3', 0);
finished
----------
f
(1 row)
0R: @pre_run 'set_endpoint_variable @ENDPOINT3': RETRIEVE 10 FROM ENDPOINT "@ENDPOINT3";
a
----
2
3
4
7
8
16
18
19
22
24
(10 rows)
-- a new retrieve session should report error
3R: @pre_run 'set_endpoint_variable @ENDPOINT3': RETRIEVE 10 FROM ENDPOINT "@ENDPOINT3";
ERROR: endpoint endpoint_id3 was already attached by receiver(pid: PID)
DETAIL: An endpoint can only be attached by one retrieving session.
-- quit this new retrieve session
3Rq: ... <quitting>
-- some endpoint retrieve partial results, some endpoint finished retrieving, some endpoint not start retrieving
1R: @pre_run 'set_endpoint_variable @ENDPOINT3': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT3";
a
----
1
12
15
20
23
26
30
31
35
36
38
40
44
46
47
48
49
50
57
61
64
68
69
71
72
74
76
78
79
83
86
87
88
89
91
95
98
(37 rows)
-- get senderpid which is endpoint execution backend
0U: @post_run 'get_tuple_cell PID31 1 1 ; create_sub "$PID31[ \t]*" senderpid31': SELECT senderpid, receiverpid<>-1, state FROM gp_get_segment_endpoints();
senderpid | ?column? | state
-----------+----------+----------
senderpid31| t | ATTACHED
(1 row)
-- run 'kill -s INT senderpid' to cancel the endpoint execution backend, retrieve session still can work
42: @pre_run 'kill -s INT ${PID31} && echo "${RAW_STR}" ': SELECT 1;
?column?
----------
1
(1 row)
-- check it can cancel the "gp_wait_parallel_retrieve_cursor"
1: SELECT pg_sleep(0.4);
pg_sleep
----------
(1 row)
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c3';
state
----------
FINISHED
READY
(2 rows)
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c3', 0);
ERROR: canceling MPP operation (seg0 192.168.235.128:7002 pid=67934)
-- check no endpoint info left
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c3';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c3';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
-- report error for EXECUTE canceled PARALLEL RETRIEVE CURSOR
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c3', 0);
ERROR: current transaction is aborted, commands ignored until end of transaction block
1: ROLLBACK;
ROLLBACK
-- check no endpoint info
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c3';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c3';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
---------- Test4: terminate (using signal QUIT) QE exec backend
1: BEGIN;
BEGIN
1: DECLARE c4 PARALLEL RETRIEVE CURSOR FOR SELECT * FROM t1;
DECLARE
1: @post_run 'parse_endpoint_info 4 1 2 3 4' : SELECT endpointname,auth_token,hostname,port,state FROM gp_get_endpoints() WHERE cursorname='c4';
endpoint_id4 | token_id | host_id | port_id | READY
endpoint_id4 | token_id | host_id | port_id | READY
endpoint_id4 | token_id | host_id | port_id | READY
(3 rows)
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c4', 0);
finished
----------
f
(1 row)
-- some endpoint retrieve partial results, some endpoint finished retrieving, some endpoint not start retrieving
0R: @pre_run 'set_endpoint_variable @ENDPOINT4': RETRIEVE 10 FROM ENDPOINT "@ENDPOINT4";
a
----
2
3
4
7
8
16
18
19
22
24
(10 rows)
1R: @pre_run 'set_endpoint_variable @ENDPOINT4': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT4";
a
----
1
12
15
20
23
26
30
31
35
36
38
40
44
46
47
48
49
50
57
61
64
68
69
71
72
74
76
78
79
83
86
87
88
89
91
95
98
(37 rows)
-- get senderpid which is endpoint execution backend
0U: @post_run 'get_tuple_cell PID41 1 1 ; create_sub "${PID41}[ \t]*" senderpid41': SELECT senderpid, receiverpid<>-1, state FROM gp_get_segment_endpoints();
senderpid | ?column? | state
-----------+----------+----------
senderpid41| t | ATTACHED
(1 row)
-- run 'kill -s QUIT senderpid' to cancel the endpoint execution backend, retrieve session still can work
42: @pre_run 'kill -s QUIT ${PID41} && echo "${RAW_STR}" ': SELECT 1;
?column?
----------
1
(1 row)
-- exit this session because the connection closed, so that it will re-connect next time use this session.
0Rq: ... <quitting>
0Uq: ... <quitting>
-- check it can cancel the "gp_wait_parallel_retrieve_cursor"
1: SELECT pg_sleep(0.4);
pg_sleep
----------
(1 row)
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c4';
ERROR: Error on receive from seg0 10.34.58.56:25432 pid=41925: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c4', 0);
ERROR: Error on receive from seg0 192.168.235.128:7002 pid=68097: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
-- check no endpoint info left
2q: ... <quitting>
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c4';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c4';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
-- report error for EXECUTE canceled PARALLEL RETRIEVE CURSOR
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c4', 0);
ERROR: current transaction is aborted, commands ignored until end of transaction block
1: ROLLBACK;
ROLLBACK
-- check no endpoint info
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c4';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c4';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
2Rq: ... <quitting>
---------- Test5: terminate (using signal TERM) QE exec backend
1: BEGIN;
BEGIN
1: DECLARE c5 PARALLEL RETRIEVE CURSOR FOR SELECT * FROM t1;
DECLARE
1: @post_run 'parse_endpoint_info 5 1 2 3 4' : SELECT endpointname,auth_token,hostname,port,state FROM gp_get_endpoints() WHERE cursorname='c5';
endpoint_id5 | token_id | host_id | port_id | READY
endpoint_id5 | token_id | host_id | port_id | READY
endpoint_id5 | token_id | host_id | port_id | READY
(3 rows)
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c5', 0);
finished
----------
f
(1 row)
-- some endpoint retrieve partial results, some endpoint finished retrieving, some endpoint not start retrieving
0R: @pre_run 'set_endpoint_variable @ENDPOINT5': RETRIEVE 10 FROM ENDPOINT "@ENDPOINT5";
a
----
2
3
4
7
8
16
18
19
22
24
(10 rows)
-- 1R still bind to Test4 session, so can not retrieve from current endpoint.
1R: @pre_run 'set_endpoint_variable @ENDPOINT5': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT5";
ERROR: the endpoint endpoint_id5 does not exist for session id xxx
-- Since seg1 retrieve session is bind to Test4 session. And Test4 session get killed. We need to restart it.
1Rq: ... <quitting>
1R: @pre_run 'set_endpoint_variable @ENDPOINT5': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT5";
a
----
1
12
15
20
23
26
30
31
35
36
38
40
44
46
47
48
49
50
57
61
64
68
69
71
72
74
76
78
79
83
86
87
88
89
91
95
98
(37 rows)
-- get senderpid which is endpoint execution backend
0U: @post_run 'get_tuple_cell PID51 1 1 ; create_sub "${PID51}[ \t]*" senderpid51': SELECT senderpid, receiverpid<>-1, state FROM gp_get_segment_endpoints();
senderpid | ?column? | state
-----------+----------+----------
senderpid51| t | ATTACHED
(1 row)
-- run 'kill -s TERM senderpid' to cancel the endpoint execution backend, retrieve session still can work
42: @pre_run 'kill -s TERM ${PID51} && echo "${RAW_STR}" ': SELECT 1;
?column?
----------
1
(1 row)
-- check it can cancel the "gp_wait_parallel_retrieve_cursor"
1: SELECT pg_sleep(0.4);
pg_sleep
----------
(1 row)
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c5';
state
----------
FINISHED
READY
(2 rows)
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c5', 0);
ERROR: terminating connection due to administrator command (seg0 192.168.235.128:7002 pid=68210)
-- check no endpoint info left
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c5';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c5';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
-- report error for EXECUTE canceled PARALLEL RETRIEVE CURSOR
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c5', 0);
ERROR: current transaction is aborted, commands ignored until end of transaction block
1: ROLLBACK;
ROLLBACK
-- check no endpoint info
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c5';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c5';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
---------- Test6: Cancel (using signal INT) the process of 'CHECK PARALLEL RETRIEVE CURSOR'
-- faul injection on QD
1: SELECT gp_inject_fault('gp_wait_parallel_retrieve_cursor_after_udf', 'reset', 1);
gp_inject_fault
-----------------
Success:
(1 row)
1: SELECT gp_inject_fault('gp_wait_parallel_retrieve_cursor_after_udf', 'sleep', '', '', '', 1, 1, 1, 1::smallint);
gp_inject_fault
-----------------
Success:
(1 row)
1: BEGIN;
BEGIN
1: DECLARE c6 PARALLEL RETRIEVE CURSOR FOR SELECT * FROM t1;
DECLARE
1: @post_run 'parse_endpoint_info 6 1 2 3 4' : SELECT endpointname,auth_token,hostname,port,state FROM gp_get_endpoints() WHERE cursorname='c6';
endpoint_id6 | token_id | host_id | port_id | READY
endpoint_id6 | token_id | host_id | port_id | READY
endpoint_id6 | token_id | host_id | port_id | READY
(3 rows)
-- get backend pid of this session which run 'gp_wait_parallel_retrieve_cursor'
1: @post_run 'get_tuple_cell PID61 1 1 ; create_sub "${PID61}[ \t]*" QDPid61': select pg_backend_pid();
pg_backend_pid
----------------
QDPid61
(1 row)
-- some endpoint retrieve partial results, some endpoint finished retrieving, some endpoint not start retrieving
0R: @pre_run 'set_endpoint_variable @ENDPOINT6': RETRIEVE 10 FROM ENDPOINT "@ENDPOINT6";
a
----
2
3
4
7
8
16
18
19
22
24
(10 rows)
1R: @pre_run 'set_endpoint_variable @ENDPOINT6': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT6";
a
----
1
12
15
20
23
26
30
31
35
36
38
40
44
46
47
48
49
50
57
61
64
68
69
71
72
74
76
78
79
83
86
87
88
89
91
95
98
(37 rows)
-- run 'kill -s INT QDPid' to cancel the endpoint execution backend, retrieve session still can work
-- fault injection sleep to wait for canceling the endpoint execution backend, retrieve session still can work
1&: SELECT * FROM gp_wait_parallel_retrieve_cursor('c6', 0); <waiting ...>
0U: @pre_run 'kill -s INT ${PID61} && echo "${RAW_STR}" ': SELECT 1;
?column?
----------
1
(1 row)
-- check it can cancel the "gp_wait_parallel_retrieve_cursor"
1<: <... completed>
ERROR: canceling statement due to user request
-- check no endpoint info left
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c6';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c6';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
-- report error for EXECUTE canceled PARALLEL RETRIEVE CURSOR
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c6', 0);
ERROR: current transaction is aborted, commands ignored until end of transaction block
1: ROLLBACK;
ROLLBACK
-- check no endpoint info
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c6';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c6';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
---------- Test6.1: Cancel (using signal INT) the process of 'CHECK PARALLEL RETRIEVE CURSOR' without rollback
-- faul injection on QD
1: SELECT gp_inject_fault('gp_wait_parallel_retrieve_cursor_after_udf', 'reset', 1);
gp_inject_fault
-----------------
Success:
(1 row)
1: SELECT gp_inject_fault('gp_wait_parallel_retrieve_cursor_after_udf', 'sleep', '', '', '', 1, 1, 1, 1::smallint);
gp_inject_fault
-----------------
Success:
(1 row)
1: BEGIN;
BEGIN
1: DECLARE c61 PARALLEL RETRIEVE CURSOR FOR SELECT * FROM t1;
DECLARE
1: @post_run 'parse_endpoint_info 61 1 2 3 4' : SELECT endpointname,auth_token,hostname,port,state FROM gp_get_endpoints() WHERE cursorname='c61';
endpoint_id61 | token_id | host_id | port_id | READY
endpoint_id61 | token_id | host_id | port_id | READY
endpoint_id61 | token_id | host_id | port_id | READY
(3 rows)
-- get backend pid of this session which run 'gp_wait_parallel_retrieve_cursor'
1: @post_run 'get_tuple_cell PID611 1 1 ; create_sub "${PID611}[ \t]*" QDPid611': select pg_backend_pid();
pg_backend_pid
----------------
QDPid611
(1 row)
-- some endpoint retrieve partial results, some endpoint finished retrieving, some endpoint not start retrieving
0R: @pre_run 'set_endpoint_variable @ENDPOINT61': RETRIEVE 10 FROM ENDPOINT "@ENDPOINT61";
a
----
2
3
4
7
8
16
18
19
22
24
(10 rows)
1R: @pre_run 'set_endpoint_variable @ENDPOINT61': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT61";
a
----
1
12
15
20
23
26
30
31
35
36
38
40
44
46
47
48
49
50
57
61
64
68
69
71
72
74
76
78
79
83
86
87
88
89
91
95
98
(37 rows)
-- run 'kill -s INT QDPid' to cancel the endpoint execution backend, retrieve session still can work
-- fault injection sleep to wait for canceling the endpoint execution backend, retrieve session still can work
1&: SELECT * FROM gp_wait_parallel_retrieve_cursor('c61', 0); <waiting ...>
0U: @pre_run 'kill -s INT ${PID611} && echo "${RAW_STR}" ': SELECT 1;
?column?
----------
1
(1 row)
-- check it can cancel the "gp_wait_parallel_retrieve_cursor"
1<: <... completed>
ERROR: canceling statement due to user request
-- check no endpoint info left
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c61';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c61';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
-- quit the session of 'CHECK PARALLEL RETRIEVE CURSOR' and keep other session connected
1q: ... <quitting>
-- check no endpoint info
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c61';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c61';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
0Rq: ... <quitting>
1Rq: ... <quitting>
---------- Test7: terminate (using signal QUIT) the process of 'CHECK PARALLEL RETRIEVE CURSOR'
1: SELECT gp_inject_fault('gp_wait_parallel_retrieve_cursor_after_udf', 'reset', 1);
gp_inject_fault
-----------------
Success:
(1 row)
1: SELECT gp_inject_fault('gp_wait_parallel_retrieve_cursor_after_udf', 'sleep', '', '', '', 1, 1, 1, 1::smallint);
gp_inject_fault
-----------------
Success:
(1 row)
1: BEGIN;
BEGIN
1: DECLARE c7 PARALLEL RETRIEVE CURSOR FOR SELECT * FROM t1;
DECLARE
1: @post_run 'parse_endpoint_info 7 1 2 3 4' : SELECT endpointname,auth_token,hostname,port,state FROM gp_get_endpoints() WHERE cursorname='c7';
endpoint_id7 | token_id | host_id | port_id | READY
endpoint_id7 | token_id | host_id | port_id | READY
endpoint_id7 | token_id | host_id | port_id | READY
(3 rows)
-- get backend pid of this session which run 'gp_wait_parallel_retrieve_cursor'
1: @post_run 'get_tuple_cell PID71 1 1 ; create_sub "${PID71}[ \t]*" QDPid71': select pg_backend_pid();
pg_backend_pid
----------------
QDPid71
(1 row)
-- some endpoint retrieve partial results, some endpoint finished retrieving, some endpoint not start retrieving
0R: @pre_run 'set_endpoint_variable @ENDPOINT7': RETRIEVE 10 FROM ENDPOINT "@ENDPOINT7";
a
----
2
3
4
7
8
16
18
19
22
24
(10 rows)
1R: @pre_run 'set_endpoint_variable @ENDPOINT7': RETRIEVE ALL FROM ENDPOINT "@ENDPOINT7";
a
----
1
12
15
20
23
26
30
31
35
36
38
40
44
46
47
48
49
50
57
61
64
68
69
71
72
74
76
78
79
83
86
87
88
89
91
95
98
(37 rows)
2U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c7';
?column? | ?column? | state
----------+----------+-------
t | f | READY
(1 row)
-- run 'kill -s QUIT QDPid' to cancel the endpoint execution backend, retrieve session still can work
-- here need to sleep sometime to wait for endpoint QE backend to detect QD connection lost.
1&: SELECT * FROM gp_wait_parallel_retrieve_cursor('c7', 0); <waiting ...>
0U: @pre_run 'kill -s QUIT ${PID71}&& sleep 5 && echo "${RAW_STR}" ': SELECT 1;
?column?
----------
1
(1 row)
-- check it can cancel the "gp_wait_parallel_retrieve_cursor"
1<: <... completed>
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
-- quit all sessions on the master, because connect lost
1q: ... <quitting>
2q: ... <quitting>
-1Uq: ... <quitting>
-- check no endpoint info left
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c7';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c7';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
-- report error for EXECUTE canceled PARALLEL RETRIEVE CURSOR
1: SELECT * FROM gp_wait_parallel_retrieve_cursor('c7', -1);
ERROR: cursor "c7" does not exist
1: ROLLBACK;
ROLLBACK
-- check no endpoint info
2: SELECT state FROM gp_get_endpoints() WHERE cursorname='c7';
state
-------
(0 rows)
*U: SELECT senderpid<>-1, receiverpid<>-1, state FROM gp_get_segment_endpoints() WHERE cursorname='c7';
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
?column? | ?column? | state
----------+----------+-------
(0 rows)
---------- Test8: Status visibilities for different sessions
1: BEGIN;
BEGIN
1: DECLARE c8 PARALLEL RETRIEVE CURSOR FOR SELECT * FROM t1;
DECLARE
1: @post_run 'get_tuple_cell SESSION81 1 1 ; create_match_sub_with_spaces $SESSION81 session81' : SELECT sessionid,state FROM gp_get_session_endpoints() WHERE cursorname='c8';
sessionid | state
-----------+-------
session81 | READY
session81 | READY
session81 | READY
(3 rows)
-- Session 2 can only see its own cursors by default.
2: BEGIN;
BEGIN
2: DECLARE c8 PARALLEL RETRIEVE CURSOR FOR SELECT * FROM t1;
DECLARE
2: @post_run 'get_tuple_cell SESSION82 1 1 ; create_match_sub_with_spaces $SESSION82 session82' : SELECT sessionid,state FROM gp_get_session_endpoints() WHERE cursorname='c8';
sessionid | state
-----------+-------
session82 | READY
session82 | READY
session82 | READY
(3 rows)
-- Session 2 can see all cursors with gp_get_endpoints().
2: SELECT sessionid,state FROM gp_get_endpoints() WHERE cursorname='c8' order by sessionid;
sessionid | state
-----------+-------
session82 | READY
session82 | READY
session82 | READY
session81 | READY
session81 | READY
session81 | READY
(6 rows)
1: CLOSE c8;
CLOSE
1: END;
END
2: CLOSE c8;
CLOSE
2: END;
END
---------- Test9: Test parallel retrieve cursor auto-check
1: drop table if exists t1;
DROP
1: create table t1(a int, b int);
CREATE
1: insert into t1 values (generate_series(1,100000), 1);
INSERT 100000
1: insert into t1 values (-1, 1);
INSERT 1
1: BEGIN;
BEGIN
1: DECLARE c9 PARALLEL RETRIEVE CURSOR FOR select count(*) from t1 group by sqrt(a); select count() from gp_get_endpoints();
count
-------
3
(1 row)
-- GP_PARALLEL_RETRIEVE_CURSOR_CHECK_TIMEOUT is 10s, we sleep 12 to check all QEs are already finished.
1: ! sleep 12;
1: SELECT endpointname,auth_token,hostname,port,state FROM gp_get_endpoints() WHERE cursorname='c9';
endpointname | auth_token | hostname | port | state
--------------+------------+----------+------+-------
(0 rows)
1: rollback;
ERROR: cannot take square root of a negative number (seg2 slice1 127.0.1.1:7004 pid=35247)
1q: ... <quitting>