提交 212fb781 编写于 作者: N Ning Yu 提交者: GitHub

Alter resgroup cpu

Support ALTER RESOURCE GROUP SET CPU_RATE_LIMIT syntax.

The new cpu rate limit take effect immediately at end of transaction.

Example 1:

    CREATE RESOURCE GROUP g1
        WITH (cpu_rate_limit=0.1,memory_limit=0.1);
    ALTER RESOURCE GROUP g1 SET CPU_RATE_LIMIT 0.2;

The new cpu rate limit take effect immediately.

Example 2:

    BEGIN;
    ALTER RESOURCE GROUP g1 SET CPU_RATE_LIMIT 0.2;

The new cpu rate limit doesn't take effect unless the transaction is
committed.
Signed-off-by: NRichard Guo <riguo@pivotal.io>
Signed-off-by: NGang Xiong <gxiong@pivotal.io>
上级 83ff0d71
......@@ -111,7 +111,7 @@ static float str2Float(const char *str, const char *prop);
static float text2Float(const text *text, const char *prop);
static int getResgroupOptionType(const char* defname);
static void parseStmtOptions(CreateResourceGroupStmt *stmt, ResourceGroupOptions *options);
static void validateCapabilities(Relation rel, Oid groupid, ResourceGroupOptions *options);
static void validateCapabilities(Relation rel, Oid groupid, ResourceGroupOptions *options, bool newGroup);
static void getResgroupCapabilityEntry(int groupId, int type, char **value, char **proposed);
static void insertResgroupCapabilityEntry(Relation rel, Oid groupid, uint16 type, char *value);
static void updateResgroupCapabilityEntry(Oid groupid, uint16 type, char *value, char *proposed);
......@@ -450,19 +450,23 @@ void
AlterResourceGroup(AlterResourceGroupStmt *stmt)
{
Relation pg_resgroup_rel;
Relation resgroup_capability_rel;
HeapTuple tuple;
ScanKeyData scankey;
SysScanDesc sscan;
Oid groupid;
ResourceGroupAlterCallbackContext * callbackCtx;
char concurrencyStr[16];
char concurrencyProposedStr[16];
ResourceGroupAlterCallbackContext *callbackCtx;
char valueStr[16];
char proposedStr[16];
int concurrency;
int concurrencyVal;
int concurrencyProposed;
int newConcurrency;
float cpuRateLimitVal;
float cpuRateLimitNew;
DefElem *defel;
int limitType;
bool needDispatch = true;
/* Permission check - only superuser can alter resource groups. */
if (!superuser())
......@@ -492,6 +496,20 @@ AlterResourceGroup(AlterResourceGroupStmt *stmt)
errmsg("concurrency limit cannot be less than %d",
RESGROUP_CONCURRENCY_UNLIMITED)));
break;
case RESGROUP_LIMIT_TYPE_CPU:
cpuRateLimitNew = defGetNumeric(defel);
if (cpuRateLimitNew <= .01f)
ereport(ERROR,
(errcode(ERRCODE_INVALID_LIMIT_VALUE),
errmsg("cpu rate limit must be greater than 0.01")));
if (cpuRateLimitNew >= 1.0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_LIMIT_VALUE),
errmsg("cpu rate limit must be less than 1.00")));
/* overall limit will be verified later after groupid is known */
break;
default:
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
......@@ -541,19 +559,68 @@ AlterResourceGroup(AlterResourceGroupStmt *stmt)
concurrency);
snprintf(concurrencyStr, sizeof(concurrencyStr), "%d", newConcurrency);
snprintf(concurrencyProposedStr, sizeof(concurrencyProposedStr), "%d", concurrency);
updateResgroupCapabilityEntry(groupid, limitType, concurrencyStr, concurrencyProposedStr);
snprintf(valueStr, sizeof(valueStr), "%d", newConcurrency);
snprintf(proposedStr, sizeof(proposedStr), "%d", concurrency);
updateResgroupCapabilityEntry(groupid, limitType, valueStr, proposedStr);
callbackCtx->value.i = newConcurrency;
callbackCtx->proposed.i = concurrency;
needDispatch = true;
break;
case RESGROUP_LIMIT_TYPE_CPU:
cpuRateLimitVal = GetCpuRateLimitForResGroup(groupid);
cpuRateLimitVal = roundf(cpuRateLimitVal * 100) / 100;
if (cpuRateLimitVal < cpuRateLimitNew)
{
ResourceGroupOptions options;
options.concurrency = 0;
options.cpuRateLimit = cpuRateLimitNew;
options.memoryLimit = 0;
options.redzoneLimit = 0;
/*
* In validateCapabilities() we scan all the resource groups
* to check whether the total cpu_rate_limit exceed 1.0 or not.
* We need to use ExclusiveLock here to prevent concurrent
* increase on different resource group.
*/
resgroup_capability_rel = heap_open(ResGroupCapabilityRelationId,
ExclusiveLock);
validateCapabilities(resgroup_capability_rel,
groupid, &options, false);
heap_close(resgroup_capability_rel, NoLock);
}
snprintf(valueStr, sizeof(valueStr),
"%.2f", cpuRateLimitNew);
snprintf(proposedStr, sizeof(proposedStr),
"%.2f", cpuRateLimitNew);
updateResgroupCapabilityEntry(groupid, limitType,
valueStr, proposedStr);
callbackCtx->value.f = cpuRateLimitNew;
callbackCtx->proposed.f = cpuRateLimitNew;
break;
default:
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unsupported resource group limit type '%s'", defel->defname)));
}
if (needDispatch && Gp_role == GP_ROLE_DISPATCH)
{
CdbDispatchUtilityStatement((Node *) stmt,
DF_CANCEL_ON_ERROR|
DF_WITH_SNAPSHOT|
DF_NEED_TWO_PHASE,
GetAssignedOidsForDispatch(), /* FIXME */
NULL);
}
/* Bump command counter to make this change visible in the callback function alterResGroupCommitCallback() */
CommandCounterIncrement();
......@@ -1220,22 +1287,53 @@ dropResGroupAbortCallback(bool isCommit, void *arg)
static void
alterResGroupCommitCallback(bool isCommit, void *arg)
{
if (isCommit)
volatile int savedInterruptHoldoffCount;
ResourceGroupAlterCallbackContext *ctx =
(ResourceGroupAlterCallbackContext *) arg;
if (!isCommit)
{
ResourceGroupAlterCallbackContext * ctx =
(ResourceGroupAlterCallbackContext *) arg;
pfree(arg);
return;
}
switch (ctx->limittype)
{
case RESGROUP_LIMIT_TYPE_CONCURRENCY:
/* wake up */
ResGroupAlterCheckForWakeup(ctx->groupid,
ctx->value.i,
ctx->proposed.i);
break;
default:
break;
}
switch (ctx->limittype)
{
case RESGROUP_LIMIT_TYPE_CONCURRENCY:
/* wake up */
ResGroupAlterCheckForWakeup(ctx->groupid,
ctx->value.i,
ctx->proposed.i);
break;
case RESGROUP_LIMIT_TYPE_CPU:
/*
* Apply the cpu rate limit to cgroup.
*
* This operation can fail in some cases, e.g.:
* 1. BEGIN;
* 2. CREATE RESOURCE GROUP g1 ...;
* 3. ALTER RESOURCE GROUP g1 SET CPU_RATE_LIMIT ...;
* 4. DROP RESOURCE GROUP g1;
* 5. COMMIT; -- or ABORT;
*
* So the error needs to be catched here.
*/
PG_TRY();
{
savedInterruptHoldoffCount = InterruptHoldoffCount;
ResGroupOps_SetCpuRateLimit(ctx->groupid, ctx->value.f);
}
PG_CATCH();
{
InterruptHoldoffCount = savedInterruptHoldoffCount;
elog(LOG, "Fail to set cpu_rate_limit for resource group %d", ctx->groupid);
}
PG_END_TRY();
break;
default:
break;
}
pfree(arg);
......@@ -1262,7 +1360,7 @@ insertResgroupCapabilities(Oid groupid,
char value[64];
Relation resgroup_capability_rel = heap_open(ResGroupCapabilityRelationId, RowExclusiveLock);
validateCapabilities(resgroup_capability_rel, groupid, options);
validateCapabilities(resgroup_capability_rel, groupid, options, true);
sprintf(value, "%d", options->concurrency);
insertResgroupCapabilityEntry(resgroup_capability_rel, groupid, RESGROUP_LIMIT_TYPE_CONCURRENCY, value);
......@@ -1357,7 +1455,8 @@ updateResgroupCapabilityEntry(Oid groupid, uint16 type, char *value, char *propo
static void
validateCapabilities(Relation rel,
Oid groupid,
ResourceGroupOptions *options)
ResourceGroupOptions *options,
bool newGroup)
{
HeapTuple tuple;
SysScanDesc sscan;
......@@ -1372,9 +1471,14 @@ validateCapabilities(Relation rel,
(Form_pg_resgroupcapability)GETSTRUCT(tuple);
if (resgCapability->resgroupid == groupid)
{
if (!newGroup)
continue;
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("Find duplicate resoure group id:%d", groupid)));
}
if (resgCapability->reslimittype == RESGROUP_LIMIT_TYPE_CPU)
{
......
......@@ -4442,6 +4442,17 @@ _copyDropResourceGroupStmt(DropResourceGroupStmt *from)
return newnode;
}
static AlterResourceGroupStmt *
_copyAlterResourceGroupStmt(AlterResourceGroupStmt *from)
{
AlterResourceGroupStmt *newnode = makeNode(AlterResourceGroupStmt);
COPY_STRING_FIELD(name);
COPY_NODE_FIELD(options);
return newnode;
}
static TableValueExpr *
_copyTableValueExpr(TableValueExpr *from)
{
......@@ -5235,6 +5246,9 @@ copyObject(void *from)
case T_DropResourceGroupStmt:
retval = _copyDropResourceGroupStmt(from);
break;
case T_AlterResourceGroupStmt:
retval = _copyAlterResourceGroupStmt(from);
break;
case T_A_Expr:
retval = _copyAExpr(from);
......
......@@ -1972,6 +1972,14 @@ _equalDropResourceGroupStmt(DropResourceGroupStmt *a, DropResourceGroupStmt *b)
return true;
}
static bool
_equalAlterResourceGroupStmt(AlterResourceGroupStmt *a, AlterResourceGroupStmt *b)
{
COMPARE_STRING_FIELD(name);
COMPARE_NODE_FIELD(options);
return true;
}
/*
* stuff from parsenodes.h
*/
......@@ -3023,6 +3031,9 @@ equal(void *a, void *b)
case T_DropResourceGroupStmt:
retval = _equalDropResourceGroupStmt(a, b);
break;
case T_AlterResourceGroupStmt:
retval = _equalAlterResourceGroupStmt(a, b);
break;
case T_A_Expr:
retval = _equalAExpr(a, b);
......
......@@ -1126,6 +1126,15 @@ _outCreateResourceGroupStmt(StringInfo str, CreateResourceGroupStmt *node)
WRITE_NODE_FIELD(options); /* List of DefElem nodes */
}
static void
_outAlterResourceGroupStmt(StringInfo str, AlterResourceGroupStmt *node)
{
WRITE_NODE_TYPE("ALTERRESOURCEGROUPSTMT");
WRITE_STRING_FIELD(name);
WRITE_NODE_FIELD(options); /* List of DefElem nodes */
}
static void
_outTupleDescNode(StringInfo str, TupleDescNode *node)
{
......@@ -1997,6 +2006,9 @@ _outNode(StringInfo str, void *obj)
case T_DropResourceGroupStmt:
_outDropResourceGroupStmt(str, obj);
break;
case T_AlterResourceGroupStmt:
_outAlterResourceGroupStmt(str, obj);
break;
case T_CommentStmt:
_outCommentStmt(str, obj);
......
......@@ -4234,6 +4234,17 @@ _outDropResourceGroupStmt(StringInfo str, DropResourceGroupStmt *node)
WRITE_STRING_FIELD(name);
}
#ifndef COMPILING_BINARY_FUNCS
static void
_outAlterResourceGroupStmt(StringInfo str, AlterResourceGroupStmt *node)
{
WRITE_NODE_TYPE("ALTERRESOURCEGROUPSTMT");
WRITE_STRING_FIELD(name);
WRITE_NODE_FIELD(options); /* List of DefElem nodes */
}
#endif /* COMPILING_BINARY_FUNCS */
static void
_outCommentStmt(StringInfo str, CommentStmt *node)
......@@ -5201,6 +5212,9 @@ _outNode(StringInfo str, void *obj)
case T_DropResourceGroupStmt:
_outDropResourceGroupStmt(str, obj);
break;
case T_AlterResourceGroupStmt:
_outAlterResourceGroupStmt(str, obj);
break;
case T_CommentStmt:
_outCommentStmt(str, obj);
......
......@@ -2530,6 +2530,17 @@ _readDropResourceGroupStmt(void)
READ_DONE();
}
static AlterResourceGroupStmt *
_readAlterResourceGroupStmt(void)
{
READ_LOCALS(AlterResourceGroupStmt);
READ_STRING_FIELD(name);
READ_NODE_FIELD(options);
READ_DONE();
}
static CommentStmt *
_readCommentStmt(void)
{
......@@ -3449,6 +3460,9 @@ readNodeBinary(void)
case T_DropResourceGroupStmt:
return_value = _readDropResourceGroupStmt();
break;
case T_AlterResourceGroupStmt:
return_value = _readAlterResourceGroupStmt();
break;
case T_CommentStmt:
return_value = _readCommentStmt();
......
......@@ -496,7 +496,7 @@ static Node *makeIsNotDistinctFromNode(Node *expr, int position);
CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
COMMITTED CONCURRENCY CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
CONTENT_P CONVERSION_P COPY COST CREATE CREATEDB
CONTENT_P CONVERSION_P COPY COST CPU_RATE_LIMIT CREATE CREATEDB
CREATEROLE CREATEUSER CROSS CSV CURRENT_P CURRENT_DATE CURRENT_ROLE
CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
......@@ -700,6 +700,7 @@ static Node *makeIsNotDistinctFromNode(Node *expr, int position);
%nonassoc CONVERSION_P
%nonassoc COPY
%nonassoc COST
%nonassoc CPU_RATE_LIMIT
%nonassoc CREATEDB
%nonassoc CREATEEXTTABLE
%nonassoc CREATEROLE
......@@ -1326,6 +1327,10 @@ OptResourceGroupElem:
/* was "concurrency" */
$$ = makeDefElem("concurrency", (Node *)$2);
}
| CPU_RATE_LIMIT FloatOnly
{
$$ = makeDefElem("cpu_rate_limit", (Node *)$2);
}
;
/*****************************************************************************
......@@ -13017,6 +13022,7 @@ unreserved_keyword:
| CONVERSION_P
| COPY
| COST
| CPU_RATE_LIMIT
| CREATEDB
| CREATEEXTTABLE
| CREATEROLE
......@@ -13327,6 +13333,7 @@ PartitionIdentKeyword: ABORT_P
| CONVERSION_P
| COPY
| COST
| CPU_RATE_LIMIT
| CREATEDB
| CREATEEXTTABLE
| CREATEROLE
......
......@@ -607,6 +607,39 @@ ResGroupOps_AssignGroup(Oid group, int pid)
writeInt64(group, "cpuacct", "cgroup.procs", pid);
}
/*
* Lock the OS group. While the group is locked it won't be removed by other
* processes.
*
* This function would block if block is true, otherwise it return with -1
* immediately.
*
* On success it return a fd to the OS group, pass it to
* ResGroupOps_UnLockGroup() to unblock it.
*/
int
ResGroupOps_LockGroup(Oid group, bool block)
{
char path[MAXPGPATH];
size_t pathsize = sizeof(path);
buildPath(group, "cpu", "", path, pathsize);
return lockDir(path, block);
}
/*
* Unblock a OS group.
*
* fd is the value returned by ResGroupOps_LockGroup().
*/
void
ResGroupOps_UnLockGroup(Oid group, int fd)
{
if (fd >= 0)
close(fd);
}
/*
* Set the cpu rate limit for the OS group.
*
......
......@@ -87,6 +87,34 @@ ResGroupOps_AssignGroup(Oid group, int pid)
unsupported_system();
}
/*
* Lock the OS group. While the group is locked it won't be removed by other
* processes.
*
* This function would block if block is true, otherwise it return with -1
* immediately.
*
* On success it return a fd to the OS group, pass it to
* ResGroupOps_UnLockGroup() to unblock it.
*/
int
ResGroupOps_LockGroup(Oid group, bool block)
{
unsupported_system();
return -1;
}
/*
* Unblock a OS group.
*
* fd is the value returned by ResGroupOps_LockGroup().
*/
void
ResGroupOps_UnLockGroup(Oid group, int fd)
{
unsupported_system();
}
/*
* Set the cpu rate limit for the OS group.
*
......
......@@ -95,6 +95,7 @@ PG_KEYWORD("continue", CONTINUE_P, UNRESERVED_KEYWORD)
PG_KEYWORD("conversion", CONVERSION_P, UNRESERVED_KEYWORD)
PG_KEYWORD("copy", COPY, UNRESERVED_KEYWORD)
PG_KEYWORD("cost", COST, UNRESERVED_KEYWORD)
PG_KEYWORD("cpu_rate_limit", CPU_RATE_LIMIT, UNRESERVED_KEYWORD)
PG_KEYWORD("create", CREATE, RESERVED_KEYWORD)
PG_KEYWORD("createdb", CREATEDB, UNRESERVED_KEYWORD)
PG_KEYWORD("createexttable", CREATEEXTTABLE, UNRESERVED_KEYWORD)
......
......@@ -22,6 +22,8 @@ extern void ResGroupOps_AdjustGUCs(void);
extern void ResGroupOps_CreateGroup(Oid group);
extern void ResGroupOps_DestroyGroup(Oid group);
extern void ResGroupOps_AssignGroup(Oid group, int pid);
extern int ResGroupOps_LockGroup(Oid group, bool block);
extern void ResGroupOps_UnLockGroup(Oid group, int fd);
extern void ResGroupOps_SetCpuRateLimit(Oid group, float cpu_rate_limit);
extern int64 ResGroupOps_GetCpuUsage(Oid group);
extern int ResGroupOps_GetCpuCores(void);
......
-- start_ignore
DROP RESOURCE GROUP rg_callback_test;
ERROR: resource group "rg_callback_test" does not exist
-- end_ignore
-- process callbacks on ABORT
BEGIN;
BEGIN
CREATE RESOURCE GROUP rg_callback_test WITH (concurrency=10, cpu_rate_limit=0.1, memory_limit=0.1);
CREATE
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
ALTER
DROP RESOURCE GROUP rg_callback_test;
DROP
ABORT;
ABORT
-- process callbacks on COMMIT
BEGIN;
BEGIN
CREATE RESOURCE GROUP rg_callback_test WITH (concurrency=10, cpu_rate_limit=0.1, memory_limit=0.1);
CREATE
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
ALTER
DROP RESOURCE GROUP rg_callback_test;
DROP
COMMIT;
COMMIT
-- process callbacks on ABORT after CREATE
CREATE RESOURCE GROUP rg_callback_test WITH (concurrency=10, cpu_rate_limit=0.1, memory_limit=0.1);
CREATE
BEGIN;
BEGIN
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
ALTER
DROP RESOURCE GROUP rg_callback_test;
DROP
ABORT;
ABORT
-- process callbacks on COMMIT after CREATE
BEGIN;
BEGIN
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
ALTER
DROP RESOURCE GROUP rg_callback_test;
DROP
COMMIT;
COMMIT
-- process callbacks on ABORT without DROP
BEGIN;
BEGIN
CREATE RESOURCE GROUP rg_callback_test WITH (concurrency=10, cpu_rate_limit=0.1, memory_limit=0.1);
CREATE
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
ALTER
ABORT;
ABORT
-- process callbacks on COMMIT without DROP
BEGIN;
BEGIN
CREATE RESOURCE GROUP rg_callback_test WITH (concurrency=10, cpu_rate_limit=0.1, memory_limit=0.1);
CREATE
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
ALTER
COMMIT;
COMMIT
DROP RESOURCE GROUP rg_callback_test;
DROP
......@@ -289,3 +289,73 @@ rsgname|num_running|num_queueing|num_queued|num_executed
-------+-----------+------------+----------+------------
(0 rows)
-- 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=0.1, memory_limit=0.2);
CREATE
CREATE RESOURCE GROUP rg2_concurrency_test WITH (concurrency=2, cpu_rate_limit=0.2, memory_limit=0.2);
CREATE
41:BEGIN;
BEGIN
41:ALTER RESOURCE GROUP rg1_concurrency_test SET CPU_RATE_LIMIT 0.35;
ALTER
42:BEGIN;
BEGIN
42&:ALTER RESOURCE GROUP rg2_concurrency_test SET CPU_RATE_LIMIT 0.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 |0.3
admin_group |0.1
rg1_concurrency_test|0.10
rg2_concurrency_test|0.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=0.1, memory_limit=0.2);
CREATE
CREATE RESOURCE GROUP rg2_concurrency_test WITH (concurrency=2, cpu_rate_limit=0.2, memory_limit=0.2);
CREATE
41:BEGIN;
BEGIN
41:ALTER RESOURCE GROUP rg1_concurrency_test SET CPU_RATE_LIMIT 0.35;
ALTER
42:BEGIN;
BEGIN
42&:ALTER RESOURCE GROUP rg2_concurrency_test SET CPU_RATE_LIMIT 0.35; <waiting ...>
41:COMMIT;
COMMIT
42<: <... completed>
ERROR: total cpu_rate_limit exceeded the limit of 1.0
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 |0.3
admin_group |0.1
rg1_concurrency_test|0.35
rg2_concurrency_test|0.20
(4 rows)
DROP RESOURCE GROUP rg1_concurrency_test;
DROP
DROP RESOURCE GROUP rg2_concurrency_test;
DROP
......@@ -183,6 +183,48 @@ ALTER
ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 1000;
ALTER
-- ALTER RESOURCE GROUP SET CPU_RATE_LIMIT VALUE
-- negative
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT -0.1;
ERROR: cpu rate limit must be greater than 0.01
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 2;
ERROR: syntax error at or near "2"
LINE 1: ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 2;
^
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.7;
ERROR: total cpu_rate_limit exceeded the limit of 1.0
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.01;
ERROR: cpu rate limit must be greater than 0.01
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT a;
ERROR: syntax error at or near "a"
LINE 1: ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT a;
^
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 'abc';
ERROR: syntax error at or near "'abc'"
LINE 1: ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 'abc';
^
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 20%;
ERROR: syntax error at or near "20"
LINE 1: ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 20%;
^
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.2%;
ERROR: syntax error at or near "%"
LINE 1: ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.2%;
^
-- positive
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.1;
ALTER
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.5;
ALTER
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.6;
ALTER
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.6;
ALTER
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.1;
ALTER
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.02;
ALTER
DROP RESOURCE GROUP rg_test_group;
DROP
......
-- ----------------------------------------------------------------------
-- Test: manage resource group in transaction
-- ----------------------------------------------------------------------
--start_ignore
DROP RESOURCE GROUP rg_test_group;
ERROR: resource group "rg_test_group" does not exist
--end_ignore
-- helper view to check the resgroup status
CREATE OR REPLACE VIEW rg_test_monitor AS SELECT groupname, concurrency, proposed_concurrency, cpu_rate_limit FROM gp_toolkit.gp_resgroup_config WHERE groupname='rg_test_group';
CREATE
-- ----------------------------------------------------------------------
-- Test: new resource group created in transaction then rollback
-- ----------------------------------------------------------------------
-- CREATE 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 |0.10
(1 row)
ROLLBACK;
ROLLBACK
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);
CREATE
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|10 |10 |0.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 |0.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 |0.10
(1 row)
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.11;
ALTER
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|11 |11 |0.11
(1 row)
ROLLBACK;
ROLLBACK
SELECT * FROM rg_test_monitor;
groupname|concurrency|proposed_concurrency|cpu_rate_limit
---------+-----------+--------------------+--------------
(0 rows)
-- CREATE, ALTER, DROP 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 |0.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 |0.10
(1 row)
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.11;
ALTER
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|11 |11 |0.11
(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
-- ----------------------------------------------------------------------
-- CREATE 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 |0.10
(1 row)
COMMIT;
COMMIT
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|10 |10 |0.10
(1 row)
DROP RESOURCE GROUP rg_test_group;
DROP
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);
CREATE
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|10 |10 |0.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 |0.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 |0.10
(1 row)
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.11;
ALTER
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|11 |11 |0.11
(1 row)
COMMIT;
COMMIT
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|11 |11 |0.11
(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
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 |0.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 |0.10
(1 row)
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.11;
ALTER
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|11 |11 |0.11
(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
-- ----------------------------------------------------------------------
CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=.10, memory_limit=.10);
CREATE
-- DROP then ROLLBACK
BEGIN;
BEGIN
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 |0.10
(1 row)
-- ALTER then ROLLBACK
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 |0.10
(1 row)
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.11;
ALTER
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|11 |11 |0.11
(1 row)
ROLLBACK;
ROLLBACK
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|10 |10 |0.10
(1 row)
-- ALTER, DROP then ROLLBACK
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 |0.10
(1 row)
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.11;
ALTER
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|11 |11 |0.11
(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 |0.10
(1 row)
-- ----------------------------------------------------------------------
-- Test: manage existing resource group in transaction then commit
-- ----------------------------------------------------------------------
-- 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
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|10 |10 |0.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 |0.10
(1 row)
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.11;
ALTER
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|11 |11 |0.11
(1 row)
COMMIT;
COMMIT
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|11 |11 |0.11
(1 row)
-- ALTER, DROP then COMMIT
BEGIN;
BEGIN
ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 12;
ALTER
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|12 |12 |0.11
(1 row)
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.12;
ALTER
SELECT * FROM rg_test_monitor;
groupname |concurrency|proposed_concurrency|cpu_rate_limit
-------------+-----------+--------------------+--------------
rg_test_group|12 |12 |0.12
(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 resource group in subtransaction must fail
-- ----------------------------------------------------------------------
-- CREATE in subtransaction
BEGIN;
BEGIN
SAVEPOINT sub1;
SAVEPOINT
CREATE RESOURCE GROUP rg_test_group WITH (concurrency=10, cpu_rate_limit=.10, memory_limit=.10);
ERROR: CREATE RESOURCE GROUP cannot run inside a subtransaction
ROLLBACK;
ROLLBACK
SELECT * FROM rg_test_monitor;
groupname|concurrency|proposed_concurrency|cpu_rate_limit
---------+-----------+--------------------+--------------
(0 rows)
-- ALTER and DROP in subtransaction
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 |0.10
(1 row)
BEGIN;
BEGIN
SAVEPOINT sub1;
SAVEPOINT
ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11;
ERROR: ALTER RESOURCE GROUP cannot run inside a subtransaction
ROLLBACK;
ROLLBACK
BEGIN;
BEGIN
SAVEPOINT sub1;
SAVEPOINT
ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11;
ERROR: ALTER RESOURCE GROUP cannot run inside a subtransaction
ROLLBACK;
ROLLBACK
BEGIN;
BEGIN
SAVEPOINT sub1;
SAVEPOINT
DROP RESOURCE GROUP rg_test_group;
ERROR: DROP RESOURCE GROUP cannot run inside a subtransaction
ROLLBACK;
ROLLBACK
DROP RESOURCE GROUP rg_test_group;
DROP
SELECT * FROM rg_test_monitor;
groupname|concurrency|proposed_concurrency|cpu_rate_limit
---------+-----------+--------------------+--------------
(0 rows)
-- cleanup
DROP VIEW rg_test_monitor;
DROP
test: resgroup/enable_resgroup_validate
test: resgroup/enable_resgroup
#test: resgroup/enable_resgroup_validate
#test: resgroup/enable_resgroup
#
#test: resgroup/resgroup_syntax
#test: resgroup/resgroup_transaction
test: resgroup/resgroup_syntax
test: resgroup/resgroup_cpu_rate_limit
test: resgroup/resgroup_concurrency
test: resgroup/drop_resgroup
test: resgroup/resgroup_memory
test: resgroup/resgroup_callback
test: resgroup/disable_resgroup
#test: resgroup/resgroup_memory
#test: resgroup/resgroup_cpu_rate_limit
#test: resgroup/drop_resgroup
#
#test: resgroup/disable_resgroup
-- start_ignore
DROP RESOURCE GROUP rg_callback_test;
-- end_ignore
-- process callbacks on ABORT
BEGIN;
CREATE RESOURCE GROUP rg_callback_test WITH (concurrency=10, cpu_rate_limit=0.1, memory_limit=0.1);
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
DROP RESOURCE GROUP rg_callback_test;
ABORT;
-- process callbacks on COMMIT
BEGIN;
CREATE RESOURCE GROUP rg_callback_test WITH (concurrency=10, cpu_rate_limit=0.1, memory_limit=0.1);
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
DROP RESOURCE GROUP rg_callback_test;
COMMIT;
-- process callbacks on ABORT after CREATE
CREATE RESOURCE GROUP rg_callback_test WITH (concurrency=10, cpu_rate_limit=0.1, memory_limit=0.1);
BEGIN;
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
DROP RESOURCE GROUP rg_callback_test;
ABORT;
-- process callbacks on COMMIT after CREATE
BEGIN;
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
DROP RESOURCE GROUP rg_callback_test;
COMMIT;
-- process callbacks on ABORT without DROP
BEGIN;
CREATE RESOURCE GROUP rg_callback_test WITH (concurrency=10, cpu_rate_limit=0.1, memory_limit=0.1);
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
ABORT;
-- process callbacks on COMMIT without DROP
BEGIN;
CREATE RESOURCE GROUP rg_callback_test WITH (concurrency=10, cpu_rate_limit=0.1, memory_limit=0.1);
ALTER RESOURCE GROUP rg_callback_test SET concurrency 20;
COMMIT;
DROP RESOURCE GROUP rg_callback_test;
......@@ -126,3 +126,38 @@
32<:
33: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';
-- 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=0.1, memory_limit=0.2);
CREATE RESOURCE GROUP rg2_concurrency_test WITH (concurrency=2, cpu_rate_limit=0.2, memory_limit=0.2);
41:BEGIN;
41:ALTER RESOURCE GROUP rg1_concurrency_test SET CPU_RATE_LIMIT 0.35;
42:BEGIN;
42&:ALTER RESOURCE GROUP rg2_concurrency_test SET CPU_RATE_LIMIT 0.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=0.1, memory_limit=0.2);
CREATE RESOURCE GROUP rg2_concurrency_test WITH (concurrency=2, cpu_rate_limit=0.2, memory_limit=0.2);
41:BEGIN;
41:ALTER RESOURCE GROUP rg1_concurrency_test SET CPU_RATE_LIMIT 0.35;
42:BEGIN;
42&:ALTER RESOURCE GROUP rg2_concurrency_test SET CPU_RATE_LIMIT 0.35;
41:COMMIT;
42<:
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;
......@@ -96,6 +96,24 @@ ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 1;
ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 2;
ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 1000;
-- ALTER RESOURCE GROUP SET CPU_RATE_LIMIT VALUE
-- negative
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT -0.1;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 2;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.7;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.01;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT a;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 'abc';
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 20%;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.2%;
-- positive
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.1;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.5;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.6;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.6;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.1;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.02;
DROP RESOURCE GROUP rg_test_group;
-- ----------------------------------------------------------------------
......
-- ----------------------------------------------------------------------
-- Test: manage resource group in transaction
-- ----------------------------------------------------------------------
--start_ignore
DROP RESOURCE GROUP rg_test_group;
--end_ignore
-- helper view to check the resgroup status
CREATE OR REPLACE VIEW rg_test_monitor AS
SELECT groupname, concurrency, proposed_concurrency, cpu_rate_limit
FROM gp_toolkit.gp_resgroup_config
WHERE groupname='rg_test_group';
-- ----------------------------------------------------------------------
-- Test: new resource group created in transaction then rollback
-- ----------------------------------------------------------------------
-- CREATE then ROLLBACK
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 0.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 0.11;
SELECT * FROM rg_test_monitor;
DROP RESOURCE GROUP rg_test_group;
SELECT * FROM rg_test_monitor;
ROLLBACK;
SELECT * FROM rg_test_monitor;
-- ----------------------------------------------------------------------
-- Test: new resource group created in transaction then commit
-- ----------------------------------------------------------------------
-- CREATE then COMMIT
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;
SELECT * FROM rg_test_monitor;
-- CREATE, 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;
DROP RESOURCE GROUP rg_test_group;
SELECT * FROM rg_test_monitor;
COMMIT;
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 0.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 0.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
-- ----------------------------------------------------------------------
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
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 0.11;
SELECT * FROM rg_test_monitor;
ROLLBACK;
SELECT * FROM rg_test_monitor;
-- ALTER, DROP then ROLLBACK
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 0.11;
SELECT * FROM rg_test_monitor;
DROP RESOURCE GROUP rg_test_group;
SELECT * FROM rg_test_monitor;
ROLLBACK;
SELECT * FROM rg_test_monitor;
-- ----------------------------------------------------------------------
-- Test: manage existing resource group in transaction then commit
-- ----------------------------------------------------------------------
-- DROP then COMMIT
BEGIN;
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);
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 0.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;
ALTER RESOURCE GROUP rg_test_group SET CPU_RATE_LIMIT 0.12;
SELECT * FROM rg_test_monitor;
DROP RESOURCE GROUP rg_test_group;
SELECT * FROM rg_test_monitor;
COMMIT;
SELECT * FROM rg_test_monitor;
-- ----------------------------------------------------------------------
-- Test: manage resource group in subtransaction must fail
-- ----------------------------------------------------------------------
-- CREATE in subtransaction
BEGIN;
SAVEPOINT sub1;
CREATE RESOURCE GROUP rg_test_group
WITH (concurrency=10, cpu_rate_limit=.10, memory_limit=.10);
ROLLBACK;
SELECT * FROM rg_test_monitor;
-- ALTER and DROP in subtransaction
CREATE RESOURCE GROUP rg_test_group
WITH (concurrency=10, cpu_rate_limit=.10, memory_limit=.10);
SELECT * FROM rg_test_monitor;
BEGIN;
SAVEPOINT sub1;
ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11;
ROLLBACK;
BEGIN;
SAVEPOINT sub1;
ALTER RESOURCE GROUP rg_test_group SET CONCURRENCY 11;
ROLLBACK;
BEGIN;
SAVEPOINT sub1;
DROP RESOURCE GROUP rg_test_group;
ROLLBACK;
DROP RESOURCE GROUP rg_test_group;
SELECT * FROM rg_test_monitor;
-- cleanup
DROP VIEW rg_test_monitor;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册