diff --git a/src/backend/commands/resgroupcmds.c b/src/backend/commands/resgroupcmds.c index 9573ebe48bcdd3ffce46bf0d21d64d75f052091a..cf31a33625aead6cf446dd2e673e1d23bc4b3d8a 100644 --- a/src/backend/commands/resgroupcmds.c +++ b/src/backend/commands/resgroupcmds.c @@ -178,12 +178,6 @@ CreateResourceGroup(CreateResourceGroupStmt *stmt) (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("must be superuser to create resource groups"))); - /* Subtransaction is not supported for resource group related operations */ - if (IsSubTransaction()) - ereport(ERROR, - (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION), - errmsg("CREATE RESOURCE GROUP cannot run inside a subtransaction"))); - /* * Check for an illegal name ('none' is used to signify no group in ALTER * ROLE). @@ -320,12 +314,6 @@ DropResourceGroup(DropResourceGroupStmt *stmt) (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("must be superuser to drop resource groups"))); - /* Subtransaction is not supported for resource group related operations */ - if (IsSubTransaction()) - ereport(ERROR, - (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION), - errmsg("DROP RESOURCE GROUP cannot run inside a subtransaction"))); - /* * Check the pg_resgroup relation to be certain the resource group already * exists. @@ -449,12 +437,6 @@ AlterResourceGroup(AlterResourceGroupStmt *stmt) (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("must be superuser to alter resource groups"))); - /* Subtransaction is not supported for resource group related operations */ - if (IsSubTransaction()) - ereport(ERROR, - (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION), - errmsg("ALTER RESOURCE GROUP cannot run inside a subtransaction"))); - /* Currently we only support to ALTER one limit at one time */ Assert(list_length(stmt->options) == 1); defel = (DefElem *) lfirst(list_head(stmt->options)); diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index e4821262db50572963114ca36f309013125e91de..4ac47ab20d06c70ca3fc61f96918e4463eb232ee 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -1743,14 +1743,23 @@ ProcessUtility(Node *parsetree, * ********************* RESOURCE GROUP statements **** */ case T_CreateResourceGroupStmt: + if (Gp_role == GP_ROLE_DISPATCH) + PreventTransactionChain(isTopLevel, "CREATE RESOURCE GROUP"); + CreateResourceGroup((CreateResourceGroupStmt *) parsetree); break; case T_AlterResourceGroupStmt: + if (Gp_role == GP_ROLE_DISPATCH) + PreventTransactionChain(isTopLevel, "ALTER RESOURCE GROUP"); + AlterResourceGroup((AlterResourceGroupStmt *) parsetree); break; case T_DropResourceGroupStmt: + if (Gp_role == GP_ROLE_DISPATCH) + PreventTransactionChain(isTopLevel, "DROP RESOURCE GROUP"); + DropResourceGroup((DropResourceGroupStmt *) parsetree); break; diff --git a/src/test/isolation2/expected/resgroup/resgroup_concurrency.out b/src/test/isolation2/expected/resgroup/resgroup_concurrency.out index 0d9a95cf481c04aecaebb96eb49830333fb7a8cd..1ab052c96e5abad58ba4aa181094c72ed636c089 100644 --- a/src/test/isolation2/expected/resgroup/resgroup_concurrency.out +++ b/src/test/isolation2/expected/resgroup/resgroup_concurrency.out @@ -4,7 +4,7 @@ DROP ROLE IF EXISTS role_concurrency_test; DROP -- start_ignore DROP RESOURCE GROUP rg_concurrency_test; -DROP +ERROR: resource group "rg_concurrency_test" does not exist -- end_ignore CREATE RESOURCE GROUP rg_concurrency_test WITH (concurrency=2, cpu_rate_limit=20, memory_limit=20); CREATE @@ -243,8 +243,6 @@ CREATE SET 32:BEGIN; BEGIN -BEGIN; -BEGIN DROP ROLE role_concurrency_test; DROP DROP RESOURCE GROUP rg_concurrency_test; @@ -252,143 +250,16 @@ ERROR: Cannot drop resource group "rg_concurrency_test" HINT: The resource group is currently managing 1 query(ies) and cannot be dropped. Terminate the queries first or try dropping the group later. The view pg_stat_activity tracks the queries managed by resource groups. -END; -END 32:END; END -32:RESET ROLE; -RESET - --- DROP is abortted -BEGIN; -BEGIN -DROP ROLE role_concurrency_test; -DROP -DROP RESOURCE GROUP rg_concurrency_test; -DROP -SELECT r.rsgname, num_running, num_queueing, num_queued, num_executed FROM gp_toolkit.gp_resgroup_status s, pg_resgroup r WHERE s.groupid=r.oid AND r.rsgname='rg_concurrency_test'; -rsgname|num_running|num_queueing|num_queued|num_executed --------+-----------+------------+----------+------------ -(0 rows) -32:SET ROLE role_concurrency_test; -SET -32&:BEGIN; -ABORT; -ABORT -32<: <... completed> -BEGIN -32:SELECT r.rsgname, num_running, num_queueing, num_queued, num_executed FROM gp_toolkit.gp_resgroup_status s, pg_resgroup r WHERE s.groupid=r.oid AND r.rsgname='rg_concurrency_test'; -rsgname |num_running|num_queueing|num_queued|num_executed --------------------+-----------+------------+----------+------------ -rg_concurrency_test|1 |0 |0 |3 -(1 row) -32:END; -END -32:RESET ROLE; -RESET - --- DROP is committed -BEGIN; -BEGIN -DROP ROLE role_concurrency_test; -DROP -DROP RESOURCE GROUP rg_concurrency_test; -DROP -SELECT r.rsgname, num_running, num_queueing, num_queued, num_executed FROM gp_toolkit.gp_resgroup_status s, pg_resgroup r WHERE s.groupid=r.oid AND r.rsgname='rg_concurrency_test'; -rsgname|num_running|num_queueing|num_queued|num_executed --------+-----------+------------+----------+------------ -(0 rows) -32:SET ROLE role_concurrency_test; -SET -32&:BEGIN; -END; -END -32<: <... completed> -ERROR: Resource group 32935 was concurrently dropped -32q: ... -SELECT r.rsgname, num_running, num_queueing, num_queued, num_executed FROM gp_toolkit.gp_resgroup_status s, pg_resgroup r WHERE s.groupid=r.oid AND r.rsgname='rg_concurrency_test'; -rsgname|num_running|num_queueing|num_queued|num_executed --------+-----------+------------+----------+------------ -(0 rows) DROP ROLE IF EXISTS role_concurrency_test; DROP DROP RESOURCE GROUP rg_concurrency_test; -ERROR: resource group "rg_concurrency_test" does not exist - --- test5: concurrently alter resource group cpu rate limit - --- start_ignore -DROP RESOURCE GROUP rg1_concurrency_test; -ERROR: resource group "rg1_concurrency_test" does not exist -DROP RESOURCE GROUP rg2_concurrency_test; -ERROR: resource group "rg2_concurrency_test" does not exist --- end_ignore - -CREATE RESOURCE GROUP rg1_concurrency_test WITH (concurrency=2, cpu_rate_limit=10, memory_limit=20); -CREATE -CREATE RESOURCE GROUP rg2_concurrency_test WITH (concurrency=2, cpu_rate_limit=20, memory_limit=20); -CREATE - -41:BEGIN; -BEGIN -41:ALTER RESOURCE GROUP rg1_concurrency_test SET CPU_RATE_LIMIT 35; -ALTER -42:BEGIN; -BEGIN -42&:ALTER RESOURCE GROUP rg2_concurrency_test SET CPU_RATE_LIMIT 35; -41:ABORT; -ABORT -42<: <... completed> -ALTER -42:COMMIT; -COMMIT -SELECT g.rsgname, c.cpu_rate_limit FROM gp_toolkit.gp_resgroup_config c, pg_resgroup g WHERE c.groupid=g.oid ORDER BY g.oid; -rsgname |cpu_rate_limit ---------------------+-------------- -default_group |30 -admin_group |10 -rg1_concurrency_test|10 -rg2_concurrency_test|35 -(4 rows) - -DROP RESOURCE GROUP rg1_concurrency_test; -DROP -DROP RESOURCE GROUP rg2_concurrency_test; -DROP - -CREATE RESOURCE GROUP rg1_concurrency_test WITH (concurrency=2, cpu_rate_limit=10, memory_limit=20); -CREATE -CREATE RESOURCE GROUP rg2_concurrency_test WITH (concurrency=2, cpu_rate_limit=20, memory_limit=20); -CREATE - -41:BEGIN; -BEGIN -41:ALTER RESOURCE GROUP rg1_concurrency_test SET CPU_RATE_LIMIT 35; -ALTER -42:BEGIN; -BEGIN -42&:ALTER RESOURCE GROUP rg2_concurrency_test SET CPU_RATE_LIMIT 35; -41:COMMIT; -COMMIT -42<: <... completed> -ERROR: total cpu_rate_limit exceeded the limit of 100 -41q: ... -42q: ... -SELECT g.rsgname, c.cpu_rate_limit FROM gp_toolkit.gp_resgroup_config c, pg_resgroup g WHERE c.groupid=g.oid ORDER BY g.oid; -rsgname |cpu_rate_limit ---------------------+-------------- -default_group |30 -admin_group |10 -rg1_concurrency_test|35 -rg2_concurrency_test|20 -(4 rows) - -DROP RESOURCE GROUP rg1_concurrency_test; -DROP -DROP RESOURCE GROUP rg2_concurrency_test; DROP +-- test5: concurrently alter resource group cpu rate limit +-- NONE -- test6: cancel a query that is waiting for a slot DROP ROLE IF EXISTS role_concurrency_test; @@ -420,7 +291,7 @@ ERROR: canceling statement due to user request SELECT pg_cancel_backend(procpid) FROM pg_stat_activity WHERE waiting_reason='resgroup' AND rsgname='rg_concurrency_test'; pg_cancel_backend ----------------- -t +t (1 row) 52<: <... completed> ERROR: canceling statement due to user request diff --git a/src/test/isolation2/expected/resgroup/resgroup_transaction.out b/src/test/isolation2/expected/resgroup/resgroup_transaction.out index 08d7617c5968848cb6da27741b45e969a4173a5c..46bdfd76690392bd8e1f45493f5e63c0e63bb5ba 100644 --- a/src/test/isolation2/expected/resgroup/resgroup_transaction.out +++ b/src/test/isolation2/expected/resgroup/resgroup_transaction.out @@ -12,466 +12,227 @@ CREATE OR REPLACE VIEW rg_test_monitor AS SELECT groupname, concurrency, propose CREATE -- ---------------------------------------------------------------------- --- Test: new resource group created in transaction then rollback +-- Test: create/alter/drop a resource group in transaction block -- ---------------------------------------------------------------------- --- CREATE then ROLLBACK +-- CREATE RESOURCE GROUP cannot run inside a transaction block BEGIN; BEGIN -CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); -CREATE -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 -(1 row) -ROLLBACK; -ROLLBACK +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); +ERROR: CREATE RESOURCE GROUP cannot run inside a transaction block +END; +END SELECT * FROM rg_test_monitor; groupname|concurrency|proposed_concurrency|cpu_rate_limit ---------+-----------+--------------------+-------------- (0 rows) --- CREATE, DROP then ROLLBACK -BEGIN; -BEGIN -CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); +-- ALTER RESOURCE GROUP cannot run inside a transaction block +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); CREATE -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 -(1 row) - -DROP RESOURCE GROUP rg_test_group; -DROP -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) -ROLLBACK; -ROLLBACK -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) - --- CREATE, ALTER then ROLLBACK BEGIN; BEGIN -CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); -CREATE -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 -(1 row) - -ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; -ALTER -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |10 -(1 row) - -ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; -ALTER +ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 10; +ERROR: ALTER RESOURCE GROUP cannot run inside a transaction block +END; +END SELECT * FROM rg_test_monitor; groupname |concurrency|proposed_concurrency|cpu_rate_limit -------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |11 +rg_test_group|20 |20 |5 (1 row) -ROLLBACK; -ROLLBACK -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) --- CREATE, ALTER, DROP then ROLLBACK +-- DROP RESOURCE GROUP cannot run inside a transaction block BEGIN; BEGIN -CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); -CREATE -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 -(1 row) - -ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; -ALTER -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |10 -(1 row) - -ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; -ALTER +DROP RESOURCE GROUP rg_test_group; +ERROR: DROP RESOURCE GROUP cannot run inside a transaction block +END; +END SELECT * FROM rg_test_monitor; groupname |concurrency|proposed_concurrency|cpu_rate_limit -------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |11 +rg_test_group|20 |20 |5 (1 row) DROP RESOURCE GROUP rg_test_group; DROP -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) -ROLLBACK; -ROLLBACK -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) + -- ---------------------------------------------------------------------- --- Test: new resource group created in transaction then commit +-- Test: create/alter/drop a resource group and DML in transaction block -- ---------------------------------------------------------------------- --- CREATE then COMMIT +-- CREATE RESOURCE GROUP cannot run inside a transaction block BEGIN; BEGIN -CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); -CREATE -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 +SELECT 1; +?column? +-------- +1 (1 row) -COMMIT; -COMMIT -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 -(1 row) -DROP RESOURCE GROUP rg_test_group; -DROP +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); +ERROR: CREATE RESOURCE GROUP cannot run inside a transaction block +END; +END SELECT * FROM rg_test_monitor; groupname|concurrency|proposed_concurrency|cpu_rate_limit ---------+-----------+--------------------+-------------- (0 rows) --- CREATE, DROP then COMMIT -BEGIN; -BEGIN -CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); +-- ALTER RESOURCE GROUP cannot run inside a transaction block +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); CREATE -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 -(1 row) - -DROP RESOURCE GROUP rg_test_group; -DROP -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) -COMMIT; -COMMIT -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) - --- CREATE, ALTER then COMMIT BEGIN; BEGIN -CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); -CREATE -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 +SELECT 1; +?column? +-------- +1 (1 row) - -ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; -ALTER -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |10 -(1 row) - -ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; -ALTER -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |11 -(1 row) -COMMIT; -COMMIT +ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 10; +ERROR: ALTER RESOURCE GROUP cannot run inside a transaction block +END; +END SELECT * FROM rg_test_monitor; groupname |concurrency|proposed_concurrency|cpu_rate_limit -------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |11 +rg_test_group|20 |20 |5 (1 row) -DROP RESOURCE GROUP rg_test_group; -DROP -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) --- CREATE, ALTER, DROP then COMMIT +-- DROP RESOURCE GROUP cannot run inside a transaction block BEGIN; BEGIN -CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); -CREATE -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 -(1 row) - -ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; -ALTER -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |10 +SELECT 1; +?column? +-------- +1 (1 row) - -ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; -ALTER +DROP RESOURCE GROUP rg_test_group; +ERROR: DROP RESOURCE GROUP cannot run inside a transaction block +END; +END SELECT * FROM rg_test_monitor; groupname |concurrency|proposed_concurrency|cpu_rate_limit -------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |11 +rg_test_group|20 |20 |5 (1 row) DROP RESOURCE GROUP rg_test_group; DROP -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) -COMMIT; -COMMIT -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) + -- ---------------------------------------------------------------------- --- Test: manage existing resource group in transaction then rollback +-- Test: create/alter/drop a resource group in subtransaction -- ---------------------------------------------------------------------- -CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); -CREATE - --- DROP then ROLLBACK +-- CREATE RESOURCE GROUP cannot run inside a subtransaction BEGIN; BEGIN -DROP RESOURCE GROUP rg_test_group; -DROP +SAVEPOINT rg_savepoint; +SAVEPOINT +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); +ERROR: CREATE RESOURCE GROUP cannot run inside a transaction block +ROLLBACK TO SAVEPOINT rg_savepoint; +ROLLBACK +ABORT; +ABORT SELECT * FROM rg_test_monitor; groupname|concurrency|proposed_concurrency|cpu_rate_limit ---------+-----------+--------------------+-------------- (0 rows) -ROLLBACK; -ROLLBACK -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 -(1 row) --- ALTER then ROLLBACK +-- ALTER RESOURCE GROUP cannot run inside a subtransaction +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); +CREATE BEGIN; BEGIN -ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; -ALTER -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |10 -(1 row) - -ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; -ALTER -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |11 -(1 row) -ROLLBACK; +SAVEPOINT rg_savepoint; +SAVEPOINT +ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 10; +ERROR: ALTER RESOURCE GROUP cannot run inside a transaction block +ROLLBACK TO SAVEPOINT rg_savepoint; ROLLBACK +ABORT; +ABORT SELECT * FROM rg_test_monitor; groupname |concurrency|proposed_concurrency|cpu_rate_limit -------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 +rg_test_group|20 |20 |5 (1 row) --- ALTER, DROP then ROLLBACK +-- DROP RESOURCE GROUP cannot run inside a subtransaction BEGIN; BEGIN -ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; -ALTER -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |10 -(1 row) - -ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; -ALTER +SAVEPOINT rg_savepoint; +SAVEPOINT +DROP RESOURCE GROUP rg_test_group; +ERROR: DROP RESOURCE GROUP cannot run inside a transaction block +ROLLBACK TO SAVEPOINT rg_savepoint; +ROLLBACK +ABORT; +ABORT SELECT * FROM rg_test_monitor; groupname |concurrency|proposed_concurrency|cpu_rate_limit -------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |11 +rg_test_group|20 |20 |5 (1 row) DROP RESOURCE GROUP rg_test_group; DROP -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) -ROLLBACK; -ROLLBACK -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 -(1 row) -- ---------------------------------------------------------------------- --- Test: manage existing resource group in transaction then commit +-- Test: create/alter/drop a resource group in function call -- ---------------------------------------------------------------------- --- DROP then COMMIT -BEGIN; -BEGIN -DROP RESOURCE GROUP rg_test_group; -DROP -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) -COMMIT; -COMMIT -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) -CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); +CREATE OR REPLACE FUNCTION rg_create_func() RETURNS VOID AS $$ CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5) $$ LANGUAGE SQL; CREATE -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|10 |10 |10 -(1 row) --- ALTER then COMMIT -BEGIN; -BEGIN -ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; -ALTER -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |10 -(1 row) +CREATE OR REPLACE FUNCTION rg_alter_func() RETURNS VOID AS $$ ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 10 $$ LANGUAGE SQL; +CREATE -ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; -ALTER -SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |11 -(1 row) -COMMIT; -COMMIT +CREATE OR REPLACE FUNCTION rg_drop_func() RETURNS VOID AS $$ DROP RESOURCE GROUP rg_test_group $$ LANGUAGE SQL; +CREATE + +-- CREATE RESOURCE GROUP cannot run inside a function call +SELECT * FROM rg_create_func(); +ERROR: CREATE RESOURCE GROUP cannot be executed from a function or multi-command string +CONTEXT: SQL function "rg_create_func" statement 1 SELECT * FROM rg_test_monitor; -groupname |concurrency|proposed_concurrency|cpu_rate_limit --------------+-----------+--------------------+-------------- -rg_test_group|11 |11 |11 -(1 row) +groupname|concurrency|proposed_concurrency|cpu_rate_limit +---------+-----------+--------------------+-------------- +(0 rows) --- ALTER, DROP then COMMIT -BEGIN; -BEGIN -ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 12; -ALTER +-- ALTER RESOURCE GROUP cannot run inside a function call +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); +CREATE +SELECT * FROM rg_alter_func(); +ERROR: ALTER RESOURCE GROUP cannot be executed from a function or multi-command string +CONTEXT: SQL function "rg_alter_func" statement 1 SELECT * FROM rg_test_monitor; groupname |concurrency|proposed_concurrency|cpu_rate_limit -------------+-----------+--------------------+-------------- -rg_test_group|12 |12 |11 +rg_test_group|20 |20 |5 (1 row) -ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 12; -ALTER +-- DROP RESOURCE GROUP cannot run inside a function call +SELECT * FROM rg_drop_func(); +ERROR: DROP RESOURCE GROUP cannot be executed from a function or multi-command string +CONTEXT: SQL function "rg_drop_func" statement 1 SELECT * FROM rg_test_monitor; groupname |concurrency|proposed_concurrency|cpu_rate_limit -------------+-----------+--------------------+-------------- -rg_test_group|12 |12 |12 +rg_test_group|20 |20 |5 (1 row) DROP RESOURCE GROUP rg_test_group; DROP -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) -COMMIT; -COMMIT -SELECT * FROM rg_test_monitor; -groupname|concurrency|proposed_concurrency|cpu_rate_limit ----------+-----------+--------------------+-------------- -(0 rows) - --- ---------------------------------------------------------------------- --- Test: create/alter/drop a resource group in subtransaction --- ---------------------------------------------------------------------- - --- CREATE RESOURCE GROUP cannot run inside a subtransaction -BEGIN; -BEGIN -SAVEPOINT rg_savepoint; -SAVEPOINT -CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); -ERROR: CREATE RESOURCE GROUP cannot run inside a subtransaction -ROLLBACK TO SAVEPOINT rg_savepoint; -ROLLBACK -ABORT; -ABORT - --- ALTER RESOURCE GROUP cannot run inside a subtransaction -BEGIN; -BEGIN -CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); -CREATE -SAVEPOINT rg_savepoint; -SAVEPOINT -ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 10; -ERROR: ALTER RESOURCE GROUP cannot run inside a subtransaction -ROLLBACK TO SAVEPOINT rg_savepoint; -ROLLBACK -ABORT; -ABORT - --- DROP RESOURCE GROUP cannot run inside a subtransaction -BEGIN; -BEGIN -CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); -CREATE -SAVEPOINT rg_savepoint; -SAVEPOINT -DROP RESOURCE GROUP rg_test_group; -ERROR: DROP RESOURCE GROUP cannot run inside a subtransaction -ROLLBACK TO SAVEPOINT rg_savepoint; -ROLLBACK -ABORT; -ABORT +DROP FUNCTION rg_create_func(); +DROP +DROP FUNCTION rg_alter_func(); +DROP +DROP FUNCTION rg_drop_func(); +DROP -- cleanup DROP VIEW rg_test_monitor; diff --git a/src/test/isolation2/sql/resgroup/resgroup_concurrency.sql b/src/test/isolation2/sql/resgroup/resgroup_concurrency.sql index e3276a3197e0804b6eb186649e90cee77552f717..7e054630c5328b5216a6aacd89189b9537c16197 100644 --- a/src/test/isolation2/sql/resgroup/resgroup_concurrency.sql +++ b/src/test/isolation2/sql/resgroup/resgroup_concurrency.sql @@ -120,79 +120,15 @@ CREATE ROLE role_concurrency_test RESOURCE GROUP rg_concurrency_test; -- DROP should fail if there're running transactions 32:SET ROLE role_concurrency_test; 32:BEGIN; -BEGIN; DROP ROLE role_concurrency_test; DROP RESOURCE GROUP rg_concurrency_test; -END; 32:END; -32:RESET ROLE; - --- DROP is abortted -BEGIN; -DROP ROLE role_concurrency_test; -DROP RESOURCE GROUP rg_concurrency_test; -SELECT r.rsgname, num_running, num_queueing, num_queued, num_executed FROM gp_toolkit.gp_resgroup_status s, pg_resgroup r WHERE s.groupid=r.oid AND r.rsgname='rg_concurrency_test'; -32:SET ROLE role_concurrency_test; -32&:BEGIN; -ABORT; -32<: -32:SELECT r.rsgname, num_running, num_queueing, num_queued, num_executed FROM gp_toolkit.gp_resgroup_status s, pg_resgroup r WHERE s.groupid=r.oid AND r.rsgname='rg_concurrency_test'; -32:END; -32:RESET ROLE; - --- DROP is committed -BEGIN; -DROP ROLE role_concurrency_test; -DROP RESOURCE GROUP rg_concurrency_test; -SELECT r.rsgname, num_running, num_queueing, num_queued, num_executed FROM gp_toolkit.gp_resgroup_status s, pg_resgroup r WHERE s.groupid=r.oid AND r.rsgname='rg_concurrency_test'; -32:SET ROLE role_concurrency_test; -32&:BEGIN; -END; -32<: -32q: -SELECT r.rsgname, num_running, num_queueing, num_queued, num_executed FROM gp_toolkit.gp_resgroup_status s, pg_resgroup r WHERE s.groupid=r.oid AND r.rsgname='rg_concurrency_test'; DROP ROLE IF EXISTS role_concurrency_test; DROP RESOURCE GROUP rg_concurrency_test; -- test5: concurrently alter resource group cpu rate limit - --- start_ignore -DROP RESOURCE GROUP rg1_concurrency_test; -DROP RESOURCE GROUP rg2_concurrency_test; --- end_ignore - -CREATE RESOURCE GROUP rg1_concurrency_test WITH (concurrency=2, cpu_rate_limit=10, memory_limit=20); -CREATE RESOURCE GROUP rg2_concurrency_test WITH (concurrency=2, cpu_rate_limit=20, memory_limit=20); - -41:BEGIN; -41:ALTER RESOURCE GROUP rg1_concurrency_test SET CPU_RATE_LIMIT 35; -42:BEGIN; -42&:ALTER RESOURCE GROUP rg2_concurrency_test SET CPU_RATE_LIMIT 35; -41:ABORT; -42<: -42:COMMIT; -SELECT g.rsgname, c.cpu_rate_limit FROM gp_toolkit.gp_resgroup_config c, pg_resgroup g WHERE c.groupid=g.oid ORDER BY g.oid; - -DROP RESOURCE GROUP rg1_concurrency_test; -DROP RESOURCE GROUP rg2_concurrency_test; - -CREATE RESOURCE GROUP rg1_concurrency_test WITH (concurrency=2, cpu_rate_limit=10, memory_limit=20); -CREATE RESOURCE GROUP rg2_concurrency_test WITH (concurrency=2, cpu_rate_limit=20, memory_limit=20); - -41:BEGIN; -41:ALTER RESOURCE GROUP rg1_concurrency_test SET CPU_RATE_LIMIT 35; -42:BEGIN; -42&:ALTER RESOURCE GROUP rg2_concurrency_test SET CPU_RATE_LIMIT 35; -41:COMMIT; -42<: -41q: -42q: -SELECT g.rsgname, c.cpu_rate_limit FROM gp_toolkit.gp_resgroup_config c, pg_resgroup g WHERE c.groupid=g.oid ORDER BY g.oid; - -DROP RESOURCE GROUP rg1_concurrency_test; -DROP RESOURCE GROUP rg2_concurrency_test; - +-- NONE -- test6: cancel a query that is waiting for a slot DROP ROLE IF EXISTS role_concurrency_test; diff --git a/src/test/isolation2/sql/resgroup/resgroup_transaction.sql b/src/test/isolation2/sql/resgroup/resgroup_transaction.sql index 6f9b73edf36f7f7aa9eaf9ca36c0aa88097ac9d8..b69923225b6d1762cf4977ac4e07b8af480845fd 100644 --- a/src/test/isolation2/sql/resgroup/resgroup_transaction.sql +++ b/src/test/isolation2/sql/resgroup/resgroup_transaction.sql @@ -13,190 +13,59 @@ CREATE OR REPLACE VIEW rg_test_monitor AS WHERE groupname='rg_test_group'; -- ---------------------------------------------------------------------- --- Test: new resource group created in transaction then rollback +-- Test: create/alter/drop a resource group in transaction block -- ---------------------------------------------------------------------- --- CREATE then ROLLBACK +-- CREATE RESOURCE GROUP cannot run inside a transaction block BEGIN; - CREATE RESOURCE GROUP rg_test_group - WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); - SELECT * FROM rg_test_monitor; -ROLLBACK; -SELECT * FROM rg_test_monitor; - --- CREATE, DROP then ROLLBACK -BEGIN; - CREATE RESOURCE GROUP rg_test_group - WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); - SELECT * FROM rg_test_monitor; - - DROP RESOURCE GROUP rg_test_group; - SELECT * FROM rg_test_monitor; -ROLLBACK; -SELECT * FROM rg_test_monitor; - --- CREATE, ALTER then ROLLBACK -BEGIN; - CREATE RESOURCE GROUP rg_test_group - WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; - SELECT * FROM rg_test_monitor; -ROLLBACK; -SELECT * FROM rg_test_monitor; - --- CREATE, ALTER, DROP then ROLLBACK -BEGIN; - CREATE RESOURCE GROUP rg_test_group - WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; - SELECT * FROM rg_test_monitor; - - DROP RESOURCE GROUP rg_test_group; - SELECT * FROM rg_test_monitor; -ROLLBACK; + CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); +END; SELECT * FROM rg_test_monitor; --- ---------------------------------------------------------------------- --- Test: new resource group created in transaction then commit --- ---------------------------------------------------------------------- - --- CREATE then COMMIT +-- ALTER RESOURCE GROUP cannot run inside a transaction block +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); BEGIN; - CREATE RESOURCE GROUP rg_test_group - WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); - SELECT * FROM rg_test_monitor; -COMMIT; -SELECT * FROM rg_test_monitor; -DROP RESOURCE GROUP rg_test_group; + ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 10; +END; SELECT * FROM rg_test_monitor; --- CREATE, DROP then COMMIT +-- DROP RESOURCE GROUP cannot run inside a transaction block BEGIN; - CREATE RESOURCE GROUP rg_test_group - WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); - SELECT * FROM rg_test_monitor; - DROP RESOURCE GROUP rg_test_group; - SELECT * FROM rg_test_monitor; -COMMIT; +END; SELECT * FROM rg_test_monitor; --- CREATE, ALTER then COMMIT -BEGIN; - CREATE RESOURCE GROUP rg_test_group - WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; - SELECT * FROM rg_test_monitor; -COMMIT; -SELECT * FROM rg_test_monitor; DROP RESOURCE GROUP rg_test_group; -SELECT * FROM rg_test_monitor; - --- CREATE, ALTER, DROP then COMMIT -BEGIN; - CREATE RESOURCE GROUP rg_test_group - WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; - SELECT * FROM rg_test_monitor; - DROP RESOURCE GROUP rg_test_group; - SELECT * FROM rg_test_monitor; -COMMIT; -SELECT * FROM rg_test_monitor; -- ---------------------------------------------------------------------- --- Test: manage existing resource group in transaction then rollback +-- Test: create/alter/drop a resource group and DML in transaction block -- ---------------------------------------------------------------------- -CREATE RESOURCE GROUP rg_test_group - WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); - --- DROP then ROLLBACK -BEGIN; - DROP RESOURCE GROUP rg_test_group; - SELECT * FROM rg_test_monitor; -ROLLBACK; -SELECT * FROM rg_test_monitor; - --- ALTER then ROLLBACK +-- CREATE RESOURCE GROUP cannot run inside a transaction block BEGIN; - ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; - SELECT * FROM rg_test_monitor; -ROLLBACK; + SELECT 1; + CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); +END; SELECT * FROM rg_test_monitor; --- ALTER, DROP then ROLLBACK +-- ALTER RESOURCE GROUP cannot run inside a transaction block +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); BEGIN; - ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; - SELECT * FROM rg_test_monitor; - - DROP RESOURCE GROUP rg_test_group; - SELECT * FROM rg_test_monitor; -ROLLBACK; + SELECT 1; + ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 10; +END; SELECT * FROM rg_test_monitor; --- ---------------------------------------------------------------------- --- Test: manage existing resource group in transaction then commit --- ---------------------------------------------------------------------- - --- DROP then COMMIT +-- DROP RESOURCE GROUP cannot run inside a transaction block BEGIN; + SELECT 1; DROP RESOURCE GROUP rg_test_group; - SELECT * FROM rg_test_monitor; -COMMIT; -SELECT * FROM rg_test_monitor; -CREATE RESOURCE GROUP rg_test_group - WITH (concurrency=10, cpu_rate_limit=10, memory_limit=10); +END; SELECT * FROM rg_test_monitor; --- ALTER then COMMIT -BEGIN; - ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11; - SELECT * FROM rg_test_monitor; - - ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 11; - SELECT * FROM rg_test_monitor; -COMMIT; -SELECT * FROM rg_test_monitor; - --- ALTER, DROP then COMMIT -BEGIN; - ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 12; - SELECT * FROM rg_test_monitor; +DROP RESOURCE GROUP rg_test_group; - ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 12; - SELECT * FROM rg_test_monitor; - - DROP RESOURCE GROUP rg_test_group; - SELECT * FROM rg_test_monitor; -COMMIT; -SELECT * FROM rg_test_monitor; -- ---------------------------------------------------------------------- -- Test: create/alter/drop a resource group in subtransaction @@ -208,22 +77,60 @@ BEGIN; CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); ROLLBACK TO SAVEPOINT rg_savepoint; ABORT; +SELECT * FROM rg_test_monitor; -- ALTER RESOURCE GROUP cannot run inside a subtransaction +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); BEGIN; - CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); SAVEPOINT rg_savepoint; ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 10; ROLLBACK TO SAVEPOINT rg_savepoint; ABORT; +SELECT * FROM rg_test_monitor; -- DROP RESOURCE GROUP cannot run inside a subtransaction BEGIN; - CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); SAVEPOINT rg_savepoint; DROP RESOURCE GROUP rg_test_group; ROLLBACK TO SAVEPOINT rg_savepoint; ABORT; +SELECT * FROM rg_test_monitor; + +DROP RESOURCE GROUP rg_test_group; + +-- ---------------------------------------------------------------------- +-- Test: create/alter/drop a resource group in function call +-- ---------------------------------------------------------------------- + +CREATE OR REPLACE FUNCTION rg_create_func() RETURNS VOID +AS $$ CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5) $$ +LANGUAGE SQL; + +CREATE OR REPLACE FUNCTION rg_alter_func() RETURNS VOID +AS $$ ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 10 $$ +LANGUAGE SQL; + +CREATE OR REPLACE FUNCTION rg_drop_func() RETURNS VOID +AS $$ DROP RESOURCE GROUP rg_test_group $$ +LANGUAGE SQL; + +-- CREATE RESOURCE GROUP cannot run inside a function call +SELECT * FROM rg_create_func(); +SELECT * FROM rg_test_monitor; + +-- ALTER RESOURCE GROUP cannot run inside a function call +CREATE RESOURCE GROUP rg_test_group WITH (cpu_rate_limit=5, memory_limit=5); +SELECT * FROM rg_alter_func(); +SELECT * FROM rg_test_monitor; + +-- DROP RESOURCE GROUP cannot run inside a function call +SELECT * FROM rg_drop_func(); +SELECT * FROM rg_test_monitor; + +DROP RESOURCE GROUP rg_test_group; +DROP FUNCTION rg_create_func(); +DROP FUNCTION rg_alter_func(); +DROP FUNCTION rg_drop_func(); -- cleanup DROP VIEW rg_test_monitor;