提交 f33658ce 编写于 作者: R Richard Guo 提交者: GitHub

Make resource group DDL cannot run inside transaction block.

Resource group DDL is supposed to be executed by DBA and usually will not be in an explicit transaction with other statements.
To reduce the complexity of resource group, resource group DDL is designed cannot run inside transaction block, sub-transaction, function or multi-command string.
Signed-off-by: NZhenghua Lyu <zlv@pivotal.io>
上级 45deda87
......@@ -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));
......
......@@ -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;
......
......@@ -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; <waiting ...>
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; <waiting ...>
END;
END
32<: <... completed>
ERROR: Resource group 32935 was concurrently dropped
32q: ... <quitting>
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; <waiting ...>
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; <waiting ...>
41:COMMIT;
COMMIT
42<: <... completed>
ERROR: total cpu_rate_limit exceeded the limit of 100
41q: ... <quitting>
42q: ... <quitting>
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
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册