diff --git a/0033-fix-pgsql_db_insert_ret_id.patch b/0033-fix-pgsql_db_insert_ret_id.patch new file mode 100644 index 0000000000000000000000000000000000000000..2cbe3f435ce4457e32a1bda06b651141fb033c64 --- /dev/null +++ b/0033-fix-pgsql_db_insert_ret_id.patch @@ -0,0 +1,147 @@ +From f8df08dd7343f0e907daf7c6afa56ece3cbee07e Mon Sep 17 00:00:00 2001 +From: motodiary +Date: Wed, 29 May 2024 09:52:57 +0800 +Subject: [PATCH] fix pgsql_db_insert_ret_id + +--- + src/database/pgsql_common.c | 33 +++++++++---------- + .../pgsql/accounting_storage_pgsql.c | 6 ++-- + .../accounting_storage/pgsql/as_pgsql_job.c | 19 ++++++----- + 3 files changed, 31 insertions(+), 27 deletions(-) + +diff --git a/src/database/pgsql_common.c b/src/database/pgsql_common.c +index 03d2bf0..df5d9e3 100755 +--- a/src/database/pgsql_common.c ++++ b/src/database/pgsql_common.c +@@ -1336,26 +1336,25 @@ extern int pgsql_db_query_check_after(pgsql_conn_t *pgsql_conn, char *query) + + extern uint64_t pgsql_db_insert_ret_id(pgsql_conn_t *pgsql_conn, char *query) + { +- SQLINTEGER new_id = 0; ++ SQLINTEGER insert_id = 0; + SQLINTEGER len; +- SQLHSTMT stmt; +- SQLRETURN rc = 0; ++ pgsql_res_t *result = NULL; ++ pgsql_row row; + +- slurm_mutex_lock(&pgsql_conn->lock); +- SQLAllocHandle(SQL_HANDLE_STMT, pgsql_conn->db_conn, &stmt); +- SQLCHAR state[PGSQL_STATE_LEN + 1]; +- if (SLURM_SUCCESS == _pgsql_query_internal(pgsql_conn->db_conn, query, stmt, state)) { +- rc = SQLGetStmtAttr(stmt, SQL_DESC_AUTO_UNIQUE_VALUE, &new_id, sizeof(new_id), &len); +- if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { +- SQLCHAR state[PGSQL_STATE_LEN + 1]; +- PGSQL_HANDLE_ERROR("SQLGetStmtAttr", rc, SQL_HANDLE_STMT, stmt, state); +- new_id = 0; +- } +- } +- pgsql_db_free_statement(&stmt); +- slurm_mutex_unlock(&pgsql_conn->lock); ++ result = pgsql_db_query_ret(pgsql_conn, query, 0); ++ //result = pgsql_db_query_last_ret(pgsql_conn, query); ++ if (!pgsql_db_match_state(pgsql_errno(result), SUCCESSFUL_COMPLETION)) { ++ pgsql_free_result(&result); ++ return 0; ++ } + +- return new_id; ++ while ((row = pgsql_fetch_row(result))) { ++ insert_id = slurm_atoul(row[0]); ++ } ++ ++ debug4("%s insert_id %d", __func__, insert_id); ++ pgsql_free_result(&result); ++ return insert_id; + + } + +diff --git a/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c b/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c +index 1d4a2bb..67442aa 100755 +--- a/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c ++++ b/src/plugins/accounting_storage/pgsql/accounting_storage_pgsql.c +@@ -977,8 +977,9 @@ static int _as_pgsql_acct_check_tables(pgsql_conn_t *pgsql_conn) + "VALUES (%ld, %ld, '%s', " + "'Added as default') " + "ON CONFLICT (\"name\") DO UPDATE " +- "SET deleted = 0;", ++ "SET deleted = 0", + qos_table, now, now, qos); ++ xstrcat(query, " returning id;"); + + DB_DEBUG(DB_QOS, pgsql_conn->conn, "%s", query); + qos_id = (int)pgsql_db_insert_ret_id( +@@ -997,9 +998,10 @@ static int _as_pgsql_acct_check_tables(pgsql_conn_t *pgsql_conn) + "VALUES (%ld, %ld, 'normal', " + "'Normal QOS default') " + "ON CONFLICT (\"name\") DO UPDATE " +- "SET deleted = 0;", ++ "SET deleted = 0", + qos_table, now, now); + ++ xstrcat(query, " returning id;"); + DB_DEBUG(DB_QOS, pgsql_conn->conn, "%s", query); + qos_id = (int)pgsql_db_insert_ret_id(pgsql_conn, query); + if (!qos_id) +diff --git a/src/plugins/accounting_storage/pgsql/as_pgsql_job.c b/src/plugins/accounting_storage/pgsql/as_pgsql_job.c +index 038d667..a08bfe3 100755 +--- a/src/plugins/accounting_storage/pgsql/as_pgsql_job.c ++++ b/src/plugins/accounting_storage/pgsql/as_pgsql_job.c +@@ -105,13 +105,14 @@ static uint64_t _get_db_index(pgsql_conn_t *pgsql_conn, + "time_submit=%d and id_job=%u", + pgsql_conn->cluster_name, job_table, + (int)submit, jobid); ++ DB_DEBUG(DB_JOB, pgsql_conn->conn, "query\n%s", query); + +- result = pgsql_db_query_ret(pgsql_conn, query, 0); +- if (!pgsql_db_match_state(pgsql_errno(result), SUCCESSFUL_COMPLETION)) { +- xfree(query); +- pgsql_free_result(&result); +- return 0; +- } ++ result = pgsql_db_query_ret(pgsql_conn, query, 0); ++ if (!pgsql_db_match_state(pgsql_errno(result), SUCCESSFUL_COMPLETION)) { ++ xfree(query); ++ pgsql_free_result(&result); ++ return 0; ++ } + xfree(query); + + row = pgsql_fetch_row(result); +@@ -125,6 +126,7 @@ static uint64_t _get_db_index(pgsql_conn_t *pgsql_conn, + return 0; + } + db_index = slurm_atoull(row[0]); ++ debug4("%s jobid %d db_index %d", __func__, jobid, db_index); + pgsql_free_result(&result); + + return db_index; +@@ -581,7 +583,7 @@ no_rollup_change: + + xstrfmtcat(query, + ") ON CONFLICT (id_job, time_submit) DO UPDATE SET " +- "job_db_inx=currval(pg_get_serial_sequence('%s_%s', 'job_db_inx')), " ++ //"job_db_inx=currval(pg_get_serial_sequence('%s_%s', 'job_db_inx')), " + "id_assoc=%u, id_user=%u, id_group=%u, " + "nodelist='%s', id_resv=%u, timelimit=%u, " + "time_submit=%ld, time_eligible=%ld, " +@@ -592,7 +594,7 @@ no_rollup_change: + "mem_req=%"PRIu64", id_array_job=%u, id_array_task=%u, " + "het_job_id=%u, het_job_offset=%u, flags=%u, " + "state_reason_prev=%u", +- pgsql_conn->cluster_name, job_table, ++ //pgsql_conn->cluster_name, job_table, + job_ptr->assoc_id, job_ptr->user_id, + job_ptr->group_id, nodes, + job_ptr->resv_id, job_ptr->time_limit, +@@ -660,6 +662,7 @@ no_rollup_change: + xstrfmtcat(query, ", container='%s'", + job_ptr->container); + ++ xstrcat(query, " returning job_db_inx;"); + DB_DEBUG(DB_JOB, pgsql_conn->conn, "query\n%s", query); + try_again: + if (!(job_ptr->db_index = pgsql_db_insert_ret_id( +-- +2.33.0 + diff --git a/slurm.spec b/slurm.spec index 4680c2964a0a2bc3015f1772388f0a7d44fe839a..9b5a2414ec7d8325717f31221a5b6df2c8321de0 100644 --- a/slurm.spec +++ b/slurm.spec @@ -1,6 +1,6 @@ Name: slurm Version: 21.08.8 -%define rel 35 +%define rel 36 Release: %{rel}%{?dist} Summary: Slurm Workload Manager @@ -48,6 +48,7 @@ Patch29: 0029-add-partition-default-value-in-job_table.patch Patch30: 0030-Modify-the-alias-after-EXCLUDED-in-SQL-to-field-name.patch Patch31: 0031-fix-some-error-add-pgsql_escape_str-function.patch Patch32: 0032-Correcting-archive-SQL-statements-in-tables.patch +Patch33: 0033-fix-pgsql_db_insert_ret_id.patch # build options .rpmmacros options change to default action # ==================== ==================== ======================== @@ -740,6 +741,9 @@ rm -rf %{buildroot} %systemd_postun_with_restart slurmdbd.service %changelog +* Wed May 29 2024 Xing Liu - 21.08.8-36 +- fix pgsql_db_insert_ret_id + * Tue May 28 2024 Xing Liu - 21.08.8-35 - Correcting archive SQL statements in tables