diff --git a/0004-fix-some-sql-bug.patch b/0004-fix-some-sql-bug.patch new file mode 100644 index 0000000000000000000000000000000000000000..bce46ac0924bd951710e3f9a8471807e7069f35d --- /dev/null +++ b/0004-fix-some-sql-bug.patch @@ -0,0 +1,521 @@ +From 106ed0adc93f3df378ee736977ef89d5215620ea Mon Sep 17 00:00:00 2001 +From: motodiary +Date: Mon, 29 Apr 2024 09:38:54 +0800 +Subject: [PATCH] fix some sql bug + +--- + src/database/pgsql_common.c | 89 ++++++++++++++---- + src/database/pgsql_common.h | 1 - + .../mysql/accounting_storage_mysql.c | 2 +- + .../pgsql/accounting_storage_pgsql.c | 93 ++++++++----------- + .../accounting_storage/pgsql/as_pgsql_assoc.c | 2 +- + .../pgsql/as_pgsql_rollup.c | 2 +- + 6 files changed, 113 insertions(+), 76 deletions(-) + mode change 100644 => 100755 src/plugins/accounting_storage/mysql/accounting_storage_mysql.c + +diff --git a/src/database/pgsql_common.c b/src/database/pgsql_common.c +index 3698609..b979f3d 100755 +--- a/src/database/pgsql_common.c ++++ b/src/database/pgsql_common.c +@@ -59,11 +59,11 @@ typedef struct { + + static char *_pgsql_handle_quotes(char *str) + { +- debug4("org str %s", str); + char *dup, *copy = NULL; + int len = 0; +- if (!str || !(len = strlen(str))) ++ if (!str || !(len = strlen(str))) { + return NULL; ++ } + + /* make a buffer 2 times the size just to be safe */ + copy = dup = xmalloc((2 * len) + 1); +@@ -76,10 +76,28 @@ static char *_pgsql_handle_quotes(char *str) + } + } while ((*dup++ = *str++)); + +- debug4("result str %s", copy); + return copy; + } + ++static void _pgsql_remove_quotes(char* str) { ++ int len = 0; ++ if (!str || !(len = strlen(str))) { ++ return ; ++ } ++ ++ char* src = str; ++ char* dest = str; ++ ++ while (*src) { ++ if (*src != '\"') { ++ *dest = *src; ++ dest++; ++ } ++ src++; ++ } ++ *dest = '\0'; ++} ++ + static void _init_pgsql_res(pgsql_res_t** result, pgsql_conn_t *pgsql_conn) + { + *result = (pgsql_res_t*)malloc(sizeof(pgsql_res_t)); +@@ -254,8 +272,11 @@ static int _pgsql_make_table_current(pgsql_conn_t *pgsql_conn, char *table_name, + char *temp = NULL, *temp2 = NULL; + List keys_list = NULL; + db_key_t *db_key = NULL; ++ char* table_prefix[200]; ++ memcpy(table_prefix, table_name, 200); ++ _pgsql_remove_quotes(table_prefix); + +- debug4("%s table_name %s", __func__, table_name); ++ debug4("%s table_name %s table_prefix %s", __func__, table_name, table_prefix); + DEF_TIMERS; + + /* figure out the unique index in the table */ +@@ -272,7 +293,7 @@ static int _pgsql_make_table_current(pgsql_conn_t *pgsql_conn, char *table_name, + WHERE \ + t.relname = '%s' \ + AND ix.indisunique = true;", +- table_name); ++ table_prefix); + debug4("figure out the unique keys in the table %s. query:\n %s", table_name, query); + + result = pgsql_db_query_ret(pgsql_conn, query, 0); +@@ -310,7 +331,7 @@ static int _pgsql_make_table_current(pgsql_conn_t *pgsql_conn, char *table_name, + WHERE \ + t.relname = '%s' \ + AND ix.indisunique = false;", +- table_name); ++ table_prefix); + debug4("figure out the non-unique keys in the table %s. query:\n %s", table_name, query); + + result = pgsql_db_query_ret(pgsql_conn, query, 0); +@@ -354,7 +375,8 @@ static int _pgsql_make_table_current(pgsql_conn_t *pgsql_conn, char *table_name, + + /* figure out the existing columns in the table */ + query = xstrdup_printf("SELECT column_name FROM information_schema.columns \ +- WHERE table_name = '%s';", table_name); ++ WHERE table_name = '%s';", table_prefix); ++ debug4("get exist columns in the table %s. query:\n %s", table_name, query); + result = pgsql_db_query_ret(pgsql_conn, query, 0); + if (!pgsql_db_match_state(pgsql_errno(result), SUCCESSFUL_COMPLETION)) { + xfree(query); +@@ -391,8 +413,8 @@ static int _pgsql_make_table_current(pgsql_conn_t *pgsql_conn, char *table_name, + list_iterator_reset(itr); + // update exist column + while ((col = list_next(itr))) { +- debug4("process column %s", col); + if (!xstrcmp(col, fields[i].name)) { ++ debug4("update exist column %s", col); + exist = 1; + // update column type + if (!strncmp(fields[i].type, "serial", 6)) { +@@ -402,14 +424,29 @@ static int _pgsql_make_table_current(pgsql_conn_t *pgsql_conn, char *table_name, + table_name, fields[i].name, fields[i].type); + + xstrfmtcat(query, "CREATE SEQUENCE IF NOT EXISTS %s_%s_seq OWNED BY %s.%s;", +- table_name, fields[i].name, table_name, fields[i].name); ++ table_prefix, fields[i].name, table_prefix, fields[i].name); + xstrfmtcat(correct_query, "CREATE SEQUENCE IF NOT EXISTS %s_%s_seq OWNED BY %s.%s;", +- table_name, fields[i].name, table_name, fields[i].name); ++ table_prefix, fields[i].name, table_prefix, fields[i].name); + + xstrfmtcat(query, "ALTER TABLE %s ALTER COLUMN \"%s\" SET DEFAULT nextval('%s_%s_seq');", +- table_name, fields[i].name, table_name, fields[i].name); ++ table_name, fields[i].name, table_prefix, fields[i].name); + xstrfmtcat(correct_query, "ALTER TABLE %s ALTER COLUMN \"%s\" SET DEFAULT nextval('%s_%s_seq');", +- table_name, fields[i].name, table_name, fields[i].name); ++ table_name, fields[i].name, table_prefix, fields[i].name); ++ } else if (!strncmp(fields[i].type, "bigserial", 9)) { ++ xstrfmtcat(query, "ALTER TABLE %s ALTER COLUMN \"%s\" TYPE bigint;", ++ table_name, fields[i].name, fields[i].type); ++ xstrfmtcat(correct_query, "ALTER TABLE %s ALTER COLUMN \"%s\" TYPE bigint;", ++ table_name, fields[i].name, fields[i].type); ++ ++ xstrfmtcat(query, "CREATE SEQUENCE IF NOT EXISTS %s_%s_seq OWNED BY %s.%s;", ++ table_prefix, fields[i].name, table_prefix, fields[i].name); ++ xstrfmtcat(correct_query, "CREATE SEQUENCE IF NOT EXISTS %s_%s_seq OWNED BY %s.%s;", ++ table_prefix, fields[i].name, table_prefix, fields[i].name); ++ ++ xstrfmtcat(query, "ALTER TABLE %s ALTER COLUMN \"%s\" SET DEFAULT nextval('%s_%s_seq');", ++ table_name, fields[i].name, table_prefix, fields[i].name); ++ xstrfmtcat(correct_query, "ALTER TABLE %s ALTER COLUMN \"%s\" SET DEFAULT nextval('%s_%s_seq');", ++ table_name, fields[i].name, table_prefix, fields[i].name); + } else { + xstrfmtcat(query, "ALTER TABLE %s ALTER COLUMN \"%s\" TYPE %s;", + table_name, fields[i].name, fields[i].type); +@@ -441,24 +478,38 @@ static int _pgsql_make_table_current(pgsql_conn_t *pgsql_conn, char *table_name, + info("adding column %s in table %s", fields[i].name, table_name); + + if (!strncmp(fields[i].type, "serial", 6)) { +- xstrfmtcat(query, "ALTER TABLE %s ADD %s TYPE integer;", ++ xstrfmtcat(query, "ALTER TABLE %s ADD \"%s\" integer;", + table_name, fields[i].name, fields[i].type); + xstrfmtcat(correct_query, "ALTER TABLE %s ALTER COLUMN \"%s\" TYPE integer;", + table_name, fields[i].name, fields[i].type); + + xstrfmtcat(query, "CREATE SEQUENCE IF NOT EXISTS %s_%s_seq OWNED BY %s.%s;", +- table_name, fields[i].name, table_name, fields[i].name); ++ table_prefix, fields[i].name, table_prefix, fields[i].name); + xstrfmtcat(correct_query, "CREATE SEQUENCE IF NOT EXISTS %s_%s_seq OWNED BY %s.%s;", +- table_name, fields[i].name, table_name, fields[i].name); ++ table_prefix, fields[i].name, table_prefix, fields[i].name); + + xstrfmtcat(query, "ALTER TABLE %s ALTER COLUMN \"%s\" SET DEFAULT nextval('%s_%s_seq');", +- table_name, fields[i].name, table_name, fields[i].name); ++ table_name, fields[i].name, table_prefix, fields[i].name); + xstrfmtcat(correct_query, "ALTER TABLE %s ALTER COLUMN \"%s\" SET DEFAULT nextval('%s_%s_seq');", +- table_name, fields[i].name, table_name, fields[i].name); ++ table_name, fields[i].name, table_prefix, fields[i].name); ++ } else if (!strncmp(fields[i].type, "bigserial", 9)) { ++ xstrfmtcat(query, "ALTER TABLE %s ALTER COLUMN \"%s\" TYPE bigint;", ++ table_name, fields[i].name, fields[i].type); ++ xstrfmtcat(correct_query, "ALTER TABLE %s ALTER COLUMN \"%s\" TYPE bigint;", ++ table_name, fields[i].name, fields[i].type); ++ ++ xstrfmtcat(query, "CREATE SEQUENCE IF NOT EXISTS %s_%s_seq OWNED BY %s.%s;", ++ table_prefix, fields[i].name, table_prefix, fields[i].name); ++ xstrfmtcat(correct_query, "CREATE SEQUENCE IF NOT EXISTS %s_%s_seq OWNED BY %s.%s;", ++ table_prefix, fields[i].name, table_prefix, fields[i].name); + ++ xstrfmtcat(query, "ALTER TABLE %s ALTER COLUMN \"%s\" SET DEFAULT nextval('%s_%s_seq');", ++ table_name, fields[i].name, table_prefix, fields[i].name); ++ xstrfmtcat(correct_query, "ALTER TABLE %s ALTER COLUMN \"%s\" SET DEFAULT nextval('%s_%s_seq');", ++ table_name, fields[i].name, table_prefix, fields[i].name); + } else { + // define column type +- xstrfmtcat(query, "ALTER TABLE %s ADD %s %s;", ++ xstrfmtcat(query, "ALTER TABLE %s ADD \"%s\" %s;", + table_name, fields[i].name, fields[i].type); + xstrfmtcat(correct_query, "ALTER TABLE %s ALTER COLUMN \"%s\" TYPE %s;", + table_name, fields[i].name, fields[i].type); +@@ -1197,6 +1248,7 @@ extern int pgsql_db_query_stmt(pgsql_conn_t *pgsql_conn, + extern int pgsql_db_create_table(pgsql_conn_t *pgsql_conn, char *table_name, + storage_field_t *fields, char *ending) + { ++ debug4("%s %s\n", __func__, table_name); + char *query = NULL; + int i = 0, rc; + storage_field_t *first_field = fields; +@@ -1270,6 +1322,7 @@ extern int pgsql_db_create_table(pgsql_conn_t *pgsql_conn, char *table_name, + rc = SLURM_SUCCESS; + } + ++ debug4("%s rows %d", __func__, rows); + return rows; + } + +diff --git a/src/database/pgsql_common.h b/src/database/pgsql_common.h +index 785a3ee..ab9e7ce 100755 +--- a/src/database/pgsql_common.h ++++ b/src/database/pgsql_common.h +@@ -136,7 +136,6 @@ typedef struct { + if (ret == SQL_SUCCESS && tmpCharLenOrInd != SQL_NULL_DATA) { \ + xstrcat(FinalValue, (char*)tmpChar); \ + } else { \ +- debug4("PGSQL_GET_TEXT_DATA ret %d, tmpCharLenOrInd %d, SQL_NULL_DATA %d", ret, tmpCharLenOrInd, SQL_NULL_DATA);\ + break; \ + }\ + } \ +diff --git a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c +old mode 100644 +new mode 100755 +index 24db1c7..6d57f91 +--- a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c ++++ b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c +@@ -2007,7 +2007,7 @@ extern int modify_common(mysql_conn_t *mysql_conn, + xassert(cluster_name); + xstrfmtcat(query, + "update \"%s_%s\" set mod_time=%ld%s " +- "where deleted=0 && %s;", ++ "where deleted=0 AND %s;", + cluster_name, table, now, vals, cond_char); + xstrfmtcat(query, + "insert into %s " +diff --git a/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c b/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c +index 588f5ac..4b1e87e 100755 +--- a/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c ++++ b/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c +@@ -424,6 +424,7 @@ static bool _check_jobs_before_remove_without_assoctable( + /* Any time a new table is added set it up here */ + static int _as_pgsql_acct_check_tables(pgsql_conn_t *pgsql_conn) + { ++ debug4("start. backup_dbd %d", backup_dbd); + storage_field_t acct_coord_table_fields[] = { + { "creation_time", "bigint", "not null" }, + { "mod_time", "bigint", "not null|default 0" }, +@@ -759,40 +760,6 @@ static int _as_pgsql_acct_check_tables(pgsql_conn_t *pgsql_conn) + $$ \n \ + LANGUAGE plpgsql;"; + +-// char *get_coord_qos = +-// "drop procedure if exists get_coord_qos; " +-// "create procedure get_coord_qos(my_table text, acct text, " +-// "cluster text, coord text) " +-// "begin " +-// "set @qos = ''; " +-// "set @delta_qos = ''; " +-// "set @found_coord = NULL; " +-// "set @my_acct = acct; " +-// "REPEAT " +-// "set @s = 'select @qos := t1.qos, " +-// "@delta_qos := REPLACE(CONCAT(t1.delta_qos, @delta_qos), " +-// "\\\',,\\\', \\\',\\\'), @my_acct_new := parent_acct, " +-// "@found_coord_curr := t2.user '; " +-// "set @s = concat(@s, 'from \"', cluster, '_', my_table, '\" " +-// "as t1 left outer join acct_coord_table as t2 on " +-// "t1.acct=t2.acct where t1.acct = @my_acct && t1.user=\\\'\\\' " +-// "&& (t2.user=\\\'', coord, '\\\' || t2.user is null)'); " +-// "prepare query from @s; " +-// "execute query; " +-// "deallocate prepare query; " +-// "if @found_coord_curr is not NULL then " +-// "set @found_coord = @found_coord_curr; " +-// "end if; " +-// "if @found_coord is NULL then " +-// "set @qos = ''; " +-// "set @delta_qos = ''; " +-// "end if; " +-// "set @my_acct = @my_acct_new; " +-// "UNTIL @qos != '' || @my_acct = '' END REPEAT; " +-// "select REPLACE(CONCAT(@qos, @delta_qos), ',,', ','); " +-// "END;"; +- +- + char *query = NULL; + time_t now = time(NULL); + char *cluster_name = NULL; +@@ -932,6 +899,7 @@ static int _as_pgsql_acct_check_tables(pgsql_conn_t *pgsql_conn) + * lock. We need to do this on all the clusters deleted or + * other wise just to make sure everything is kept up to + * date. */ ++ debug4("check cluster tables"); + itr = list_iterator_create(as_pgsql_total_cluster_list); + while ((cluster_name = list_next(itr))) { + if ((rc = create_cluster_tables(pgsql_conn, cluster_name)) +@@ -1148,7 +1116,7 @@ extern int create_cluster_assoc_table( + storage_field_t assoc_table_fields[] = { + { "creation_time", "bigint", "not null" }, + { "mod_time", "bigint", "default 0|not null" }, +- { "deleted", "boolean", "default false|not null" }, ++ { "deleted", "smallint", "default 0" }, + { "is_def", "boolean", "default false|not null" }, + { "id_assoc", "serial", "not null" }, + { "user", "text", "not null|default ''" }, +@@ -1182,16 +1150,20 @@ extern int create_cluster_assoc_table( + }; + + char table_name[200]; ++ char table_prefix[200]; + char* ending = NULL; + + snprintf(table_name, sizeof(table_name), "\"%s_%s\"", + cluster_name, assoc_table); ++ snprintf(table_prefix, sizeof(table_prefix), "%s_%s", ++ cluster_name, assoc_table); ++ + ending = xstrdup_printf(", primary key (id_assoc));" + "CREATE UNIQUE INDEX IF NOT EXISTS %s_udex ON %s " + "(substr(\"user\", 1, 42), substr(acct, 1, 42), substr(\"partition\", 1, 42));" + "CREATE INDEX IF NOT EXISTS %s_lft_idx ON %s (lft);" + "CREATE INDEX IF NOT EXISTS %s_acct_idx ON %s (acct);", +- table_name, table_name, table_name, table_name, table_name, table_name); ++ table_prefix, table_name, table_prefix, table_name, table_prefix, table_name); + if (pgsql_db_create_table(pgsql_conn, table_name, + assoc_table_fields, ending) == SLURM_ERROR) { + xfree(ending); +@@ -1208,7 +1180,7 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + storage_field_t cluster_usage_table_fields[] = { + { "creation_time", "bigint", "not null" }, + { "mod_time", "bigint", "default 0|not null" }, +- { "deleted", "boolean", "default false|not null" }, ++ { "deleted", "smallint", "default 0" }, + { "id_tres", "integer", "not null" }, + { "time_start", "bigint", "not null" }, + { "count", "bigint", "default 0|not null" }, +@@ -1227,7 +1199,7 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + { "node_name", "varchar", "default ''|not null" }, + { "cluster_nodes", "text", "not null|default ''" }, + { "reason", "varchar", "not null" }, +- { "reason_uid", "integer", "default 4294967294|not null" }, ++ { "reason_uid", "bigint", "default 4294967294|not null" }, + { "state", "integer", "default 0|not null" }, + { "tres", "text", "not null|default ''" }, + { NULL, NULL} +@@ -1236,7 +1208,7 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + storage_field_t id_usage_table_fields[] = { + { "creation_time", "bigint", "not null" }, + { "mod_time", "bigint", "default 0|not null" }, +- { "deleted", "boolean", "default false|not null" }, ++ { "deleted", "smallint", "default 0" }, + { "id", "integer", "not null" }, + { "id_tres", "integer", "default 1|not null" }, + { "time_start", "bigint", "not null" }, +@@ -1247,7 +1219,7 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + storage_field_t job_table_fields[] = { + { "job_db_inx", "bigserial", "not null" }, + { "mod_time", "bigint", "default 0|not null" }, +- { "deleted", "boolean", "default false|not null" }, ++ { "deleted", "smallint", "default 0" }, + { "account", "text", "" }, + { "admin_comment", "text", "" }, + { "array_task_str", "text", "" }, +@@ -1311,7 +1283,7 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + + storage_field_t resv_table_fields[] = { + { "id_resv", "integer", "default 0|not null" }, +- { "deleted", "smallint", "default 0|not null" }, ++ { "deleted", "smallint", "default 0" }, + { "assoclist", "text", "not null|default ''" }, + { "flags", "bigint", "default 0|not null" }, + { "nodelist", "text", "not null|default ''" }, +@@ -1326,7 +1298,7 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + + storage_field_t step_table_fields[] = { + { "job_db_inx", "bigint", "not null" }, +- { "deleted", "smallint", "default 0|not null" }, ++ { "deleted", "smallint", "default 0" }, + { "exit_code", "integer", "default 0|not null" }, + { "id_step", "integer", "not null" }, + { "step_het_comp", "integer", "default 4294967294|not null" }, +@@ -1383,7 +1355,7 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + storage_field_t wckey_table_fields[] = { + { "creation_time", "bigint", "not null" }, + { "mod_time", "bigint", "default 0|not null" }, +- { "deleted", "smallint", "default 0|not null" }, ++ { "deleted", "smallint", "default 0" }, + { "is_def", "smallint", "default 0|not null" }, + { "id_wckey", "serial", "not null" }, + { "wckey_name", "text", "not null|default ''" }, +@@ -1392,6 +1364,7 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + }; + + char table_name[200]; ++ char table_prefix[200]; + char* ending = NULL; + + if (create_cluster_assoc_table(pgsql_conn, cluster_name) +@@ -1454,11 +1427,13 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + + snprintf(table_name, sizeof(table_name), "\"%s_%s\"", + cluster_name, event_table); ++ snprintf(table_prefix, sizeof(table_prefix), "%s_%s", ++ cluster_name, event_table); + + ending = xstrdup_printf(", primary key (node_name, time_start));" + "CREATE INDEX IF NOT EXISTS %s_rollup_idx ON %s " + "(substr(node_name, 1, 42), time_start, time_end, state);", +- table_name, table_name); ++ table_prefix, table_name); + if (pgsql_db_create_table(pgsql_conn, table_name, + event_table_fields, ending) == SLURM_ERROR) { + xfree(ending); +@@ -1468,6 +1443,8 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + + snprintf(table_name, sizeof(table_name), "\"%s_%s\"", + cluster_name, job_table); ++ snprintf(table_prefix, sizeof(table_prefix), "%s_%s", ++ cluster_name, job_table); + + /* + * sacct_def is the index for query's with state as time_start is used +@@ -1487,11 +1464,11 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + "CREATE INDEX IF NOT EXISTS %s_reserv_idx ON %s (id_resv);" + "CREATE INDEX IF NOT EXISTS %s_sacct_def_idx ON %s (id_user, time_start, time_end);" + "CREATE INDEX IF NOT EXISTS %s_sacct_def2_idx ON %s (id_user, time_end, time_eligible);", +- table_name, table_name, table_name, table_name, table_name, table_name, +- table_name, table_name, table_name, table_name, table_name, table_name, +- table_name, table_name, table_name, table_name, table_name, table_name, +- table_name, table_name, table_name, table_name, table_name, table_name, +- table_name, table_name); ++ table_prefix, table_name, table_prefix, table_name, table_prefix, table_name, ++ table_prefix, table_name, table_prefix, table_name, table_prefix, table_name, ++ table_prefix, table_name, table_prefix, table_name, table_prefix, table_name, ++ table_prefix, table_name, table_prefix, table_name, table_prefix, table_name, ++ table_prefix, table_name); + + if (pgsql_db_create_table(pgsql_conn, table_name, job_table_fields, ending) + == SLURM_ERROR) { +@@ -1519,10 +1496,13 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + + snprintf(table_name, sizeof(table_name), "\"%s_%s\"", + cluster_name, step_table); ++ snprintf(table_prefix, sizeof(table_prefix), "%s_%s", ++ cluster_name, step_table); ++ + ending = xstrdup_printf(", primary key (job_db_inx, id_step, step_het_comp));" + "CREATE INDEX IF NOT EXISTS %s_no_step_comp_idx ON %s (job_db_inx, id_step);" + "CREATE INDEX IF NOT EXISTS %s_time_start_end_idx ON %s (time_start, time_end);", +- table_name, table_name, table_name, table_name); ++ table_prefix, table_name, table_prefix, table_name); + if (pgsql_db_create_table(pgsql_conn, table_name, + step_table_fields, ending) == SLURM_ERROR) { + xfree(ending); +@@ -1532,9 +1512,11 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + + snprintf(table_name, sizeof(table_name), "\"%s_%s\"", + cluster_name, suspend_table); ++ snprintf(table_prefix, sizeof(table_prefix), "%s_%s", ++ cluster_name, suspend_table); + ending = xstrdup_printf(", primary key (job_db_inx, time_start));" + "CREATE INDEX IF NOT EXISTS %s_job_db_inx_times_idx ON %s (job_db_inx, time_start, time_end);", +- table_name, table_name); ++ table_prefix, table_name); + if (pgsql_db_create_table(pgsql_conn, table_name, + suspend_table_fields, ending) == SLURM_ERROR) { + xfree(ending); +@@ -1544,9 +1526,12 @@ extern int create_cluster_tables(pgsql_conn_t *pgsql_conn, char *cluster_name) + + snprintf(table_name, sizeof(table_name), "\"%s_%s\"", + cluster_name, wckey_table); ++ snprintf(table_prefix, sizeof(table_prefix), "%s_%s", ++ cluster_name, wckey_table); ++ + ending = xstrdup_printf(", primary key (id_wckey));" +- "CREATE UNIQUE INDEX IF NOT EXISTS %s_udex ON %s (substr(wckey_name, 1, 42), substr(user, 1, 42));", +- table_name, table_name); ++ "CREATE UNIQUE INDEX IF NOT EXISTS %s_udex ON %s (substr(wckey_name, 1, 42), substr(\"user\", 1, 42));", ++ table_prefix, table_name); + if (pgsql_db_create_table(pgsql_conn, table_name, + wckey_table_fields, ending) == SLURM_ERROR) { + xfree(ending); +@@ -2031,7 +2016,7 @@ extern int modify_common(pgsql_conn_t *pgsql_conn, + } else { + xstrfmtcat(query, + "update %s set mod_time=%ld%s " +- "where deleted=0 && %s;", ++ "where deleted=0 AND %s;", + table, now, vals, cond_char); + xstrfmtcat(query, + "insert into %s " +diff --git a/src/plugins/accounting_storage/pgsql/as_pgsql_assoc.c b/src/plugins/accounting_storage/pgsql/as_pgsql_assoc.c +index f846b39..a135293 100755 +--- a/src/plugins/accounting_storage/pgsql/as_pgsql_assoc.c ++++ b/src/plugins/accounting_storage/pgsql/as_pgsql_assoc.c +@@ -49,7 +49,7 @@ char *assoc_req_inx[] = { + "rgt", + "user", + "acct", +- "`partition`", ++ "partition", + "shares", + "grp_tres_mins", + "grp_tres_run_mins", +diff --git a/src/plugins/accounting_storage/pgsql/as_pgsql_rollup.c b/src/plugins/accounting_storage/pgsql/as_pgsql_rollup.c +index 4275bf9..bcf369f 100755 +--- a/src/plugins/accounting_storage/pgsql/as_pgsql_rollup.c ++++ b/src/plugins/accounting_storage/pgsql/as_pgsql_rollup.c +@@ -1370,7 +1370,7 @@ extern int as_pgsql_hourly_rollup(pgsql_conn_t *pgsql_conn, + + /* now get the jobs during this time only */ + query = xstrdup_printf("select %s from \"%s_%s\" as job " +- "where (job.time_eligible AND " ++ "where (job.time_eligible != 0 AND " + "job.time_eligible < %ld AND " + "(job.time_end >= %ld OR " + "job.time_end = 0)) " +-- +2.33.0 + diff --git a/slurm.spec b/slurm.spec index 6dc710be9f955d0c1c06ffc7fd888f1f4e53dc3a..95398566379fb1b1f1c5d4f78510af81e7ae04b2 100644 --- a/slurm.spec +++ b/slurm.spec @@ -1,6 +1,6 @@ Name: slurm Version: 21.08.8 -%define rel 6 +%define rel 7 Release: %{rel}%{?dist} Summary: Slurm Workload Manager @@ -19,6 +19,7 @@ Source: %{slurm_source_dir}.tar.bz2 Patch1: 0001-support-oversubscribe-in-submit_job-restapi.patch Patch2: 0002-add-pgsql-plugin.patch Patch3: 0003-replace-with-AND-in-as_pgsql_resource.patch +Patch4: 0004-fix-some-sql-bug.patch # build options .rpmmacros options change to default action # ==================== ==================== ======================== @@ -711,6 +712,9 @@ rm -rf %{buildroot} %systemd_postun_with_restart slurmdbd.service %changelog +* Mon Apr 29 2024 Xing Liu - 21.08.8-7 +- fix some sql bug + * Sun Apr 28 2024 Xing Liu - 21.08.8-6 - add Patch3 in slurm.spec - replace ‘&&’ with AND in sql in as_pgsql_resource.c