提交 02814cc8 编写于 作者: A Ashwin Agrawal

Move udf exception handling tests from tinc to ICW.

Simplified the tests by setting the GUCs at session level instead of
reloads. Also removed creating tables with index, sequence etc as not
needed for these tests.

So, same coverage is achieved with ICW in 15 secs vs older version
taking 15 mins in TINC.
上级 9108acbb
...@@ -644,3 +644,321 @@ SELECT count(*) FROM test_truncate_tab; ...@@ -644,3 +644,321 @@ SELECT count(*) FROM test_truncate_tab;
51 51
(1 row) (1 row)
-- Tests exception handling of GPDB PL/PgSQL UDF
-- It exercises:
-- 1. PROTOCOL or SQL type of dtm_action_target
-- 2. Various levels of sub-transactions
-- 3. dtm_action_protocol(PROTOCOL): subtransaction_begin, subtransaction_rollback or subtransaction_release
-- 4. dtm_action: fail_begin_command, fail_end_command or panic_begin_comand
--
-- debug_dtm_action: Using this can specify what action to be
-- triggered/simulated and at what point like error / panic / delay
-- and at start or end command after receiving by the segment.
-- debug_dtm_action_segment: Using this can specify segment number to
-- trigger the specified dtm_action.
-- debug_dtm_action_target: Allows to set target for specified
-- dtm_action should it be DTM protocol command or SQL command from
-- master to segment.
-- debug_dtm_action_protocol: Allows to specify sub-type of DTM
-- protocol for which to perform specified dtm_action (like prepare,
-- abort_no_prepared, commit_prepared, abort_prepared,
-- subtransaction_begin, subtransaction_release,
-- subtransaction_rollback, etc...
--
-- debug_dtm_action_sql_command_tag: If debug_dtm_action_target is sql
-- then this parameter can be used to set the type of sql that should
-- trigger the exeception. Ex: 'MPPEXEC UPDATE'
-- debug_dtm_action_nestinglevel: This allows to optional specify at
-- which specific depth level in transaction to take the specified
-- dtm_action. This apples only to target with protocol and not SQL.
--
--
-- start_matchsubs
-- s/\s+\(.*\.[ch]:\d+\)/ (SOMEFILE:SOMEFUNC)/
-- m/ /
-- m/transaction \d+/
-- s/transaction \d+/transaction /
-- m/transaction -\d+/
-- s/transaction -\d+/transaction/
-- end_matchsubs
CREATE OR REPLACE FUNCTION test_excep (arg INTEGER) RETURNS INTEGER
AS $$
DECLARE res INTEGER;
BEGIN
res := 100 / arg;
RETURN res;
EXCEPTION
WHEN division_by_zero
THEN RETURN 999;
END;
$$
LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION test_protocol_allseg(mid int, mshop int, mgender character) RETURNS VOID AS
$$
DECLARE tfactor int default 0;
BEGIN
BEGIN
CREATE TABLE employees(id int, shop_id int, gender character) DISTRIBUTED BY (id);
INSERT INTO employees VALUES (0, 1, 'm');
END;
BEGIN
BEGIN
IF EXISTS (select 1 from employees where id = mid) THEN
RAISE EXCEPTION 'Duplicate employee id';
ELSE
IF NOT (mshop between 1 AND 2) THEN
RAISE EXCEPTION 'Invalid shop id' ;
END IF;
END IF;
SELECT * INTO tfactor FROM test_excep(0);
BEGIN
INSERT INTO employees VALUES (mid, mshop, mgender);
EXCEPTION
WHEN OTHERS THEN
BEGIN
RAISE NOTICE 'catching the exception ...3';
END;
END;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'catching the exception ...2';
END;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'catching the exception ...1';
END;
END;
$$
LANGUAGE plpgsql;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
ERROR: DTM error (gathered results from cmd 'Rollback Current Subtransaction') (cdbtm.c:2040)
DETAIL: Raise error for debug_dtm_action = 3, debug_dtm_action_protocol = Rollback Current Subtransaction (seg0 127.0.1.1:25432 pid=24104)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 17 during exception cleanup
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: catching the exception ...2
ERROR: DTM error (gathered results from cmd 'Rollback Current Subtransaction') (cdbtm.c:2040)
DETAIL: transaction 1518031192-0000000602 at level 1 already processed (current level 1) (cdbtm.c:3456) (seg1 127.0.1.1:25433 pid=24105)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 8 during exception cleanup
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=4;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: catching the exception ...2
test_protocol_allseg
----------------------
(1 row)
select * from employees;
id | shop_id | gender
----+---------+--------
0 | 1 | m
(1 row)
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
ERROR: DTM error (gathered results from cmd ' Begin Internal Subtransaction') (cdbtm.c:2040)
DETAIL: Raise ERROR for debug_dtm_action = 2, debug_dtm_action_protocol = Begin Internal Subtransaction (seg0 127.0.1.1:25432 pid=24104)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 8 during statement block entry
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=4;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: catching the exception ...2
test_protocol_allseg
----------------------
(1 row)
select * from employees;
id | shop_id | gender
----+---------+--------
0 | 1 | m
(1 row)
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
ERROR: DTM error (gathered results from cmd ' Begin Internal Subtransaction') (cdbtm.c:2040)
DETAIL: Raise error for debug_dtm_action = 3, debug_dtm_action_protocol = Begin Internal Subtransaction (seg0 127.0.1.1:25432 pid=24104)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 8 during statement block entry
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: catching the exception ...2
test_protocol_allseg
----------------------
(1 row)
select * from employees;
id | shop_id | gender
----+---------+--------
0 | 1 | m
(1 row)
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
NOTICE: catching the exception ...2
ERROR: DTM error (gathered results from cmd 'Rollback Current Subtransaction') (cdbtm.c:2040)
DETAIL: transaction 1518031192-0000000650 at level 1 already processed (current level 1) (cdbtm.c:3456) (seg0 127.0.1.1:25432 pid=24104)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 8 during exception cleanup
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: catching the exception ...2
test_protocol_allseg
----------------------
(1 row)
select * from employees;
id | shop_id | gender
----+---------+--------
0 | 1 | m
(1 row)
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
ERROR: DTM error (gathered results from cmd 'Rollback Current Subtransaction') (cdbtm.c:2040)
DETAIL: Raise ERROR for debug_dtm_action = 2, debug_dtm_action_protocol = Rollback Current Subtransaction (seg0 127.0.1.1:25432 pid=24104)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 17 during exception cleanup
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: catching the exception ...2
test_protocol_allseg
----------------------
(1 row)
select * from employees;
id | shop_id | gender
----+---------+--------
0 | 1 | m
(1 row)
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
NOTICE: catching the exception ...2
test_protocol_allseg
----------------------
(1 row)
select * from employees;
id | shop_id | gender
----+---------+--------
0 | 1 | m
(1 row)
-- Tests exception handling of GPDB PL/PgSQL UDF
-- It exercises:
-- 1. PROTOCOL or SQL type of dtm_action_target
-- 2. Various levels of sub-transactions
-- 3. dtm_action_protocol(PROTOCOL): subtransaction_begin, subtransaction_rollback or subtransaction_release
-- 4. dtm_action: fail_begin_command, fail_end_command or panic_begin_comand
--
-- debug_dtm_action: Using this can specify what action to be
-- triggered/simulated and at what point like error / panic / delay
-- and at start or end command after receiving by the segment.
-- debug_dtm_action_segment: Using this can specify segment number to
-- trigger the specified dtm_action.
-- debug_dtm_action_target: Allows to set target for specified
-- dtm_action should it be DTM protocol command or SQL command from
-- master to segment.
-- debug_dtm_action_protocol: Allows to specify sub-type of DTM
-- protocol for which to perform specified dtm_action (like prepare,
-- abort_no_prepared, commit_prepared, abort_prepared,
-- subtransaction_begin, subtransaction_release,
-- subtransaction_rollback, etc...
--
-- debug_dtm_action_sql_command_tag: If debug_dtm_action_target is sql
-- then this parameter can be used to set the type of sql that should
-- trigger the exeception. Ex: 'MPPEXEC UPDATE'
-- debug_dtm_action_nestinglevel: This allows to optional specify at
-- which specific depth level in transaction to take the specified
-- dtm_action. This apples only to target with protocol and not SQL.
--
--
-- start_matchsubs
-- s/\s+\(.*\.[ch]:\d+\)/ (SOMEFILE:SOMEFUNC)/
-- m/ /
-- m/transaction \d+/
-- s/transaction \d+/transaction /
-- m/transaction -\d+/
-- s/transaction -\d+/transaction/
-- end_matchsubs
CREATE OR REPLACE FUNCTION test_excep (arg INTEGER) RETURNS INTEGER
AS $$
DECLARE res INTEGER;
BEGIN
res := 100 / arg;
RETURN res;
EXCEPTION
WHEN division_by_zero
THEN RETURN 999;
END;
$$
LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION test_protocol_allseg(mid int, mshop int, mgender character) RETURNS VOID AS
$$
DECLARE tfactor int default 0;
BEGIN
BEGIN
CREATE TABLE employees(id int, shop_id int, gender character) DISTRIBUTED BY (id);
INSERT INTO employees VALUES (0, 1, 'm');
END;
BEGIN
BEGIN
IF EXISTS (select 1 from employees where id = mid) THEN
RAISE EXCEPTION 'Duplicate employee id';
ELSE
IF NOT (mshop between 1 AND 2) THEN
RAISE EXCEPTION 'Invalid shop id' ;
END IF;
END IF;
SELECT * INTO tfactor FROM test_excep(0);
BEGIN
INSERT INTO employees VALUES (mid, mshop, mgender);
EXCEPTION
WHEN OTHERS THEN
BEGIN
RAISE NOTICE 'catching the exception ...3';
END;
END;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'catching the exception ...2';
END;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'catching the exception ...1';
END;
END;
$$
LANGUAGE plpgsql;
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: Releasing segworker groups to finish aborting the transaction.
ERROR: DTM error (gathered results from cmd ' Begin Internal Subtransaction') (cdbtm.c:2040)
DETAIL: PANIC for debug_dtm_action = 4, debug_dtm_action_protocol = Begin Internal Subtransaction (postgres.c:1440) (seg1 127.0.1.1:25433 pid=24563)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 8 during statement block entry
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: Releasing segworker groups to finish aborting the transaction.
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 18 during exception cleanup
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=4;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: Releasing segworker groups to finish aborting the transaction.
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 18 during exception cleanup
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: Releasing segworker groups to finish aborting the transaction.
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 17 during exception cleanup
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: Releasing segworker groups to finish aborting the transaction.
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 17 during exception cleanup
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
--
--
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
NOTICE: table "employees" does not exist, skipping
select test_protocol_allseg(1, 2,'f');
NOTICE: Releasing segworker groups to finish aborting the transaction.
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
CONTEXT: PL/pgSQL function "test_protocol_allseg" line 17 during exception cleanup
ERROR: could not connect to segment: initialization of segworker group failed (cdbgang.c:235)
select * from employees;
ERROR: relation "employees" does not exist
LINE 1: select * from employees;
^
...@@ -79,6 +79,7 @@ test: sreh ...@@ -79,6 +79,7 @@ test: sreh
ignore: gp_portal_error ignore: gp_portal_error
test: external_table external_table_create_privs column_compression compression_zstd eagerfree alter_table_aocs alter_table_aocs2 alter_distribution_policy aoco_privileges aocs test: external_table external_table_create_privs column_compression compression_zstd eagerfree alter_table_aocs alter_table_aocs2 alter_distribution_policy aoco_privileges aocs
test: alter_table_set alter_table_gp alter_table_ao ao_create_alter_valid_table subtransaction_visibility oid_consistency udf_exception_blocks test: alter_table_set alter_table_gp alter_table_ao ao_create_alter_valid_table subtransaction_visibility oid_consistency udf_exception_blocks
test: udf_exception_blocks_panic_scenarios
test: ic test: ic
ignore: icudp_full ignore: icudp_full
......
...@@ -488,3 +488,215 @@ SELECT count(*) FROM test_truncate_tab; ...@@ -488,3 +488,215 @@ SELECT count(*) FROM test_truncate_tab;
INSERT INTO test_truncate_tab select * from generate_series(350, 400); INSERT INTO test_truncate_tab select * from generate_series(350, 400);
SELECT count(*) FROM test_truncate_tab; SELECT count(*) FROM test_truncate_tab;
-- Tests exception handling of GPDB PL/PgSQL UDF
-- It exercises:
-- 1. PROTOCOL or SQL type of dtm_action_target
-- 2. Various levels of sub-transactions
-- 3. dtm_action_protocol(PROTOCOL): subtransaction_begin, subtransaction_rollback or subtransaction_release
-- 4. dtm_action: fail_begin_command, fail_end_command or panic_begin_comand
--
-- debug_dtm_action: Using this can specify what action to be
-- triggered/simulated and at what point like error / panic / delay
-- and at start or end command after receiving by the segment.
-- debug_dtm_action_segment: Using this can specify segment number to
-- trigger the specified dtm_action.
-- debug_dtm_action_target: Allows to set target for specified
-- dtm_action should it be DTM protocol command or SQL command from
-- master to segment.
-- debug_dtm_action_protocol: Allows to specify sub-type of DTM
-- protocol for which to perform specified dtm_action (like prepare,
-- abort_no_prepared, commit_prepared, abort_prepared,
-- subtransaction_begin, subtransaction_release,
-- subtransaction_rollback, etc...
--
-- debug_dtm_action_sql_command_tag: If debug_dtm_action_target is sql
-- then this parameter can be used to set the type of sql that should
-- trigger the exeception. Ex: 'MPPEXEC UPDATE'
-- debug_dtm_action_nestinglevel: This allows to optional specify at
-- which specific depth level in transaction to take the specified
-- dtm_action. This apples only to target with protocol and not SQL.
--
--
-- start_matchsubs
-- s/\s+\(.*\.[ch]:\d+\)/ (SOMEFILE:SOMEFUNC)/
-- m/ /
-- m/transaction \d+/
-- s/transaction \d+/transaction /
-- m/transaction -\d+/
-- s/transaction -\d+/transaction/
-- end_matchsubs
CREATE OR REPLACE FUNCTION test_excep (arg INTEGER) RETURNS INTEGER
AS $$
DECLARE res INTEGER;
BEGIN
res := 100 / arg;
RETURN res;
EXCEPTION
WHEN division_by_zero
THEN RETURN 999;
END;
$$
LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION test_protocol_allseg(mid int, mshop int, mgender character) RETURNS VOID AS
$$
DECLARE tfactor int default 0;
BEGIN
BEGIN
CREATE TABLE employees(id int, shop_id int, gender character) DISTRIBUTED BY (id);
INSERT INTO employees VALUES (0, 1, 'm');
END;
BEGIN
BEGIN
IF EXISTS (select 1 from employees where id = mid) THEN
RAISE EXCEPTION 'Duplicate employee id';
ELSE
IF NOT (mshop between 1 AND 2) THEN
RAISE EXCEPTION 'Invalid shop id' ;
END IF;
END IF;
SELECT * INTO tfactor FROM test_excep(0);
BEGIN
INSERT INTO employees VALUES (mid, mshop, mgender);
EXCEPTION
WHEN OTHERS THEN
BEGIN
RAISE NOTICE 'catching the exception ...3';
END;
END;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'catching the exception ...2';
END;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'catching the exception ...1';
END;
END;
$$
LANGUAGE plpgsql;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=4;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=4;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=fail_begin_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=0;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=fail_end_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
-- Tests exception handling of GPDB PL/PgSQL UDF
-- It exercises:
-- 1. PROTOCOL or SQL type of dtm_action_target
-- 2. Various levels of sub-transactions
-- 3. dtm_action_protocol(PROTOCOL): subtransaction_begin, subtransaction_rollback or subtransaction_release
-- 4. dtm_action: fail_begin_command, fail_end_command or panic_begin_comand
--
-- debug_dtm_action: Using this can specify what action to be
-- triggered/simulated and at what point like error / panic / delay
-- and at start or end command after receiving by the segment.
-- debug_dtm_action_segment: Using this can specify segment number to
-- trigger the specified dtm_action.
-- debug_dtm_action_target: Allows to set target for specified
-- dtm_action should it be DTM protocol command or SQL command from
-- master to segment.
-- debug_dtm_action_protocol: Allows to specify sub-type of DTM
-- protocol for which to perform specified dtm_action (like prepare,
-- abort_no_prepared, commit_prepared, abort_prepared,
-- subtransaction_begin, subtransaction_release,
-- subtransaction_rollback, etc...
--
-- debug_dtm_action_sql_command_tag: If debug_dtm_action_target is sql
-- then this parameter can be used to set the type of sql that should
-- trigger the exeception. Ex: 'MPPEXEC UPDATE'
-- debug_dtm_action_nestinglevel: This allows to optional specify at
-- which specific depth level in transaction to take the specified
-- dtm_action. This apples only to target with protocol and not SQL.
--
--
-- start_matchsubs
-- s/\s+\(.*\.[ch]:\d+\)/ (SOMEFILE:SOMEFUNC)/
-- m/ /
-- m/transaction \d+/
-- s/transaction \d+/transaction /
-- m/transaction -\d+/
-- s/transaction -\d+/transaction/
-- end_matchsubs
CREATE OR REPLACE FUNCTION test_excep (arg INTEGER) RETURNS INTEGER
AS $$
DECLARE res INTEGER;
BEGIN
res := 100 / arg;
RETURN res;
EXCEPTION
WHEN division_by_zero
THEN RETURN 999;
END;
$$
LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION test_protocol_allseg(mid int, mshop int, mgender character) RETURNS VOID AS
$$
DECLARE tfactor int default 0;
BEGIN
BEGIN
CREATE TABLE employees(id int, shop_id int, gender character) DISTRIBUTED BY (id);
INSERT INTO employees VALUES (0, 1, 'm');
END;
BEGIN
BEGIN
IF EXISTS (select 1 from employees where id = mid) THEN
RAISE EXCEPTION 'Duplicate employee id';
ELSE
IF NOT (mshop between 1 AND 2) THEN
RAISE EXCEPTION 'Invalid shop id' ;
END IF;
END IF;
SELECT * INTO tfactor FROM test_excep(0);
BEGIN
INSERT INTO employees VALUES (mid, mshop, mgender);
EXCEPTION
WHEN OTHERS THEN
BEGIN
RAISE NOTICE 'catching the exception ...3';
END;
END;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'catching the exception ...2';
END;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'catching the exception ...1';
END;
END;
$$
LANGUAGE plpgsql;
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_release;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=4;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_rollback;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=0;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
--
--
SET debug_dtm_action_segment=1;
SET debug_dtm_action_target=protocol;
SET debug_dtm_action_protocol=subtransaction_begin;
SET debug_dtm_action=panic_begin_command;
SET debug_dtm_action_nestinglevel=3;
DROP TABLE IF EXISTS employees;
select test_protocol_allseg(1, 2,'f');
select * from employees;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册