From 6fe0e72d55a34a0858627d1dcfc9ffd9b04ffe87 Mon Sep 17 00:00:00 2001 From: lepip Date: Thu, 11 Jan 2024 09:39:03 +0000 Subject: [PATCH 1/9] Added support for deactivating rules --- src/query_tag.c | 2 +- test/expected/query_tag.out | 20 ++++++++++---------- test/sql/query_tag.sql | 18 +++++++++--------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/query_tag.c b/src/query_tag.c index df5bf50..901ccef 100644 --- a/src/query_tag.c +++ b/src/query_tag.c @@ -94,7 +94,7 @@ static Oid resgroup_assign_by_query_tag(void) { int full_length = snprintf( query, sizeof(query), "select rule_id, dest_resg from wlm_rules where resgname = '%s' and role " - "= '%s' and is_tag_in_guc(query_tag) order by order_id limit 1;", + "= '%s' and active = TRUE and is_tag_in_guc(query_tag) order by order_id limit 1;", rgname, rolename); if (full_length >= MAX_QUERY_SIZE) { elog(ERROR, "QUERY_TAG: failed, query tag too long"); diff --git a/test/expected/query_tag.out b/test/expected/query_tag.out index a285720..775aebe 100644 --- a/test/expected/query_tag.out +++ b/test/expected/query_tag.out @@ -53,10 +53,10 @@ CREATE RESOURCE GROUP rgroup1 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_S ERROR: resource group "rgroup1" already exists CREATE RESOURCE GROUP rgroup2 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); ERROR: resource group "rgroup2" already exists -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag) - VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1'); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag) - VALUES ('admin_group', 'clepip', 'rgroup2', 4, 'group=rgroup1'); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1', TRUE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup2', 4, 'group=rgroup1', TRUE); SET QUERY_TAG TO "group=rgroup1"; SELECT current_resgroup(); current_resgroup @@ -66,10 +66,10 @@ SELECT current_resgroup(); -- should still set to rgroup1 (we are in admin_group, the "current_rsgroup" shows group after --- applying tags, and tags are applied accordingly to users rsgroup) -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag) - VALUES ('rgroup1', 'clepip', 'rgroup2', 1, 'group=still_1'); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag) - VALUES ('admin_group', 'clepip', 'rgroup1', 5, 'group=still_1'); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('rgroup1', 'clepip', 'rgroup2', 1, 'group=still_1', TRUE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup1', 5, 'group=still_1', TRUE); SET QUERY_TAG TO "group=still_1"; SELECT CURRENT_RESGROUP(); current_resgroup @@ -77,7 +77,7 @@ SELECT CURRENT_RESGROUP(); rgroup1 (1 row) --- (right now doesn't work) +-- should set to rgroup1 INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) VALUES ('admin_group', 'clepip', 'rgroup2', 1, 'group=cancelled', FALSE); INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) @@ -86,6 +86,6 @@ SET QUERY_TAG TO "group=cancelled"; SELECT CURRENT_RESGROUP(); current_resgroup ------------------ - rgroup2 + rgroup1 (1 row) diff --git a/test/sql/query_tag.sql b/test/sql/query_tag.sql index 5c3fec4..d157553 100644 --- a/test/sql/query_tag.sql +++ b/test/sql/query_tag.sql @@ -30,10 +30,10 @@ SHOW QUERY_TAG; CREATE RESOURCE GROUP rgroup1 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); CREATE RESOURCE GROUP rgroup2 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag) - VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1'); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag) - VALUES ('admin_group', 'clepip', 'rgroup2', 4, 'group=rgroup1'); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1', TRUE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup2', 4, 'group=rgroup1', TRUE); SET QUERY_TAG TO "group=rgroup1"; SELECT current_resgroup(); @@ -41,15 +41,15 @@ SELECT current_resgroup(); -- should still set to rgroup1 (we are in admin_group, the "current_rsgroup" shows group after --- applying tags, and tags are applied accordingly to users rsgroup) -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag) - VALUES ('rgroup1', 'clepip', 'rgroup2', 1, 'group=still_1'); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag) - VALUES ('admin_group', 'clepip', 'rgroup1', 5, 'group=still_1'); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('rgroup1', 'clepip', 'rgroup2', 1, 'group=still_1', TRUE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup1', 5, 'group=still_1', TRUE); SET QUERY_TAG TO "group=still_1"; SELECT CURRENT_RESGROUP(); --- (right now doesn't work) +-- should set to rgroup1 INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) VALUES ('admin_group', 'clepip', 'rgroup2', 1, 'group=cancelled', FALSE); From 984dedab96b0defba9deec2f77f3a60ad98fa0b2 Mon Sep 17 00:00:00 2001 From: lepip Date: Thu, 11 Jan 2024 14:52:11 +0000 Subject: [PATCH 2/9] save progress (unstable) --- src/query_tag.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/query_tag.c b/src/query_tag.c index 901ccef..dc0becc 100644 --- a/src/query_tag.c +++ b/src/query_tag.c @@ -33,14 +33,13 @@ static const int MAX_QUERY_TAG_LENGTH = 100; static resgroup_assign_hook_type prev_hook = NULL; Datum is_tag_in_guc(PG_FUNCTION_ARGS) { - text *query_tag = PG_GETARG_TEXT_P(0); - char *query_tag_str = text_to_cstring(query_tag); - - const char *guc_query_tag_value = - GetConfigOption("QUERY_TAG", false, false); - bool result = is_tag_in_guc_ctype(query_tag_str, guc_query_tag_value); - - pfree(query_tag_str); + text *rule_query_tag = PG_GETARG_TEXT_P(0); + char *rule_query_tag_cstr = text_to_cstring(rule_query_tag); + bool result = is_tag_in_guc_ctype(rule_query_tag_cstr, query_tag); + + List *tags; + bool aboba = SplitIdentifierString(rule_query_tag_cstr, ';', &tags); + pfree(rule_query_tag_cstr); PG_RETURN_BOOL(result); } From 629d22bd8ebf2aeb73564f64042217a10a25c727 Mon Sep 17 00:00:00 2001 From: lepip Date: Sun, 14 Jan 2024 18:35:13 +0000 Subject: [PATCH 3/9] New parser version (doesn't work) --- src/parser.c | 189 ++++++------------------------------------------ src/parser.h | 12 +-- src/query_tag.c | 54 +++++++++----- 3 files changed, 63 insertions(+), 192 deletions(-) diff --git a/src/parser.c b/src/parser.c index 02e7b4d..c68d8c3 100644 --- a/src/parser.c +++ b/src/parser.c @@ -5,187 +5,46 @@ #include "c.h" #include -static bool good_char(char c) { - return (isalnum(c) || c == '=' || c == ';' || c == '_'); -} - -bool parse_tags(const char *guc, List **parsed) { - *parsed = NIL; - bool is_in_key = true; - bool is_empty = true; - const char *substr_ptr_start; - const char *substr_ptr_end; - char *key_tag = NULL, *value_tag = NULL; - if (!guc || *guc == '\0') { - return true; - } - substr_ptr_start = guc; - const char *cur; - for (cur = guc;; ++cur) { - if (*cur == '\0') { - if (is_in_key) { - return false; - } - if (is_empty) { - return true; - } - substr_ptr_end = cur; - value_tag = copy_substr(substr_ptr_start, substr_ptr_end); - substr_ptr_start = cur + 1; - - tag_pair *tpair; - tpair = malloc(sizeof(tpair)); - tpair->key = key_tag; - tpair->value = value_tag; - *parsed = lappend(*parsed, tpair); - break; - } - if (!good_char(*cur)) { - return false; - } - if (*cur == '=') { - if (is_empty) { - return false; - } - if (is_in_key) { - is_in_key = false; - is_empty = true; - } else { - return false; - } - } - if (*cur == ';') { - if (is_empty) { - return false; - } - if (is_in_key) { - return false; - } else { - is_in_key = true; - is_empty = true; - } - } - if (isalpha(*cur) || *cur == '_') { - is_empty = false; - } - if (*cur == '=') { - substr_ptr_end = cur; - key_tag = copy_substr(substr_ptr_start, substr_ptr_end); - substr_ptr_start = cur + 1; - } - if (*cur == ';') { - substr_ptr_end = cur; - value_tag = copy_substr(substr_ptr_start, substr_ptr_end); - substr_ptr_start = cur + 1; - - tag_pair *tpair; - tpair = malloc(sizeof(tpair)); - tpair->key = key_tag; - tpair->value = value_tag; - *parsed = lappend(*parsed, tpair); - } - } - - return true; -} -void tag_list_free(List **tag_list) { - ListCell *cell; - foreach (cell, *tag_list) { - tag_pair *tpair = lfirst(cell); - free(tpair->key); - free(tpair->value); - free(tpair); - } - list_free(*tag_list); - *tag_list = NIL; -} - -bool is_safe(const char *guc) { - if (!guc) +bool split_tags(char *tags, List **splitted) { + List *tags_list = NIL; + bool ok = SplitIdentifierString(tags, ';', &tags_list); + if (!ok) { + list_free(tags_list); return false; - if (*guc == '\0') - return true; - bool is_in_key = true; - bool is_empty = true; - for (const char *cur = guc; *cur != '\0'; ++cur) { - if (!good_char(*cur)) { - elog(INFO, "GUHed char: %c", *cur); + } + ListCell *current_tag; + list_free(*splitted); + *splitted = NIL; + foreach(current_tag, tags_list) { + List *parsed_tags; + ok = SplitIdentifierString(lfirst(current_tag), '=', &parsed_tags); + if (!ok || list_length(parsed_tags) != 2) { + list_free(tags_list); + list_free(parsed_tags); return false; } - if (*cur == '=') { - if (is_empty) { - return false; - } - if (is_in_key) { - is_in_key = false; - is_empty = true; - } else { - return false; - } - } - if (*cur == ';') { - if (is_empty) { - return false; - } - if (is_in_key) { - return false; - } else { - is_in_key = true; - is_empty = true; - } - } - if (isalnum(*cur) || *cur == '_') { - is_empty = false; - } + *splitted = lappend(*splitted, parsed_tags); } - if (is_in_key && !is_empty) - return false; return true; } -char *copy_substr(const char *start, const char *end) { - int len = end - start; - char *ret = calloc(len + 1, sizeof(char)); - memcpy(ret, start, len); - ret[len] = '\0'; - return ret; -} - -bool is_tag_in_guc_ctype(const char *tag, const char *guc) { - List *parsed_guc = NIL; - List *parsed_tag = NIL; - - bool ok = parse_tags(guc, &parsed_guc); - if (!ok) { - tag_list_free(&parsed_guc); - return false; - } - - ok = parse_tags(tag, &parsed_tag); - if (!ok) { - tag_list_free(&parsed_tag); - return false; - } - ListCell *guc_pair_cell, *tag_pair_cell; - foreach (tag_pair_cell, parsed_tag) { - tag_pair *cur_tag = lfirst(tag_pair_cell); +bool is_tag_list_in_guc_list(List *rule_tags, List *guc_tags) { + ListCell *guc_cell, *tag_cell; + foreach (tag_cell, rule_tags) { + List *tag_pair = lfirst(tag_cell); bool found = false; - foreach (guc_pair_cell, parsed_guc) { - tag_pair *cur_guc = lfirst(guc_pair_cell); - if (strcmp(cur_tag->key, cur_guc->key) == 0 && - strcmp(cur_tag->value, cur_guc->value) == 0) { + foreach (guc_cell, guc_tags) { + List *guc_pair = lfirst(guc_cell); + if (strcmp(linitial(guc_pair), linitial(tag_pair)) == 0 && + strcmp(lsecond(guc_pair), lsecond(tag_pair)) == 0) { found = true; break; } } if (!found) { - tag_list_free(&parsed_guc); - tag_list_free(&parsed_tag); return false; } } - tag_list_free(&parsed_guc); - tag_list_free(&parsed_tag); return true; } diff --git a/src/parser.h b/src/parser.h index 5cc26ec..96cf863 100644 --- a/src/parser.h +++ b/src/parser.h @@ -1,12 +1,4 @@ #include "nodes/pg_list.h" -typedef struct tpair{ - char *key; - char *value; -} tag_pair; - -bool is_safe(const char *guc); -bool parse_tags(const char *guc, List **parsed); -void tag_list_free(List **tag_list); -char *copy_substr(const char *start, const char *end); -bool is_tag_in_guc_ctype(const char *tag, const char *guc); +bool split_tags(char *tags, List **splitted); +bool is_tag_list_in_guc_list(List *rule_tags, List *guc_tags); \ No newline at end of file diff --git a/src/query_tag.c b/src/query_tag.c index dc0becc..fb1f53c 100644 --- a/src/query_tag.c +++ b/src/query_tag.c @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -25,6 +26,9 @@ static bool check_new_query_tag(char **, void **, GucSource); void _PG_init(void); void _PG_fini(void); +static List *parsed_query_tags; + +static char *query_tag_mutable; static char *query_tag = NULL; const static char *NO_GROUP_MSG = "unknown"; static const int MAX_QUERY_SIZE = 200; @@ -35,13 +39,21 @@ static resgroup_assign_hook_type prev_hook = NULL; Datum is_tag_in_guc(PG_FUNCTION_ARGS) { text *rule_query_tag = PG_GETARG_TEXT_P(0); char *rule_query_tag_cstr = text_to_cstring(rule_query_tag); - bool result = is_tag_in_guc_ctype(rule_query_tag_cstr, query_tag); - - List *tags; - bool aboba = SplitIdentifierString(rule_query_tag_cstr, ';', &tags); + List *rule_tags; + bool split_ok; + split_ok = split_tags(rule_query_tag_cstr, &rule_tags); + if (!split_ok) { + pfree(rule_query_tag_cstr); + return false; + } + bool result = is_tag_list_in_guc_list(rule_tags, parsed_query_tags); pfree(rule_query_tag_cstr); - - PG_RETURN_BOOL(result); + ListCell *rule_tag; + foreach(rule_tag, rule_tags) { + list_free(lfirst(rule_tag)); + } + list_free(rule_tags); + return true; } static Oid resgroup_assign_by_query_tag(void) { @@ -62,7 +74,7 @@ static Oid resgroup_assign_by_query_tag(void) { strcpy(query, "SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_tables WHERE " "tablename = 'wlm_rules')"); - elog(DEBUG3, "QUERY_TAG: Entered resgroup hook."); + elog(NOTICE, "QUERY_TAG: Entered resgroup hook."); int SPI_status; bool extension_created = false; @@ -80,15 +92,15 @@ static Oid resgroup_assign_by_query_tag(void) { } } if (!extension_created) { - elog(DEBUG3, "QUERY_TAG: Table wlm_rules doesn't exist, abort."); + elog(NOTICE, "QUERY_TAG: Table wlm_rules doesn't exist, abort."); SPI_finish(); return groupId; } - elog(DEBUG3, "QUERY_TAG: Table wlm_rules exists, continue."); + elog(NOTICE, "QUERY_TAG: Table wlm_rules exists, continue."); char *rgname = GetResGroupNameForId(groupId); char *rolename = GetUserNameFromId(GetUserId()); - elog(DEBUG3, "QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = %s and rolename = %s", + elog(NOTICE, "QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = %s and rolename = %s", rgname, rolename); int full_length = snprintf( query, sizeof(query), @@ -113,26 +125,34 @@ static Oid resgroup_assign_by_query_tag(void) { SPI_finish(); return groupId; } - elog(DEBUG3, "QUERY_TAG: set resgroup to: %s, %d", crgname, + elog(NOTICE, "QUERY_TAG: set resgroup to: %s, %d", crgname, GetResGroupIdForName(crgname)); SPI_finish(); return GetResGroupIdForName(crgname); } - elog(DEBUG3, "QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId."); + elog(NOTICE, "QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId."); SPI_finish(); return groupId; } static bool check_new_query_tag(char **newvalue, void **extra, GucSource source) { - elog(DEBUG3, "QUERY_TAG: Checking new tag"); + elog(NOTICE, "QUERY_TAG: Checking new tag"); if (strlen(*newvalue) >= MAX_QUERY_TAG_LENGTH) { - elog(DEBUG3, "QUERY_TAG: Tag too long, didn't set."); + elog(NOTICE, "QUERY_TAG: Tag too long, didn't set."); return false; } - if (!is_safe(*newvalue)) { + List *parsed_new_query_tag; + char *new_query_tag_mutable = pstrdup(*newvalue); + if (!split_tags(new_query_tag_mutable, &parsed_new_query_tag)) { + list_free(parsed_new_query_tag); + pfree(new_query_tag_mutable); return false; } - elog(DEBUG3, "QUERY_TAG: All okay, set new tag."); + pfree(query_tag_mutable); + query_tag_mutable = new_query_tag_mutable; + list_free(parsed_query_tags); + parsed_query_tags = parsed_new_query_tag; + elog(NOTICE, "QUERY_TAG: All okay, set new tag."); return true; } @@ -159,7 +179,7 @@ void _PG_init(void) { &query_tag, "", /* initial value */ PGC_USERSET, 0, /* flags */ - check_new_query_tag, /* check hook */ + check_new_query_tag, /* check hook */ NULL, /* assign hook */ NULL); /* show hook */ prev_hook = resgroup_assign_hook; From 24b55cbe2d7b6c045e138d62d8d5882093102245 Mon Sep 17 00:00:00 2001 From: lepip Date: Sun, 14 Jan 2024 19:00:57 +0000 Subject: [PATCH 4/9] Fixed memory leak --- src/query_tag.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/query_tag.c b/src/query_tag.c index fb1f53c..ad9c089 100644 --- a/src/query_tag.c +++ b/src/query_tag.c @@ -26,9 +26,9 @@ static bool check_new_query_tag(char **, void **, GucSource); void _PG_init(void); void _PG_fini(void); -static List *parsed_query_tags; +static List *parsed_query_tags = NIL; -static char *query_tag_mutable; +static char *query_tag_mutable = NULL; static char *query_tag = NULL; const static char *NO_GROUP_MSG = "unknown"; static const int MAX_QUERY_SIZE = 200; @@ -42,18 +42,22 @@ Datum is_tag_in_guc(PG_FUNCTION_ARGS) { List *rule_tags; bool split_ok; split_ok = split_tags(rule_query_tag_cstr, &rule_tags); + ListCell *rule_tag; if (!split_ok) { + foreach(rule_tag, rule_tags) { + list_free(lfirst(rule_tag)); + } + list_free(rule_tags); pfree(rule_query_tag_cstr); return false; } bool result = is_tag_list_in_guc_list(rule_tags, parsed_query_tags); pfree(rule_query_tag_cstr); - ListCell *rule_tag; foreach(rule_tag, rule_tags) { list_free(lfirst(rule_tag)); } list_free(rule_tags); - return true; + return result; } static Oid resgroup_assign_by_query_tag(void) { From 73b3e9573afa26d74652daf363c7791fc8b847af Mon Sep 17 00:00:00 2001 From: lepip Date: Thu, 18 Jan 2024 14:40:21 +0000 Subject: [PATCH 5/9] WIP new parser. There is a log in results folder of executing on test/sql/query_tag.sql. Main problem: is_tag_in_guc is running on seg0. --- Makefile | 2 +- results/query_tag.out | 574 +++++++++++++++++++++++++++++++++++++++++ sql/query_tag--1.0.sql | 4 +- src/parser.c | 91 +++++-- src/parser.h | 11 +- src/query_tag.c | 84 +++--- 6 files changed, 710 insertions(+), 56 deletions(-) create mode 100644 results/query_tag.out diff --git a/Makefile b/Makefile index b4e41f3..eac36e1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # It doesn't use CFLAGS in compiling, it uses some postgres magic instead :( -CFLAGS := ${CFLAGS} -Wall -Werror +override CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-unused-but-set-variable -Wno-address -Wno-format-truncation -Wno-stringop-truncation -g -ggdb -std=gnu99 -Werror=uninitialized -Werror=implicit-function-declaration -DGPBUILD EXTENSION = query_tag EXTVERSION = $(shell grep default_version $(EXTENSION).control | \ diff --git a/results/query_tag.out b/results/query_tag.out new file mode 100644 index 0000000..c7b1554 --- /dev/null +++ b/results/query_tag.out @@ -0,0 +1,574 @@ +CREATE EXTENSION query_tag; +NOTICE: QUERY_TAG: Table wlm_rules doesn't exist, abort. +SET QUERY_TAG TO "aboba=aboba"; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Checking new tag +NOTICE: QUERY_TAG: Free old one: 2135397528 +NOTICE: FREED: 2135397528 +NOTICE: QUERY_TAG: Setup new one: 2137724040 +NOTICE: Printing tags: +NOTICE: 0: aboba +NOTICE: 1: aboba +NOTICE: heh, 1 +NOTICE: heh, 2 (seg0 127.0.1.1:6002 pid=779316) +NOTICE: heh, 2 (seg1 127.0.1.1:6003 pid=779317) +NOTICE: heh, 2 (seg2 127.0.1.1:6004 pid=779318) +-- weird query_tags +SET QUERY_TAG TO "a"; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Checking new tag +NOTICE: QUERY_TAG: Tag didn't pass parsing. +ERROR: invalid value for parameter "QUERY_TAG": "a" +SHOW QUERY_TAG; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: Printing tags: +NOTICE: 0: aboba +NOTICE: 1: aboba +NOTICE: Printing tags: +NOTICE: 0: aboba +NOTICE: 1: aboba + QUERY_TAG +------------- + aboba=aboba +(1 row) + +SET QUERY_TAG TO "=aboba"; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Checking new tag +NOTICE: QUERY_TAG: Tag didn't pass parsing. +ERROR: invalid value for parameter "QUERY_TAG": "=aboba" +SHOW QUERY_TAG; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: Printing tags: +NOTICE: 0: aboba +NOTICE: 1: aboba +NOTICE: Printing tags: +NOTICE: 0: aboba +NOTICE: 1: aboba + QUERY_TAG +------------- + aboba=aboba +(1 row) + +SET QUERY_TAG TO "a=a;"; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Checking new tag +NOTICE: QUERY_TAG: Tag didn't pass parsing. +ERROR: invalid value for parameter "QUERY_TAG": "a=a;" +SHOW QUERY_TAG; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: Printing tags: +NOTICE: 0: aboba +NOTICE: 1: aboba +NOTICE: Printing tags: +NOTICE: 0: aboba +NOTICE: 1: aboba + QUERY_TAG +------------- + aboba=aboba +(1 row) + +SET QUERY_TAG TO "a;"; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Checking new tag +NOTICE: QUERY_TAG: Tag didn't pass parsing. +ERROR: invalid value for parameter "QUERY_TAG": "a;" +SHOW QUERY_TAG; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: Printing tags: +NOTICE: 0: aboba +NOTICE: 1: aboba +NOTICE: Printing tags: +NOTICE: 0: aboba +NOTICE: 1: aboba + QUERY_TAG +------------- + aboba=aboba +(1 row) + +SET QUERY_TAG TO "123=123"; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Checking new tag +NOTICE: QUERY_TAG: Free old one: 2137724040 +NOTICE: FREED: 2137724040 +NOTICE: QUERY_TAG: Setup new one: 2135397528 +NOTICE: Printing tags: +NOTICE: 0: 123 +NOTICE: 1: 123 +NOTICE: heh, 1 +NOTICE: heh, 2 (seg0 127.0.1.1:6002 pid=779316) +NOTICE: heh, 2 (seg1 127.0.1.1:6003 pid=779317) +NOTICE: heh, 2 (seg2 127.0.1.1:6004 pid=779318) +SHOW QUERY_TAG; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: Printing tags: +NOTICE: 0: 123 +NOTICE: 1: 123 +NOTICE: Printing tags: +NOTICE: 0: 123 +NOTICE: 1: 123 + QUERY_TAG +----------- + 123=123 +(1 row) + +SET QUERY_TAG TO ";"; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Checking new tag +NOTICE: QUERY_TAG: Tag didn't pass parsing. +ERROR: invalid value for parameter "QUERY_TAG": ";" +SHOW QUERY_TAG; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: Printing tags: +NOTICE: 0: 123 +NOTICE: 1: 123 +NOTICE: Printing tags: +NOTICE: 0: 123 +NOTICE: 1: 123 + QUERY_TAG +----------- + 123=123 +(1 row) + +-- complex behaviour +-- should set to rgroup1 +CREATE RESOURCE GROUP rgroup1 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +ERROR: resource group "rgroup1" already exists +CREATE RESOURCE GROUP rgroup2 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +ERROR: resource group "rgroup2" already exists +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1', TRUE); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup2', 4, 'group=rgroup1', TRUE); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +SET QUERY_TAG TO "group=rgroup1"; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Checking new tag +NOTICE: QUERY_TAG: Free old one: 2135397528 +NOTICE: FREED: 2135397528 +NOTICE: QUERY_TAG: Setup new one: 2137732168 +NOTICE: Printing tags: +NOTICE: 0: group +NOTICE: 1: rgroup1 +NOTICE: heh, 1 +NOTICE: heh, 2 (seg0 127.0.1.1:6002 pid=779316) +NOTICE: heh, 2 (seg2 127.0.1.1:6004 pid=779318) +NOTICE: heh, 2 (seg1 127.0.1.1:6003 pid=779317) +SELECT current_resgroup(); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. + current_resgroup +------------------ + admin_group +(1 row) + +-- should still set to rgroup1 (we are in admin_group, the "current_rsgroup" shows group after +--- applying tags, and tags are applied accordingly to users rsgroup) +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('rgroup1', 'clepip', 'rgroup2', 1, 'group=still_1', TRUE); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup1', 5, 'group=still_1', TRUE); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +SET QUERY_TAG TO "group=still_1"; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Checking new tag +NOTICE: QUERY_TAG: Free old one: 2137732168 +NOTICE: FREED: 2137732168 +NOTICE: QUERY_TAG: Setup new one: 2135397528 +NOTICE: Printing tags: +NOTICE: 0: group +NOTICE: 1: still_1 +NOTICE: heh, 1 +NOTICE: heh, 2 (seg0 127.0.1.1:6002 pid=779316) +NOTICE: heh, 2 (seg2 127.0.1.1:6004 pid=779318) +NOTICE: heh, 2 (seg1 127.0.1.1:6003 pid=779317) +SELECT CURRENT_RESGROUP(); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. + current_resgroup +------------------ + admin_group +(1 row) + +-- should set to rgroup1 +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup2', 1, 'group=cancelled', FALSE); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) + VALUES ('admin_group', 'clepip', 'rgroup1', 2, 'group=cancelled', TRUE); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +SET QUERY_TAG TO "group=cancelled"; +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: cancelled (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. +NOTICE: QUERY_TAG: Checking new tag +NOTICE: QUERY_TAG: Free old one: 2135397528 +NOTICE: FREED: 2135397528 +NOTICE: QUERY_TAG: Setup new one: 2137732168 +NOTICE: Printing tags: +NOTICE: 0: group +NOTICE: 1: cancelled +NOTICE: heh, 1 +NOTICE: heh, 2 (seg0 127.0.1.1:6002 pid=779316) +NOTICE: heh, 2 (seg2 127.0.1.1:6004 pid=779318) +NOTICE: heh, 2 (seg1 127.0.1.1:6003 pid=779317) +SELECT CURRENT_RESGROUP(); +NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: 1: cancelled (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) +NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. + current_resgroup +------------------ + admin_group +(1 row) + diff --git a/sql/query_tag--1.0.sql b/sql/query_tag--1.0.sql index f5e874b..9ab1f8e 100644 --- a/sql/query_tag--1.0.sql +++ b/sql/query_tag--1.0.sql @@ -6,10 +6,10 @@ CREATE FUNCTION CURRENT_RESGROUP() RETURNS text AS 'query_tag', 'current_resgroup' LANGUAGE C STRICT VOLATILE; -CREATE OR REPLACE FUNCTION is_tag_in_guc(query_tag text) +CREATE FUNCTION is_tag_in_guc(query_tag text) RETURNS boolean AS 'query_tag', 'is_tag_in_guc' - LANGUAGE C STRICT VOLATILE; + LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; CREATE TABLE wlm_rules ( serial_number integer, diff --git a/src/parser.c b/src/parser.c index c68d8c3..831decb 100644 --- a/src/parser.c +++ b/src/parser.c @@ -4,37 +4,68 @@ #include "utils/builtins.h" #include "c.h" #include +#include "utils/memutils.h" +static void free_double_list(List **double_list) { + ListCell *current_cell; + foreach(current_cell, *double_list) { + list_free(lfirst(current_cell)); + } + list_free(*double_list); + *double_list = NIL; +} -bool split_tags(char *tags, List **splitted) { - List *tags_list = NIL; - bool ok = SplitIdentifierString(tags, ';', &tags_list); +bool split_tags(const char *tags, ParsedTags **parced) { + MemoryContext oldctx = MemoryContextSwitchTo(TopMemoryContext); + *parced = palloc(sizeof(**parced)); + if (!tags) { + elog(ERROR, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAmoGUS"); + } + char *tags_mutable = pstrdup(tags); + List *almost_parced_tags = NIL; + bool ok = SplitIdentifierString(tags_mutable, ';', &almost_parced_tags); if (!ok) { - list_free(tags_list); + pfree(*parced); + *parced = NULL; + pfree(tags_mutable); + list_free(almost_parced_tags); + MemoryContextSwitchTo(oldctx); return false; } ListCell *current_tag; - list_free(*splitted); - *splitted = NIL; - foreach(current_tag, tags_list) { - List *parsed_tags; - ok = SplitIdentifierString(lfirst(current_tag), '=', &parsed_tags); - if (!ok || list_length(parsed_tags) != 2) { - list_free(tags_list); - list_free(parsed_tags); + List *parced_tags = NIL; + foreach(current_tag, almost_parced_tags) { + List *parsed_current_tag = NIL; + ok = SplitIdentifierString(lfirst(current_tag), '=', &parsed_current_tag); + if (!ok || list_length(parsed_current_tag) != 2) { + list_free(parsed_current_tag); + free_double_list(&parced_tags); + pfree(*parced); + *parced = NULL; + pfree(tags_mutable); + list_free(almost_parced_tags); + MemoryContextSwitchTo(oldctx); return false; } - *splitted = lappend(*splitted, parsed_tags); + parced_tags = lappend(parced_tags, parsed_current_tag); } + + (*parced)->tags_mutable = tags_mutable; + (*parced)->parsed_tags = parced_tags; + MemoryContextSwitchTo(oldctx); return true; } -bool is_tag_list_in_guc_list(List *rule_tags, List *guc_tags) { +bool is_parsed_rule_in_parsed_guc(ParsedTags *rule_tags, ParsedTags *guc_tags) { + elog(NOTICE, "Printing guc:"); + print_parsed_tags(guc_tags); + elog(NOTICE, "Printing rule:"); + print_parsed_tags(rule_tags); ListCell *guc_cell, *tag_cell; - foreach (tag_cell, rule_tags) { + foreach (tag_cell, rule_tags->parsed_tags) { List *tag_pair = lfirst(tag_cell); bool found = false; - foreach (guc_cell, guc_tags) { + foreach (guc_cell, guc_tags->parsed_tags) { List *guc_pair = lfirst(guc_cell); if (strcmp(linitial(guc_pair), linitial(tag_pair)) == 0 && strcmp(lsecond(guc_pair), lsecond(tag_pair)) == 0) { @@ -48,3 +79,31 @@ bool is_tag_list_in_guc_list(List *rule_tags, List *guc_tags) { } return true; } + +void free_parsed_tags(ParsedTags **parced) { + if (*parced) { + free_double_list(&(*parced)->parsed_tags); + if ((*parced)->tags_mutable) + pfree((*parced)->tags_mutable); + elog(NOTICE, "FREED: %d", (int)*parced); + pfree(*parced); + *parced = NULL; + } +} + +void print_parsed_tags(ParsedTags *parsed) { + elog(NOTICE, "Printing tags:"); + ListCell *current_cell; + ListCell *current_tag; + int id = 0; + if (parsed) { + foreach(current_cell, parsed->parsed_tags) { + foreach(current_tag, lfirst(current_cell)) { + elog(NOTICE, "%d: %s", id, lfirst(current_tag)); + id++; + } + } + } else { + elog(NOTICE, "Null, lol"); + } +} \ No newline at end of file diff --git a/src/parser.h b/src/parser.h index 96cf863..5d2157b 100644 --- a/src/parser.h +++ b/src/parser.h @@ -1,4 +1,11 @@ #include "nodes/pg_list.h" -bool split_tags(char *tags, List **splitted); -bool is_tag_list_in_guc_list(List *rule_tags, List *guc_tags); \ No newline at end of file +typedef struct ParsedTags { + char *tags_mutable; + List *parsed_tags; +} ParsedTags; + +bool split_tags(const char *tags, ParsedTags **parced); +bool is_parsed_rule_in_parsed_guc(ParsedTags *parced_rule, ParsedTags *parced_guc); +void free_parsed_tags(ParsedTags **parced); +void print_parsed_tags(ParsedTags *parsed); diff --git a/src/query_tag.c b/src/query_tag.c index ad9c089..befe9ba 100644 --- a/src/query_tag.c +++ b/src/query_tag.c @@ -13,6 +13,7 @@ #include "parser.h" #include "utils/syscache.h" #include "catalog/pg_authid.h" +#include "cdb/cdbvars.h" PG_MODULE_MAGIC; @@ -26,9 +27,7 @@ static bool check_new_query_tag(char **, void **, GucSource); void _PG_init(void); void _PG_fini(void); -static List *parsed_query_tags = NIL; - -static char *query_tag_mutable = NULL; +static ParsedTags *parsed_guc_tags; static char *query_tag = NULL; const static char *NO_GROUP_MSG = "unknown"; static const int MAX_QUERY_SIZE = 200; @@ -37,31 +36,25 @@ static const int MAX_QUERY_TAG_LENGTH = 100; static resgroup_assign_hook_type prev_hook = NULL; Datum is_tag_in_guc(PG_FUNCTION_ARGS) { + elog(NOTICE, "Printing gucs in istaginguc"); + print_parsed_tags(parsed_guc_tags); text *rule_query_tag = PG_GETARG_TEXT_P(0); char *rule_query_tag_cstr = text_to_cstring(rule_query_tag); - List *rule_tags; - bool split_ok; - split_ok = split_tags(rule_query_tag_cstr, &rule_tags); - ListCell *rule_tag; - if (!split_ok) { - foreach(rule_tag, rule_tags) { - list_free(lfirst(rule_tag)); - } - list_free(rule_tags); - pfree(rule_query_tag_cstr); - return false; + if (!rule_query_tag_cstr) { + PG_RETURN_BOOL(false); } - bool result = is_tag_list_in_guc_list(rule_tags, parsed_query_tags); - pfree(rule_query_tag_cstr); - foreach(rule_tag, rule_tags) { - list_free(lfirst(rule_tag)); + ParsedTags *parsed_rule_tags = NULL; + bool ok = split_tags(rule_query_tag_cstr, &parsed_rule_tags); + if (!ok) { + pfree(rule_query_tag_cstr); + PG_RETURN_BOOL(false); } - list_free(rule_tags); - return result; + bool result = is_parsed_rule_in_parsed_guc(parsed_rule_tags, parsed_guc_tags); + free_parsed_tags(&parsed_rule_tags); + PG_RETURN_BOOL(result); } static Oid resgroup_assign_by_query_tag(void) { - Oid groupId = InvalidOid; if (prev_hook) groupId = prev_hook(); @@ -78,7 +71,7 @@ static Oid resgroup_assign_by_query_tag(void) { strcpy(query, "SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_tables WHERE " "tablename = 'wlm_rules')"); - elog(NOTICE, "QUERY_TAG: Entered resgroup hook."); + elog(DEBUG3, "QUERY_TAG: Entered resgroup hook."); int SPI_status; bool extension_created = false; @@ -100,7 +93,7 @@ static Oid resgroup_assign_by_query_tag(void) { SPI_finish(); return groupId; } - elog(NOTICE, "QUERY_TAG: Table wlm_rules exists, continue."); + elog(DEBUG3, "QUERY_TAG: Table wlm_rules exists, continue."); char *rgname = GetResGroupNameForId(groupId); char *rolename = GetUserNameFromId(GetUserId()); @@ -140,26 +133,42 @@ static Oid resgroup_assign_by_query_tag(void) { } static bool check_new_query_tag(char **newvalue, void **extra, GucSource source) { + if (Gp_role != GP_ROLE_DISPATCH) { + return true; + } + if (!*newvalue) { + return true; + } + if (query_tag && (strcmp(*newvalue, query_tag) == 0)) { + elog(NOTICE, "QUERY_TAG: Dolboeb blyat"); + return true; + } elog(NOTICE, "QUERY_TAG: Checking new tag"); if (strlen(*newvalue) >= MAX_QUERY_TAG_LENGTH) { elog(NOTICE, "QUERY_TAG: Tag too long, didn't set."); return false; } - List *parsed_new_query_tag; - char *new_query_tag_mutable = pstrdup(*newvalue); - if (!split_tags(new_query_tag_mutable, &parsed_new_query_tag)) { - list_free(parsed_new_query_tag); - pfree(new_query_tag_mutable); + ParsedTags *new_parsed_guc_tag = NULL; + bool ok = split_tags(*newvalue, &new_parsed_guc_tag); + if (!ok) { + elog(NOTICE, "QUERY_TAG: Tag didn't pass parsing."); return false; } - pfree(query_tag_mutable); - query_tag_mutable = new_query_tag_mutable; - list_free(parsed_query_tags); - parsed_query_tags = parsed_new_query_tag; - elog(NOTICE, "QUERY_TAG: All okay, set new tag."); + if (parsed_guc_tags == new_parsed_guc_tag) { + return true; + } + elog(NOTICE, "QUERY_TAG: Free old one: %d", parsed_guc_tags); + free_parsed_tags(&parsed_guc_tags); + elog(NOTICE, "QUERY_TAG: Setup new one: %d", new_parsed_guc_tag); + parsed_guc_tags = new_parsed_guc_tag; + print_parsed_tags(parsed_guc_tags); return true; } +static void assign_query_tag(const char *newvalue, void *extra) { + elog(NOTICE, "heh, %d", (int)Gp_role); +} + static Oid current_resgroup_id() { Oid group_id = ResGroupGetGroupIdBySessionId(MySessionState->sessionId); return group_id; @@ -175,6 +184,11 @@ Datum current_resgroup(PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P(cstring_to_text(resgroup_name)); } +static const char *show_query_tag(void) { + print_parsed_tags(parsed_guc_tags); + return query_tag; +} + void _PG_init(void) { DefineCustomStringVariable( "QUERY_TAG", @@ -184,8 +198,8 @@ void _PG_init(void) { "", /* initial value */ PGC_USERSET, 0, /* flags */ check_new_query_tag, /* check hook */ - NULL, /* assign hook */ - NULL); /* show hook */ + assign_query_tag, /* assign hook */ + show_query_tag); /* show hook */ prev_hook = resgroup_assign_hook; resgroup_assign_hook = resgroup_assign_by_query_tag; } From bf7f3c6f99ea560651f7afde75c14fb4db573f19 Mon Sep 17 00:00:00 2001 From: lepip Date: Tue, 30 Jan 2024 16:06:14 +0000 Subject: [PATCH 6/9] Fixed the memory issues and changed the parser --- results/query_tag.out | 574 ------------------------------------ sql/query_tag--1.0.sql | 2 +- src/parser.c | 14 +- src/query_tag.c | 52 +++- test/expected/query_tag.out | 15 +- 5 files changed, 51 insertions(+), 606 deletions(-) delete mode 100644 results/query_tag.out diff --git a/results/query_tag.out b/results/query_tag.out deleted file mode 100644 index c7b1554..0000000 --- a/results/query_tag.out +++ /dev/null @@ -1,574 +0,0 @@ -CREATE EXTENSION query_tag; -NOTICE: QUERY_TAG: Table wlm_rules doesn't exist, abort. -SET QUERY_TAG TO "aboba=aboba"; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Checking new tag -NOTICE: QUERY_TAG: Free old one: 2135397528 -NOTICE: FREED: 2135397528 -NOTICE: QUERY_TAG: Setup new one: 2137724040 -NOTICE: Printing tags: -NOTICE: 0: aboba -NOTICE: 1: aboba -NOTICE: heh, 1 -NOTICE: heh, 2 (seg0 127.0.1.1:6002 pid=779316) -NOTICE: heh, 2 (seg1 127.0.1.1:6003 pid=779317) -NOTICE: heh, 2 (seg2 127.0.1.1:6004 pid=779318) --- weird query_tags -SET QUERY_TAG TO "a"; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Checking new tag -NOTICE: QUERY_TAG: Tag didn't pass parsing. -ERROR: invalid value for parameter "QUERY_TAG": "a" -SHOW QUERY_TAG; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: Printing tags: -NOTICE: 0: aboba -NOTICE: 1: aboba -NOTICE: Printing tags: -NOTICE: 0: aboba -NOTICE: 1: aboba - QUERY_TAG -------------- - aboba=aboba -(1 row) - -SET QUERY_TAG TO "=aboba"; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Checking new tag -NOTICE: QUERY_TAG: Tag didn't pass parsing. -ERROR: invalid value for parameter "QUERY_TAG": "=aboba" -SHOW QUERY_TAG; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: Printing tags: -NOTICE: 0: aboba -NOTICE: 1: aboba -NOTICE: Printing tags: -NOTICE: 0: aboba -NOTICE: 1: aboba - QUERY_TAG -------------- - aboba=aboba -(1 row) - -SET QUERY_TAG TO "a=a;"; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Checking new tag -NOTICE: QUERY_TAG: Tag didn't pass parsing. -ERROR: invalid value for parameter "QUERY_TAG": "a=a;" -SHOW QUERY_TAG; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: Printing tags: -NOTICE: 0: aboba -NOTICE: 1: aboba -NOTICE: Printing tags: -NOTICE: 0: aboba -NOTICE: 1: aboba - QUERY_TAG -------------- - aboba=aboba -(1 row) - -SET QUERY_TAG TO "a;"; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Checking new tag -NOTICE: QUERY_TAG: Tag didn't pass parsing. -ERROR: invalid value for parameter "QUERY_TAG": "a;" -SHOW QUERY_TAG; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: Printing tags: -NOTICE: 0: aboba -NOTICE: 1: aboba -NOTICE: Printing tags: -NOTICE: 0: aboba -NOTICE: 1: aboba - QUERY_TAG -------------- - aboba=aboba -(1 row) - -SET QUERY_TAG TO "123=123"; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Checking new tag -NOTICE: QUERY_TAG: Free old one: 2137724040 -NOTICE: FREED: 2137724040 -NOTICE: QUERY_TAG: Setup new one: 2135397528 -NOTICE: Printing tags: -NOTICE: 0: 123 -NOTICE: 1: 123 -NOTICE: heh, 1 -NOTICE: heh, 2 (seg0 127.0.1.1:6002 pid=779316) -NOTICE: heh, 2 (seg1 127.0.1.1:6003 pid=779317) -NOTICE: heh, 2 (seg2 127.0.1.1:6004 pid=779318) -SHOW QUERY_TAG; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: Printing tags: -NOTICE: 0: 123 -NOTICE: 1: 123 -NOTICE: Printing tags: -NOTICE: 0: 123 -NOTICE: 1: 123 - QUERY_TAG ------------ - 123=123 -(1 row) - -SET QUERY_TAG TO ";"; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Checking new tag -NOTICE: QUERY_TAG: Tag didn't pass parsing. -ERROR: invalid value for parameter "QUERY_TAG": ";" -SHOW QUERY_TAG; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: Printing tags: -NOTICE: 0: 123 -NOTICE: 1: 123 -NOTICE: Printing tags: -NOTICE: 0: 123 -NOTICE: 1: 123 - QUERY_TAG ------------ - 123=123 -(1 row) - --- complex behaviour --- should set to rgroup1 -CREATE RESOURCE GROUP rgroup1 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -ERROR: resource group "rgroup1" already exists -CREATE RESOURCE GROUP rgroup2 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -ERROR: resource group "rgroup2" already exists -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1', TRUE); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup2', 4, 'group=rgroup1', TRUE); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -SET QUERY_TAG TO "group=rgroup1"; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Checking new tag -NOTICE: QUERY_TAG: Free old one: 2135397528 -NOTICE: FREED: 2135397528 -NOTICE: QUERY_TAG: Setup new one: 2137732168 -NOTICE: Printing tags: -NOTICE: 0: group -NOTICE: 1: rgroup1 -NOTICE: heh, 1 -NOTICE: heh, 2 (seg0 127.0.1.1:6002 pid=779316) -NOTICE: heh, 2 (seg2 127.0.1.1:6004 pid=779318) -NOTICE: heh, 2 (seg1 127.0.1.1:6003 pid=779317) -SELECT current_resgroup(); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. - current_resgroup ------------------- - admin_group -(1 row) - --- should still set to rgroup1 (we are in admin_group, the "current_rsgroup" shows group after ---- applying tags, and tags are applied accordingly to users rsgroup) -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('rgroup1', 'clepip', 'rgroup2', 1, 'group=still_1', TRUE); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup1', 5, 'group=still_1', TRUE); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -SET QUERY_TAG TO "group=still_1"; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Checking new tag -NOTICE: QUERY_TAG: Free old one: 2137732168 -NOTICE: FREED: 2137732168 -NOTICE: QUERY_TAG: Setup new one: 2135397528 -NOTICE: Printing tags: -NOTICE: 0: group -NOTICE: 1: still_1 -NOTICE: heh, 1 -NOTICE: heh, 2 (seg0 127.0.1.1:6002 pid=779316) -NOTICE: heh, 2 (seg2 127.0.1.1:6004 pid=779318) -NOTICE: heh, 2 (seg1 127.0.1.1:6003 pid=779317) -SELECT CURRENT_RESGROUP(); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. - current_resgroup ------------------- - admin_group -(1 row) - --- should set to rgroup1 -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup2', 1, 'group=cancelled', FALSE); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup1', 2, 'group=cancelled', TRUE); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -SET QUERY_TAG TO "group=cancelled"; -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: cancelled (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. -NOTICE: QUERY_TAG: Checking new tag -NOTICE: QUERY_TAG: Free old one: 2135397528 -NOTICE: FREED: 2135397528 -NOTICE: QUERY_TAG: Setup new one: 2137732168 -NOTICE: Printing tags: -NOTICE: 0: group -NOTICE: 1: cancelled -NOTICE: heh, 1 -NOTICE: heh, 2 (seg0 127.0.1.1:6002 pid=779316) -NOTICE: heh, 2 (seg2 127.0.1.1:6004 pid=779318) -NOTICE: heh, 2 (seg1 127.0.1.1:6003 pid=779317) -SELECT CURRENT_RESGROUP(); -NOTICE: QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = admin_group and rolename = clepip -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: rgroup1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: still_1 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing gucs in istaginguc (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing guc: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing rule: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: Printing tags: (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 0: group (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: 1: cancelled (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: FREED: -2091468360 (seg0 slice1 127.0.1.1:6002 pid=779316) -NOTICE: QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId. - current_resgroup ------------------- - admin_group -(1 row) - diff --git a/sql/query_tag--1.0.sql b/sql/query_tag--1.0.sql index 9ab1f8e..ad5d9b2 100644 --- a/sql/query_tag--1.0.sql +++ b/sql/query_tag--1.0.sql @@ -6,7 +6,7 @@ CREATE FUNCTION CURRENT_RESGROUP() RETURNS text AS 'query_tag', 'current_resgroup' LANGUAGE C STRICT VOLATILE; -CREATE FUNCTION is_tag_in_guc(query_tag text) +CREATE FUNCTION is_tag_in_guc(text) RETURNS boolean AS 'query_tag', 'is_tag_in_guc' LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; diff --git a/src/parser.c b/src/parser.c index 831decb..b9c234b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -19,7 +19,7 @@ bool split_tags(const char *tags, ParsedTags **parced) { MemoryContext oldctx = MemoryContextSwitchTo(TopMemoryContext); *parced = palloc(sizeof(**parced)); if (!tags) { - elog(ERROR, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAmoGUS"); + elog(ERROR, "QUERY_TAG: there's a NULL query_tag somewhere."); } char *tags_mutable = pstrdup(tags); List *almost_parced_tags = NIL; @@ -57,9 +57,9 @@ bool split_tags(const char *tags, ParsedTags **parced) { } bool is_parsed_rule_in_parsed_guc(ParsedTags *rule_tags, ParsedTags *guc_tags) { - elog(NOTICE, "Printing guc:"); + elog(DEBUG4, "Printing guc:"); print_parsed_tags(guc_tags); - elog(NOTICE, "Printing rule:"); + elog(DEBUG4, "Printing rule:"); print_parsed_tags(rule_tags); ListCell *guc_cell, *tag_cell; foreach (tag_cell, rule_tags->parsed_tags) { @@ -85,25 +85,25 @@ void free_parsed_tags(ParsedTags **parced) { free_double_list(&(*parced)->parsed_tags); if ((*parced)->tags_mutable) pfree((*parced)->tags_mutable); - elog(NOTICE, "FREED: %d", (int)*parced); + elog(DEBUG4, "FREED: %d", (int)*parced); pfree(*parced); *parced = NULL; } } void print_parsed_tags(ParsedTags *parsed) { - elog(NOTICE, "Printing tags:"); + elog(DEBUG4, "Printing tags:"); ListCell *current_cell; ListCell *current_tag; int id = 0; if (parsed) { foreach(current_cell, parsed->parsed_tags) { foreach(current_tag, lfirst(current_cell)) { - elog(NOTICE, "%d: %s", id, lfirst(current_tag)); + elog(DEBUG4, "%d: %s", id, lfirst(current_tag)); id++; } } } else { - elog(NOTICE, "Null, lol"); + elog(DEBUG4, "Null, lol"); } } \ No newline at end of file diff --git a/src/query_tag.c b/src/query_tag.c index befe9ba..34cc8b7 100644 --- a/src/query_tag.c +++ b/src/query_tag.c @@ -36,7 +36,7 @@ static const int MAX_QUERY_TAG_LENGTH = 100; static resgroup_assign_hook_type prev_hook = NULL; Datum is_tag_in_guc(PG_FUNCTION_ARGS) { - elog(NOTICE, "Printing gucs in istaginguc"); + elog(DEBUG4, "Printing gucs in istaginguc"); print_parsed_tags(parsed_guc_tags); text *rule_query_tag = PG_GETARG_TEXT_P(0); char *rule_query_tag_cstr = text_to_cstring(rule_query_tag); @@ -89,7 +89,7 @@ static Oid resgroup_assign_by_query_tag(void) { } } if (!extension_created) { - elog(NOTICE, "QUERY_TAG: Table wlm_rules doesn't exist, abort."); + elog(DEBUG3, "QUERY_TAG: Table wlm_rules doesn't exist, abort."); SPI_finish(); return groupId; } @@ -97,7 +97,7 @@ static Oid resgroup_assign_by_query_tag(void) { char *rgname = GetResGroupNameForId(groupId); char *rolename = GetUserNameFromId(GetUserId()); - elog(NOTICE, "QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = %s and rolename = %s", + elog(DEBUG3, "QUERY_TAG: Trying to fetch rules from wlm_rules, where resgname = %s and rolename = %s", rgname, rolename); int full_length = snprintf( query, sizeof(query), @@ -122,51 +122,71 @@ static Oid resgroup_assign_by_query_tag(void) { SPI_finish(); return groupId; } - elog(NOTICE, "QUERY_TAG: set resgroup to: %s, %d", crgname, + elog(DEBUG1, "QUERY_TAG: set resgroup to: %s, %d", crgname, GetResGroupIdForName(crgname)); SPI_finish(); return GetResGroupIdForName(crgname); } - elog(NOTICE, "QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId."); + elog(DEBUG3, "QUERY_TAG: didn't find matching rules for the current query. Keeping original groupId."); SPI_finish(); return groupId; } static bool check_new_query_tag(char **newvalue, void **extra, GucSource source) { - if (Gp_role != GP_ROLE_DISPATCH) { - return true; - } if (!*newvalue) { + free_parsed_tags(&parsed_guc_tags); + parsed_guc_tags = NULL; return true; } if (query_tag && (strcmp(*newvalue, query_tag) == 0)) { - elog(NOTICE, "QUERY_TAG: Dolboeb blyat"); return true; } - elog(NOTICE, "QUERY_TAG: Checking new tag"); + elog(DEBUG3, "QUERY_TAG: Checking new tag"); if (strlen(*newvalue) >= MAX_QUERY_TAG_LENGTH) { - elog(NOTICE, "QUERY_TAG: Tag too long, didn't set."); + elog(DEBUG3, "QUERY_TAG: Tag too long, didn't set."); return false; } ParsedTags *new_parsed_guc_tag = NULL; bool ok = split_tags(*newvalue, &new_parsed_guc_tag); if (!ok) { - elog(NOTICE, "QUERY_TAG: Tag didn't pass parsing."); + elog(DEBUG3, "QUERY_TAG: Tag didn't pass parsing."); return false; } if (parsed_guc_tags == new_parsed_guc_tag) { + elog(DEBUG3, "Why... (This like shouldn't ever occur), %d", (int)parsed_guc_tags); return true; } - elog(NOTICE, "QUERY_TAG: Free old one: %d", parsed_guc_tags); - free_parsed_tags(&parsed_guc_tags); - elog(NOTICE, "QUERY_TAG: Setup new one: %d", new_parsed_guc_tag); + elog(DEBUG3, "QUERY_TAG: Free old one: %d", parsed_guc_tags); + if (parsed_guc_tags) { + free_parsed_tags(&parsed_guc_tags); + parsed_guc_tags = NULL; + } + elog(DEBUG3, "QUERY_TAG: Setup new one: %d", new_parsed_guc_tag); parsed_guc_tags = new_parsed_guc_tag; print_parsed_tags(parsed_guc_tags); return true; } +int *stuff = NULL; + static void assign_query_tag(const char *newvalue, void *extra) { - elog(NOTICE, "heh, %d", (int)Gp_role); + /*elog(NOTICE, "heh, %d", (int)Gp_role); + MemoryContext old_context = MemoryContextSwitchTo(TopMemoryContext); + elog(NOTICE, "stuff: %d", (int)stuff); + if (stuff) { + elog(NOTICE, "stuff value: %d", *stuff); + } else { + elog(NOTICE, "stuff value: NULL"); + } + int *old_stuff = stuff; + stuff = palloc(sizeof(*stuff)); + *stuff = (int)stuff; + elog(NOTICE, "new_stuff: %d", (int)stuff); + elog(NOTICE, "new_stuff value: %d", *stuff); + if (old_stuff != stuff && old_stuff != NULL) { + pfree(old_stuff); + } + MemoryContextSwitchTo(old_context);*/ } static Oid current_resgroup_id() { diff --git a/test/expected/query_tag.out b/test/expected/query_tag.out index 775aebe..ba179db 100644 --- a/test/expected/query_tag.out +++ b/test/expected/query_tag.out @@ -18,18 +18,19 @@ SHOW QUERY_TAG; (1 row) SET QUERY_TAG TO "a=a;"; +ERROR: invalid value for parameter "QUERY_TAG": "a=a;" SHOW QUERY_TAG; - QUERY_TAG ------------ - a=a; + QUERY_TAG +------------- + aboba=aboba (1 row) SET QUERY_TAG TO "a;"; ERROR: invalid value for parameter "QUERY_TAG": "a;" SHOW QUERY_TAG; - QUERY_TAG ------------ - a=a; + QUERY_TAG +------------- + aboba=aboba (1 row) SET QUERY_TAG TO "123=123"; @@ -50,9 +51,7 @@ SHOW QUERY_TAG; -- complex behaviour -- should set to rgroup1 CREATE RESOURCE GROUP rgroup1 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); -ERROR: resource group "rgroup1" already exists CREATE RESOURCE GROUP rgroup2 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); -ERROR: resource group "rgroup2" already exists INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1', TRUE); INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) From b897f11f97d7c7aeb288d63eb14b1985751473c2 Mon Sep 17 00:00:00 2001 From: lepip Date: Tue, 30 Jan 2024 16:10:09 +0000 Subject: [PATCH 7/9] Removed minor legacy. --- sql/query_tag--1.0.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/query_tag--1.0.sql b/sql/query_tag--1.0.sql index ad5d9b2..3e6f5cd 100644 --- a/sql/query_tag--1.0.sql +++ b/sql/query_tag--1.0.sql @@ -9,7 +9,7 @@ CREATE FUNCTION CURRENT_RESGROUP() RETURNS text CREATE FUNCTION is_tag_in_guc(text) RETURNS boolean AS 'query_tag', 'is_tag_in_guc' - LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; + LANGUAGE C STRICT VOLATILE; CREATE TABLE wlm_rules ( serial_number integer, From 81dd605d863a8f4683e344823d770247fa3f7350 Mon Sep 17 00:00:00 2001 From: lepip Date: Thu, 1 Feb 2024 19:01:33 +0000 Subject: [PATCH 8/9] WIP. Added kill rules. --- sql/query_tag--1.0.sql | 3 ++- src/query_tag.c | 45 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/sql/query_tag--1.0.sql b/sql/query_tag--1.0.sql index 3e6f5cd..c7a544a 100644 --- a/sql/query_tag--1.0.sql +++ b/sql/query_tag--1.0.sql @@ -32,7 +32,8 @@ CREATE TABLE wlm_rules ( spill_file_mb int, cpuskew_percent int, cpuskew_duration_sec int, - order_id int not null + order_id int not null, + kill_rule boolean ); CREATE TABLE gpcc_wlm_log_history ( diff --git a/src/query_tag.c b/src/query_tag.c index 34cc8b7..531ff9e 100644 --- a/src/query_tag.c +++ b/src/query_tag.c @@ -14,6 +14,7 @@ #include "utils/syscache.h" #include "catalog/pg_authid.h" #include "cdb/cdbvars.h" +#include "optimizer/planner.h" PG_MODULE_MAGIC; @@ -34,6 +35,42 @@ static const int MAX_QUERY_SIZE = 200; static const int MAX_QUERY_TAG_LENGTH = 100; static resgroup_assign_hook_type prev_hook = NULL; +static planner_hook_type prev_planner_hook = NULL; + +PlannedStmt * +kill_rules_manager(Query *parse, int cursorOptions, ParamListInfo boundParams) +{ + PlannedStmt *result = NULL; + result = prev_planner_hook(parse, cursorOptions, boundParams); + + int n_moves = result->nMotionNodes; + int SPI_status; + StringInfoData query; + StringInfoData cost_query; + char *rgname = GetResGroupNameForId(current_resgroup_id()); + char *rolename = GetUserNameFromId(GetUserId()); + initStringInfo(&query); + initStringInfo(&cost_query); + float cost = 0; // TODO + if (result->planGen == PLANGEN_PLANNER) { + appendStringInfo(&cost_query, "planner_cost <= %d", cost); + } else { + appendStringInfo(&cost_query, "orca_cost <= %d", cost); + } + appendStringInfo(&query, "select rule_id, dest_resg from wlm_rules where resgname = '%s' and role " + "= '%s' and active = TRUE and %s and is_tag_in_guc(query_tag) and kill_rule = TRUE order by order_id limit 1;", + rgname, rolename, cost_query.data); + + SPI_status = SPI_execute(query.data, false, 0); + if (SPI_status < 0) { + SPI_finish(); + elog(ERROR, "QUERY_TAG: Failed to execute SQL query: %s", query.data); + } + if (SPI_processed > 0) { + elog(ERROR, "QUERY_TAG: there's a kill_rule. Stopped"); + } + return result; +} Datum is_tag_in_guc(PG_FUNCTION_ARGS) { elog(DEBUG4, "Printing gucs in istaginguc"); @@ -102,7 +139,7 @@ static Oid resgroup_assign_by_query_tag(void) { int full_length = snprintf( query, sizeof(query), "select rule_id, dest_resg from wlm_rules where resgname = '%s' and role " - "= '%s' and active = TRUE and is_tag_in_guc(query_tag) order by order_id limit 1;", + "= '%s' and active = TRUE and is_tag_in_guc(query_tag) and kill_rule = FALSE order by order_id limit 1;", rgname, rolename); if (full_length >= MAX_QUERY_SIZE) { elog(ERROR, "QUERY_TAG: failed, query tag too long"); @@ -221,7 +258,13 @@ void _PG_init(void) { assign_query_tag, /* assign hook */ show_query_tag); /* show hook */ prev_hook = resgroup_assign_hook; + if (planner_hook) { + prev_planner_hook = planner_hook; + } else { + prev_planner_hook = standard_planner; + } resgroup_assign_hook = resgroup_assign_by_query_tag; + planner_hook = kill_rules_manager; } void _PG_fini(void) { From 717c395297d75cac45f1dbbaf9d6ae99ddac683d Mon Sep 17 00:00:00 2001 From: lepip Date: Sun, 4 Feb 2024 18:58:11 +0000 Subject: [PATCH 9/9] Fixed minor issues + new WIP 'kill_rule' --- src/parser.c | 70 +++++++++++++------------------------ src/parser.h | 7 ++-- src/query_tag.c | 69 +++++++++++++----------------------- test/expected/query_tag.out | 24 ++++++------- test/sql/query_tag.sql | 24 ++++++------- 5 files changed, 76 insertions(+), 118 deletions(-) diff --git a/src/parser.c b/src/parser.c index b9c234b..28ff8b5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -15,52 +15,48 @@ static void free_double_list(List **double_list) { *double_list = NIL; } -bool split_tags(const char *tags, ParsedTags **parced) { - MemoryContext oldctx = MemoryContextSwitchTo(TopMemoryContext); - *parced = palloc(sizeof(**parced)); +bool split_tags(const char *tags, ParsedTags **parsed) { if (!tags) { elog(ERROR, "QUERY_TAG: there's a NULL query_tag somewhere."); } + MemoryContext oldctx = MemoryContextSwitchTo(TopMemoryContext); + *parsed = palloc(sizeof(**parsed)); char *tags_mutable = pstrdup(tags); - List *almost_parced_tags = NIL; - bool ok = SplitIdentifierString(tags_mutable, ';', &almost_parced_tags); + List *tag_pairs = NIL; + bool ok = SplitIdentifierString(tags_mutable, ';', &tag_pairs); if (!ok) { - pfree(*parced); - *parced = NULL; + pfree(*parsed); + *parsed = NULL; pfree(tags_mutable); - list_free(almost_parced_tags); + list_free(tag_pairs); MemoryContextSwitchTo(oldctx); return false; } ListCell *current_tag; - List *parced_tags = NIL; - foreach(current_tag, almost_parced_tags) { + List *parsed_tags = NIL; + foreach(current_tag, tag_pairs) { List *parsed_current_tag = NIL; ok = SplitIdentifierString(lfirst(current_tag), '=', &parsed_current_tag); if (!ok || list_length(parsed_current_tag) != 2) { list_free(parsed_current_tag); - free_double_list(&parced_tags); - pfree(*parced); - *parced = NULL; + free_double_list(&parsed_tags); + pfree(*parsed); + *parsed = NULL; pfree(tags_mutable); - list_free(almost_parced_tags); + list_free(tag_pairs); MemoryContextSwitchTo(oldctx); return false; } - parced_tags = lappend(parced_tags, parsed_current_tag); + parsed_tags = lappend(parsed_tags, parsed_current_tag); } - (*parced)->tags_mutable = tags_mutable; - (*parced)->parsed_tags = parced_tags; + (*parsed)->tags_mutable = tags_mutable; + (*parsed)->parsed_tags = parsed_tags; MemoryContextSwitchTo(oldctx); return true; } bool is_parsed_rule_in_parsed_guc(ParsedTags *rule_tags, ParsedTags *guc_tags) { - elog(DEBUG4, "Printing guc:"); - print_parsed_tags(guc_tags); - elog(DEBUG4, "Printing rule:"); - print_parsed_tags(rule_tags); ListCell *guc_cell, *tag_cell; foreach (tag_cell, rule_tags->parsed_tags) { List *tag_pair = lfirst(tag_cell); @@ -80,30 +76,12 @@ bool is_parsed_rule_in_parsed_guc(ParsedTags *rule_tags, ParsedTags *guc_tags) { return true; } -void free_parsed_tags(ParsedTags **parced) { - if (*parced) { - free_double_list(&(*parced)->parsed_tags); - if ((*parced)->tags_mutable) - pfree((*parced)->tags_mutable); - elog(DEBUG4, "FREED: %d", (int)*parced); - pfree(*parced); - *parced = NULL; - } -} - -void print_parsed_tags(ParsedTags *parsed) { - elog(DEBUG4, "Printing tags:"); - ListCell *current_cell; - ListCell *current_tag; - int id = 0; - if (parsed) { - foreach(current_cell, parsed->parsed_tags) { - foreach(current_tag, lfirst(current_cell)) { - elog(DEBUG4, "%d: %s", id, lfirst(current_tag)); - id++; - } - } - } else { - elog(DEBUG4, "Null, lol"); +void free_parsed_tags(ParsedTags **parsed) { + if (*parsed) { + free_double_list(&(*parsed)->parsed_tags); + if ((*parsed)->tags_mutable) + pfree((*parsed)->tags_mutable); + pfree(*parsed); + *parsed = NULL; } } \ No newline at end of file diff --git a/src/parser.h b/src/parser.h index 5d2157b..571fb5d 100644 --- a/src/parser.h +++ b/src/parser.h @@ -5,7 +5,6 @@ typedef struct ParsedTags { List *parsed_tags; } ParsedTags; -bool split_tags(const char *tags, ParsedTags **parced); -bool is_parsed_rule_in_parsed_guc(ParsedTags *parced_rule, ParsedTags *parced_guc); -void free_parsed_tags(ParsedTags **parced); -void print_parsed_tags(ParsedTags *parsed); +bool split_tags(const char *tags, ParsedTags **parsed); +bool is_parsed_rule_in_parsed_guc(ParsedTags *parsed_rule, ParsedTags *parsed_guc); +void free_parsed_tags(ParsedTags **parsed); diff --git a/src/query_tag.c b/src/query_tag.c index 531ff9e..14add84 100644 --- a/src/query_tag.c +++ b/src/query_tag.c @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include "catalog/pg_authid.h" #include "cdb/cdbvars.h" #include "optimizer/planner.h" +#include PG_MODULE_MAGIC; @@ -42,29 +44,42 @@ kill_rules_manager(Query *parse, int cursorOptions, ParamListInfo boundParams) { PlannedStmt *result = NULL; result = prev_planner_hook(parse, cursorOptions, boundParams); + return result; + + // under construction int n_moves = result->nMotionNodes; - int SPI_status; + int SPI_status = -1; StringInfoData query; StringInfoData cost_query; char *rgname = GetResGroupNameForId(current_resgroup_id()); char *rolename = GetUserNameFromId(GetUserId()); initStringInfo(&query); initStringInfo(&cost_query); - float cost = 0; // TODO + double cost = result->planTree->total_cost; + elog(NOTICE, "Cost: %f", cost); if (result->planGen == PLANGEN_PLANNER) { - appendStringInfo(&cost_query, "planner_cost <= %d", cost); + appendStringInfo(&cost_query, "planner_cost <= %f", cost); } else { - appendStringInfo(&cost_query, "orca_cost <= %d", cost); + appendStringInfo(&cost_query, "orca_cost <= %f", cost); } appendStringInfo(&query, "select rule_id, dest_resg from wlm_rules where resgname = '%s' and role " "= '%s' and active = TRUE and %s and is_tag_in_guc(query_tag) and kill_rule = TRUE order by order_id limit 1;", rgname, rolename, cost_query.data); + PG_TRY(); + { + SPI_status = SPI_execute(query.data, false, 0); + } + PG_CATCH(); + { + SPI_status = -1; + } + PG_END_TRY(); - SPI_status = SPI_execute(query.data, false, 0); if (SPI_status < 0) { SPI_finish(); - elog(ERROR, "QUERY_TAG: Failed to execute SQL query: %s", query.data); + elog(DEBUG3, "QUERY_TAG: query failed in the kill rule processor."); + return result; } if (SPI_processed > 0) { elog(ERROR, "QUERY_TAG: there's a kill_rule. Stopped"); @@ -73,8 +88,6 @@ kill_rules_manager(Query *parse, int cursorOptions, ParamListInfo boundParams) } Datum is_tag_in_guc(PG_FUNCTION_ARGS) { - elog(DEBUG4, "Printing gucs in istaginguc"); - print_parsed_tags(parsed_guc_tags); text *rule_query_tag = PG_GETARG_TEXT_P(0); char *rule_query_tag_cstr = text_to_cstring(rule_query_tag); if (!rule_query_tag_cstr) { @@ -189,43 +202,16 @@ static bool check_new_query_tag(char **newvalue, void **extra, GucSource source) elog(DEBUG3, "QUERY_TAG: Tag didn't pass parsing."); return false; } - if (parsed_guc_tags == new_parsed_guc_tag) { - elog(DEBUG3, "Why... (This like shouldn't ever occur), %d", (int)parsed_guc_tags); - return true; - } - elog(DEBUG3, "QUERY_TAG: Free old one: %d", parsed_guc_tags); + // if they are the same, it means, that memory contexts messed up + assert(parsed_guc_tags != new_parsed_guc_tag); if (parsed_guc_tags) { free_parsed_tags(&parsed_guc_tags); parsed_guc_tags = NULL; } - elog(DEBUG3, "QUERY_TAG: Setup new one: %d", new_parsed_guc_tag); parsed_guc_tags = new_parsed_guc_tag; - print_parsed_tags(parsed_guc_tags); return true; } -int *stuff = NULL; - -static void assign_query_tag(const char *newvalue, void *extra) { - /*elog(NOTICE, "heh, %d", (int)Gp_role); - MemoryContext old_context = MemoryContextSwitchTo(TopMemoryContext); - elog(NOTICE, "stuff: %d", (int)stuff); - if (stuff) { - elog(NOTICE, "stuff value: %d", *stuff); - } else { - elog(NOTICE, "stuff value: NULL"); - } - int *old_stuff = stuff; - stuff = palloc(sizeof(*stuff)); - *stuff = (int)stuff; - elog(NOTICE, "new_stuff: %d", (int)stuff); - elog(NOTICE, "new_stuff value: %d", *stuff); - if (old_stuff != stuff && old_stuff != NULL) { - pfree(old_stuff); - } - MemoryContextSwitchTo(old_context);*/ -} - static Oid current_resgroup_id() { Oid group_id = ResGroupGetGroupIdBySessionId(MySessionState->sessionId); return group_id; @@ -241,11 +227,6 @@ Datum current_resgroup(PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P(cstring_to_text(resgroup_name)); } -static const char *show_query_tag(void) { - print_parsed_tags(parsed_guc_tags); - return query_tag; -} - void _PG_init(void) { DefineCustomStringVariable( "QUERY_TAG", @@ -255,8 +236,8 @@ void _PG_init(void) { "", /* initial value */ PGC_USERSET, 0, /* flags */ check_new_query_tag, /* check hook */ - assign_query_tag, /* assign hook */ - show_query_tag); /* show hook */ + NULL, /* assign hook */ + NULL); /* show hook */ prev_hook = resgroup_assign_hook; if (planner_hook) { prev_planner_hook = planner_hook; diff --git a/test/expected/query_tag.out b/test/expected/query_tag.out index ba179db..3fe691f 100644 --- a/test/expected/query_tag.out +++ b/test/expected/query_tag.out @@ -52,10 +52,10 @@ SHOW QUERY_TAG; -- should set to rgroup1 CREATE RESOURCE GROUP rgroup1 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); CREATE RESOURCE GROUP rgroup2 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1', TRUE); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup2', 4, 'group=rgroup1', TRUE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1', TRUE, FALSE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('admin_group', 'clepip', 'rgroup2', 4, 'group=rgroup1', TRUE, FALSE); SET QUERY_TAG TO "group=rgroup1"; SELECT current_resgroup(); current_resgroup @@ -65,10 +65,10 @@ SELECT current_resgroup(); -- should still set to rgroup1 (we are in admin_group, the "current_rsgroup" shows group after --- applying tags, and tags are applied accordingly to users rsgroup) -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('rgroup1', 'clepip', 'rgroup2', 1, 'group=still_1', TRUE); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup1', 5, 'group=still_1', TRUE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('rgroup1', 'clepip', 'rgroup2', 1, 'group=still_1', TRUE, FALSE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('admin_group', 'clepip', 'rgroup1', 5, 'group=still_1', TRUE, FALSE); SET QUERY_TAG TO "group=still_1"; SELECT CURRENT_RESGROUP(); current_resgroup @@ -77,10 +77,10 @@ SELECT CURRENT_RESGROUP(); (1 row) -- should set to rgroup1 -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup2', 1, 'group=cancelled', FALSE); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup1', 2, 'group=cancelled', TRUE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('admin_group', 'clepip', 'rgroup2', 1, 'group=cancelled', FALSE, FALSE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('admin_group', 'clepip', 'rgroup1', 2, 'group=cancelled', TRUE, FALSE); SET QUERY_TAG TO "group=cancelled"; SELECT CURRENT_RESGROUP(); current_resgroup diff --git a/test/sql/query_tag.sql b/test/sql/query_tag.sql index d157553..134a1a7 100644 --- a/test/sql/query_tag.sql +++ b/test/sql/query_tag.sql @@ -30,10 +30,10 @@ SHOW QUERY_TAG; CREATE RESOURCE GROUP rgroup1 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); CREATE RESOURCE GROUP rgroup2 WITH (CPU_RATE_LIMIT=20, MEMORY_LIMIT=25, MEMORY_SPILL_RATIO=20); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1', TRUE); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup2', 4, 'group=rgroup1', TRUE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('admin_group', 'clepip', 'rgroup1', 3, 'group=rgroup1', TRUE, FALSE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('admin_group', 'clepip', 'rgroup2', 4, 'group=rgroup1', TRUE, FALSE); SET QUERY_TAG TO "group=rgroup1"; SELECT current_resgroup(); @@ -41,20 +41,20 @@ SELECT current_resgroup(); -- should still set to rgroup1 (we are in admin_group, the "current_rsgroup" shows group after --- applying tags, and tags are applied accordingly to users rsgroup) -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('rgroup1', 'clepip', 'rgroup2', 1, 'group=still_1', TRUE); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup1', 5, 'group=still_1', TRUE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('rgroup1', 'clepip', 'rgroup2', 1, 'group=still_1', TRUE, FALSE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('admin_group', 'clepip', 'rgroup1', 5, 'group=still_1', TRUE, FALSE); SET QUERY_TAG TO "group=still_1"; SELECT CURRENT_RESGROUP(); -- should set to rgroup1 -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup2', 1, 'group=cancelled', FALSE); -INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active) - VALUES ('admin_group', 'clepip', 'rgroup1', 2, 'group=cancelled', TRUE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('admin_group', 'clepip', 'rgroup2', 1, 'group=cancelled', FALSE, FALSE); +INSERT INTO wlm_rules (resgname, role, dest_resg, order_id, query_tag, active, kill_rule) + VALUES ('admin_group', 'clepip', 'rgroup1', 2, 'group=cancelled', TRUE, FALSE); SET QUERY_TAG TO "group=cancelled"; SELECT CURRENT_RESGROUP(); \ No newline at end of file