From 03e404dcf4d32a07947fb839fc3eaa4575f4f4ba Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 21 Dec 2023 16:01:16 +0100 Subject: [PATCH 01/20] Remove group_sum_starttime Remove group_sum_starttime due to its unclear purpose and predominantly zero values. 'select count(*) from mxq_group where group_sum_starttime=0' +----------+ | count(*) | +----------+ | 539223 | +----------+ 'select count(*) from mxq_group where group_sum_starttime!=0' +----------+ | count(*) | +----------+ | 11014 | +----------+ 'select distinct(group_sum_starttime) from mxq_group limit 10' +---------------------+ | group_sum_starttime | +---------------------+ | 0 | | 62509173560 | | 682762450608 | | 50573290960 | | 126435008048 | | 328732081280 | | 75859753168 | | 75859750064 | | 1770065450784 | | 75861674832 | +---------------------+ --- mxq_group.c | 4 +--- mxq_group.h | 1 - mysql/create_tables.sql | 1 - mysql/create_trigger.sql | 10 +--------- 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/mxq_group.c b/mxq_group.c index 066eff38..a354f424 100644 --- a/mxq_group.c +++ b/mxq_group.c @@ -11,7 +11,7 @@ #include "mx_util.h" #include "mx_mysql.h" -#define GROUP_FIELDS_CNT 38 +#define GROUP_FIELDS_CNT 37 #define GROUP_FIELDS \ " group_id," \ " group_name," \ @@ -42,7 +42,6 @@ " group_jobs_unknown," \ " group_jobs_restarted," \ " group_slots_running," \ - " group_sum_starttime," \ " stats_max_sumrss," \ " stats_max_maxrss," \ " stats_max_utime_sec," \ @@ -97,7 +96,6 @@ static int bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_gro res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_restarted)); res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_slots_running)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_sum_starttime)); res += mx_mysql_bind_var(result, idx++, uint64, &(g->stats_max_sumrss)); res += mx_mysql_bind_var(result, idx++, uint64, &(g->stats_max_maxrss)); diff --git a/mxq_group.h b/mxq_group.h index 5eb23b2e..a72e1580 100644 --- a/mxq_group.h +++ b/mxq_group.h @@ -46,7 +46,6 @@ struct mxq_group { uint64_t group_jobs_restarted; uint64_t group_slots_running; - uint64_t group_sum_starttime; uint64_t stats_max_sumrss; uint64_t stats_max_maxrss; diff --git a/mysql/create_tables.sql b/mysql/create_tables.sql index 549b55a7..7885e52e 100644 --- a/mysql/create_tables.sql +++ b/mysql/create_tables.sql @@ -35,7 +35,6 @@ CREATE TABLE IF NOT EXISTS mxq_group ( group_jobs_restarted INT8 UNSIGNED NOT NULL DEFAULT 0, group_slots_running INT8 UNSIGNED NOT NULL DEFAULT 0, - group_sum_starttime INT8 UNSIGNED NOT NULL DEFAULT 0, group_mtime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, diff --git a/mysql/create_trigger.sql b/mysql/create_trigger.sql index e4a35dbb..0833974e 100644 --- a/mysql/create_trigger.sql +++ b/mysql/create_trigger.sql @@ -53,7 +53,6 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job SET NEW.date_start = NOW(); UPDATE mxq_group SET - group_sum_starttime = group_sum_starttime + UNIX_TIMESTAMP(NEW.date_start) * OLD.host_slots, group_jobs_inq = group_jobs_inq - 1, group_jobs_running = group_jobs_running + 1, group_slots_running = group_slots_running + NEW.host_slots @@ -68,17 +67,13 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job UPDATE mxq_group SET group_slots_running = group_slots_running - OLD.host_slots - + NEW.host_slots, - group_sum_starttime = group_sum_starttime - - UNIX_TIMESTAMP(OLD.date_start) * OLD.host_slots - + UNIX_TIMESTAMP(OLD.date_start) * NEW.host_slots + + NEW.host_slots WHERE group_id = NEW.group_id; -- LOADED(150) | RUNNING(200) -> KILLED(400) | FAILED(750) ELSEIF NEW.job_status IN (400, 750) AND OLD.job_status IN (150, 200) THEN UPDATE mxq_group SET - group_sum_starttime = group_sum_starttime - LEAST(group_sum_starttime, UNIX_TIMESTAMP(OLD.date_start) * OLD.host_slots), group_slots_running = group_slots_running - OLD.host_slots, group_jobs_running = group_jobs_running - 1, group_jobs_failed = group_jobs_failed + 1, @@ -107,7 +102,6 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job ELSEIF NEW.job_status = 999 AND OLD.job_status IN (150, 200) THEN UPDATE mxq_group SET - group_sum_starttime = group_sum_starttime - LEAST(group_sum_starttime, UNIX_TIMESTAMP(OLD.date_start) * OLD.host_slots), group_slots_running = group_slots_running - OLD.host_slots, group_jobs_running = group_jobs_running - 1, group_jobs_unknown = group_jobs_unknown + 1 @@ -125,7 +119,6 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job ELSEIF NEW.job_status = 1000 AND OLD.job_status IN (150, 200) THEN UPDATE mxq_group SET - group_sum_starttime = group_sum_starttime - LEAST(group_sum_starttime, UNIX_TIMESTAMP(OLD.date_start) * OLD.host_slots), group_slots_running = group_slots_running - OLD.host_slots, group_jobs_running = group_jobs_running - 1, group_jobs_finished = group_jobs_finished + 1, @@ -146,7 +139,6 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job ELSEIF NEW.job_status = 0 AND OLD.job_status IN (150) THEN UPDATE mxq_group SET - group_sum_starttime = group_sum_starttime - UNIX_TIMESTAMP(OLD.date_start) * NEW.host_slots, group_jobs_inq = group_jobs_inq + 1, group_jobs_running = group_jobs_running - 1, group_slots_running = group_slots_running - OLD.host_slots From 7777073bf1a3d29de2afb9409ba4e1fc59b1c788 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Sat, 23 Dec 2023 18:54:38 +0100 Subject: [PATCH 02/20] mx_mysql: Refactor error handling The current error handling in mx_mysql logs errors multiple times in different forms due to nested functions and the mapping of MySQL error codes to system error codes. This leads to unclear semantics and complicated code. The current error handling return the same error in errno and in the function return value which results in uneeded accesses to errno This commit introduces the following changes: * MySQL error strings are captured but not logged by the module. A new function mx_mysql_error() is provided for the caller to retrieve the latest error string. * System error codes are returned as the function value, but errno is not set. * It is now the caller's responsibility to log errors. This change reduces the object size of mx_mysql by 28%. Future commits will address error return values that do not relate to MySQL error strings. --- mx_mysql.c | 332 +++++++++++++++++------------------------------------ mx_mysql.h | 13 +-- 2 files changed, 110 insertions(+), 235 deletions(-) diff --git a/mx_mysql.c b/mx_mysql.c index 87e4789b..b29c7eda 100644 --- a/mx_mysql.c +++ b/mx_mysql.c @@ -20,36 +20,31 @@ #include "mx_util.h" #include "mx_log.h" -#define mx__mysql_log(lvl, mysql) \ - mx_log_ ## lvl("MySQL %s(): ERROR %u (%s): %s", \ - (mysql)->func, \ - mx__mysql_errno(mysql), \ - mx__mysql_sqlstate(mysql), \ - mx__mysql_error(mysql)) - -#define mx__mysql_stmt_log(lvl, stmt) \ - mx_log_ ## lvl("MySQL %s(): ERROR %u (%s): %s", \ - (stmt)->func, \ - mx__mysql_stmt_errno(stmt), \ - mx__mysql_stmt_sqlstate(stmt), \ - mx__mysql_stmt_error(stmt)) - -#define mx__mysql_log_emerg(mysql) mx__mysql_log(emerg, (mysql)) -#define mx__mysql_log_err(mysql) mx__mysql_log(err, (mysql)) -#define mx__mysql_log_warning(mysql) mx__mysql_log(warning, (mysql)) -#define mx__mysql_log_info(mysql) mx__mysql_log(info, (mysql)) -#define mx__mysql_log_debug(mysql) mx__mysql_log(debug, (mysql)) - -#define mx__mysql_stmt_log_emerg(stmt) mx__mysql_stmt_log(emerg, (stmt)) -#define mx__mysql_stmt_log_err(stmt) mx__mysql_stmt_log(err, (stmt)) -#define mx__mysql_stmt_log_warning(stmt) mx__mysql_stmt_log(warning, (stmt)) -#define mx__mysql_stmt_log_info(stmt) mx__mysql_stmt_log(info, (stmt)) -#define mx__mysql_stmt_log_debug(stmt) mx__mysql_stmt_log(debug, (stmt)) - static struct mx_mysql_stmt *mx_mysql_statement_prepare_with_bindings(struct mx_mysql *mysql, char *statement, struct mx_mysql_bind *param, struct mx_mysql_bind *result); /**********************************************************************/ +static char* mx_mysql_last_error; + +__attribute__((destructor)) +static void mx_mysql_exit(void) { + free(mx_mysql_last_error); +} + +static void mx_mysql_save_error(const char *err) { + size_t len = strlen(err); + mx_mysql_last_error = realloc(mx_mysql_last_error, len+1); + if (mx_mysql_last_error == NULL) { + mx_log_crit("out of memory"); + return; + } + strncpy(mx_mysql_last_error, err, len+1); +} + +char *mx_mysql_error(void) { + return mx_mysql_last_error == NULL ? "no error information" : mx_mysql_last_error; +} + static int mx__mysql_errno(struct mx_mysql *mysql) { unsigned int error; @@ -73,15 +68,6 @@ static const char *mx__mysql_error(struct mx_mysql *mysql) return mysql_error(mysql->mysql); } -static const char *mx__mysql_sqlstate(struct mx_mysql *mysql) -{ - mx_assert_return_NULL(mysql, EINVAL); - mx_assert_return_NULL(mysql->mysql, EBADF); - - /* no mysql errors possible */ - return mysql_sqlstate(mysql->mysql); -} - static int mx__mysql_stmt_errno(struct mx_mysql_stmt *stmt) { unsigned int error; @@ -96,39 +82,16 @@ static int mx__mysql_stmt_errno(struct mx_mysql_stmt *stmt) return (int)error; } -static const char *mx__mysql_stmt_error(struct mx_mysql_stmt *stmt) -{ - mx_assert_return_NULL(stmt, EINVAL); - mx_assert_return_NULL(stmt->stmt, EBADF); - - /* no mysql errors possible */ - return mysql_stmt_error(stmt->stmt); -} - -static const char *mx__mysql_stmt_sqlstate(struct mx_mysql_stmt *stmt) -{ - mx_assert_return_NULL(stmt, EINVAL); - mx_assert_return_NULL(stmt->stmt, EBADF); - - /* no mysql errors possible */ - return mysql_stmt_sqlstate(stmt->stmt); -} - static int mx__mysql_init(struct mx_mysql *mysql) { mx_assert_return_minus_errno(mysql, EINVAL); mx_assert_return_minus_errno(!mysql->mysql, EUCLEAN); - mysql->func = "mysql_init"; mysql->mysql = mysql_init(NULL); if (mysql->mysql) return 0; - - errno = ENOMEM; - - mx_log_debug("Error: MySQL mysql_init(): %m"); - - return -errno; + mx_mysql_save_error("out of memory"); + return -ENOMEM; } static int mx__mysql_options(struct mx_mysql *mysql, enum mysql_option option, const void *arg) @@ -138,13 +101,11 @@ static int mx__mysql_options(struct mx_mysql *mysql, enum mysql_option option, c mx_assert_return_minus_errno(mysql, EINVAL); mx_assert_return_minus_errno(mysql->mysql, EBADF); - mysql->func = "mysql_options"; res = mysql_options(mysql->mysql, option, arg); if (res == 0) return 0; - - mx__mysql_log_emerg(mysql); - return -(errno=EBADE); + mx_mysql_save_error(mysql_error(mysql->mysql)); + return -EBADE; } static int mx__mysql_real_connect(struct mx_mysql *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag) @@ -154,19 +115,18 @@ static int mx__mysql_real_connect(struct mx_mysql *mysql, const char *host, cons mx_assert_return_minus_errno(mysql, EINVAL); mx_assert_return_minus_errno(mysql->mysql, EBADF); - mysql->func = "mysql_real_connect"; m = mysql_real_connect(mysql->mysql, host, user, passwd, db, port, unix_socket, client_flag); if (m && m == mysql->mysql) return 0; - mx__mysql_log_warning(mysql); + mx_mysql_save_error(mysql_error(mysql->mysql)); switch (mx__mysql_errno(mysql)) { case CR_ALREADY_CONNECTED: - return -(errno=EALREADY); + return -EALREADY; case CR_OUT_OF_MEMORY: - return -(errno=ENOMEM); + return -ENOMEM; case CR_CONN_HOST_ERROR: case CR_CONNECTION_ERROR: @@ -176,19 +136,9 @@ static int mx__mysql_real_connect(struct mx_mysql *mysql, const char *host, cons case CR_VERSION_ERROR: case CR_SERVER_LOST: case CR_SERVER_GONE_ERROR: - return -(errno=EAGAIN); - - case CR_NAMEDPIPEOPEN_ERROR: - case CR_NAMEDPIPEWAIT_ERROR: - case CR_NAMEDPIPESETSTATE_ERROR: - mx__mysql_log_emerg(mysql); - mx_log_emerg("ERROR: mysql_real_connect() returned Windows error number: %d", mx__mysql_errno(mysql)); - return -(errno=EBADE); /* we are not on windows*/ + return -EAGAIN; } - - mx__mysql_log_emerg(mysql); - mx_log_emerg("ERROR: mysql_real_connect() returned undefined error number: %d", mx__mysql_errno(mysql)); - return -(errno=EBADE); + return -EBADE; } static int mx__mysql_ping(struct mx_mysql *mysql) @@ -198,20 +148,18 @@ static int mx__mysql_ping(struct mx_mysql *mysql) int res; - mysql->func = "mysql_ping"; res = mysql_ping(mysql->mysql); if (res == 0) return 0; - mx__mysql_log_warning(mysql); + mx_mysql_save_error(mysql_error(mysql->mysql)); switch (mx__mysql_errno(mysql)) { case CR_COMMANDS_OUT_OF_SYNC: - mx__mysql_log_emerg(mysql); - return -(errno=EPROTO); + return -EPROTO; case CR_OUT_OF_MEMORY: - return -(errno=ENOMEM); + return -ENOMEM; case CR_CONN_HOST_ERROR: case CR_CONNECTION_ERROR: @@ -221,15 +169,12 @@ static int mx__mysql_ping(struct mx_mysql *mysql) case CR_VERSION_ERROR: case CR_SERVER_LOST: case CR_SERVER_GONE_ERROR: - return -(errno=EAGAIN); + return -EAGAIN; case CR_UNKNOWN_ERROR: - return -(errno=EIO); + return -EIO; } - - mx__mysql_log_emerg(mysql); - mx_log_emerg("ERROR: mysql_ping() returned undefined error number: %d", mx__mysql_errno(mysql)); - return -(errno=EBADE); + return -EBADE; } static int mx__mysql_stmt_init(struct mx_mysql_stmt *stmt) @@ -238,19 +183,11 @@ static int mx__mysql_stmt_init(struct mx_mysql_stmt *stmt) mx_assert_return_minus_errno(!stmt->stmt, EUCLEAN); mx_assert_return_minus_errno(stmt->mysql, EBADF); - stmt->mysql->func = "mysql_stmt_init"; stmt->stmt = mysql_stmt_init(stmt->mysql->mysql); if (stmt->stmt) return 0; - - mx__mysql_log_warning(stmt->mysql); - - if (mx__mysql_errno(stmt->mysql) == CR_OUT_OF_MEMORY) - return -(errno=ENOMEM); - - mx__mysql_log_emerg(stmt->mysql); - mx_log_emerg("ERROR: mysql_stmt_init() returned undefined error number: %d", mx__mysql_errno(stmt->mysql)); - return -(errno=EBADE); + mx_mysql_save_error("out of memory"); + return -ENOMEM; } static int mx__mysql_stmt_prepare(struct mx_mysql_stmt *stmt, char *statement) @@ -266,38 +203,32 @@ static int mx__mysql_stmt_prepare(struct mx_mysql_stmt *stmt, char *statement) mx_assert_return_minus_errno(stmt->mysql, EBADF); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_prepare"; res = mysql_stmt_prepare(stmt->stmt, statement, strlen(statement)); if (res == 0) { stmt->statement = statement; return 0; } - mx__mysql_stmt_log_warning(stmt); + mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); switch (mx__mysql_stmt_errno(stmt)) { case CR_OUT_OF_MEMORY: - return -(errno=ENOMEM); + return -ENOMEM; case CR_COMMANDS_OUT_OF_SYNC: - mx__mysql_stmt_log_emerg(stmt); - return -(errno=EPROTO); + return -EPROTO; case CR_SERVER_GONE_ERROR: case CR_SERVER_LOST: - return -(errno=EAGAIN); + return -EAGAIN; case CR_UNKNOWN_ERROR: - return -(errno=EIO); + return -EIO; case ER_PARSE_ERROR: - mx__mysql_stmt_log_emerg(stmt); - return -(errno=EBADRQC); + return -EBADRQC; } - - mx__mysql_stmt_log_emerg(stmt); - mx_log_emerg("ERROR: mysql_stmt_prepare() returned undefined error number: %d", mx__mysql_stmt_errno(stmt)); - return -(errno=EBADE); + return -EBADE; } static int mx__mysql_stmt_bind_param(struct mx_mysql_stmt *stmt) @@ -307,28 +238,23 @@ static int mx__mysql_stmt_bind_param(struct mx_mysql_stmt *stmt) mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_bind_param"; res = (int)mysql_stmt_bind_param(stmt->stmt, stmt->param.bind); if (res == 0) return 0; - mx__mysql_stmt_log_warning(stmt); + mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); switch (mx__mysql_stmt_errno(stmt)) { case CR_OUT_OF_MEMORY: - return -(errno=ENOMEM); + return -ENOMEM; case CR_UNSUPPORTED_PARAM_TYPE: - mx__mysql_stmt_log_emerg(stmt); - return -(errno=EPROTO); + return -EPROTO; case CR_UNKNOWN_ERROR: - return -(errno=EIO); + return -EIO; } - - mx__mysql_stmt_log_emerg(stmt); - mx_log_emerg("ERROR: mysql_stmt_bind_param() returned undefined error number: %d", mx__mysql_stmt_errno(stmt)); - return -(errno=EBADE); + return -EBADE; } static int mx__mysql_stmt_bind_result(struct mx_mysql_stmt *stmt) @@ -338,27 +264,23 @@ static int mx__mysql_stmt_bind_result(struct mx_mysql_stmt *stmt) mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_bind_result"; res = (int)mysql_stmt_bind_result(stmt->stmt, stmt->result.bind); if (res == 0) return 0; - mx__mysql_stmt_log_warning(stmt); + mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); switch (mx__mysql_stmt_errno(stmt)) { case CR_OUT_OF_MEMORY: - return -(errno=ENOMEM); + return -ENOMEM; case CR_UNSUPPORTED_PARAM_TYPE: - mx__mysql_stmt_log_emerg(stmt); - return -(errno=EPROTO); + return -EPROTO; case CR_UNKNOWN_ERROR: - return -(errno=EIO); + return -EIO; } - mx__mysql_stmt_log_emerg(stmt); - mx_log_emerg("ERROR: mysql_stmt_bind_result() returned undefined error number: %d", mx__mysql_stmt_errno(stmt)); - return -(errno=EBADE); + return -EBADE; } static int mx__mysql_stmt_execute(struct mx_mysql_stmt *stmt) @@ -368,31 +290,27 @@ static int mx__mysql_stmt_execute(struct mx_mysql_stmt *stmt) mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_execute"; res = mysql_stmt_execute(stmt->stmt); if (res == 0) return 0; - mx__mysql_stmt_log_warning(stmt); + mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); switch (mx__mysql_stmt_errno(stmt)) { case CR_COMMANDS_OUT_OF_SYNC: - mx__mysql_stmt_log_emerg(stmt); - return -(errno=EPROTO); + return -EPROTO; case CR_OUT_OF_MEMORY: - return -(errno=ENOMEM); + return -ENOMEM; case CR_SERVER_GONE_ERROR: case CR_SERVER_LOST: - return -(errno=EAGAIN); + return -EAGAIN; case CR_UNKNOWN_ERROR: - return -(errno=EIO); + return -EIO; } - mx__mysql_stmt_log_emerg(stmt); - mx_log_emerg("ERROR: mysql_stmt_execute() returned undefined error number: %d", mx__mysql_stmt_errno(stmt)); - return -(errno=EBADE); + return -EBADE; } static int mx__mysql_stmt_store_result(struct mx_mysql_stmt *stmt) @@ -402,32 +320,27 @@ static int mx__mysql_stmt_store_result(struct mx_mysql_stmt *stmt) mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_store_result"; res = mysql_stmt_store_result(stmt->stmt); if (res == 0) return 0; - mx__mysql_stmt_log_warning(stmt); + mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); switch (mx__mysql_stmt_errno(stmt)) { case CR_COMMANDS_OUT_OF_SYNC: - mx__mysql_stmt_log_emerg(stmt); - return -(errno=EPROTO); + return -EPROTO; case CR_OUT_OF_MEMORY: - return -(errno=ENOMEM); + return -ENOMEM; case CR_SERVER_GONE_ERROR: case CR_SERVER_LOST: - return -(errno=EAGAIN); + return -EAGAIN; case CR_UNKNOWN_ERROR: - return -(errno=EIO); + return -EIO; } - - mx__mysql_stmt_log_emerg(stmt); - mx_log_emerg("ERROR: mysql_stmt_store_result() returned undefined error number: %d", mx__mysql_stmt_errno(stmt)); - return -(errno=EBADE); + return -EBADE; } static int mx__mysql_stmt_free_result(struct mx_mysql_stmt *stmt) @@ -437,14 +350,12 @@ static int mx__mysql_stmt_free_result(struct mx_mysql_stmt *stmt) mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_free_result"; res = (int)mysql_stmt_free_result(stmt->stmt); if (res == 0) return 0; - mx__mysql_stmt_log_emerg(stmt); - mx_log_emerg("ERROR: mysql_stmt_free_result() returned undefined error number: %d", mx__mysql_stmt_errno(stmt)); - return -(errno=EBADE); + mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); + return -EBADE; } static int mx__mysql_stmt_fetch(struct mx_mysql_stmt *stmt) @@ -454,47 +365,39 @@ static int mx__mysql_stmt_fetch(struct mx_mysql_stmt *stmt) mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_fetch"; res = mysql_stmt_fetch(stmt->stmt); if (res == 0) return 0; if (res == 1) { - mx__mysql_stmt_log_warning(stmt); + mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); switch (mx__mysql_stmt_errno(stmt)) { case CR_OUT_OF_MEMORY: - return -(errno=ENOMEM); + return -ENOMEM; case CR_SERVER_GONE_ERROR: case CR_SERVER_LOST: - return -(errno=EAGAIN); + return -EAGAIN; case CR_UNKNOWN_ERROR: - mx__mysql_stmt_log_emerg(stmt); - return -(errno=EIO); + return -EIO; case CR_COMMANDS_OUT_OF_SYNC: case CR_UNSUPPORTED_PARAM_TYPE: - mx__mysql_stmt_log_emerg(stmt); - return -(errno=EPROTO); + return -EPROTO; } - mx__mysql_stmt_log_emerg(stmt); - mx_log_emerg("ERROR: mysql_stmt_fetch() returned undefined error number: %d", mx__mysql_stmt_errno(stmt)); - return -(errno=EBADE); + return -EBADE; } switch (res) { case MYSQL_NO_DATA: - return -(errno=ENOENT); + return -ENOENT; case MYSQL_DATA_TRUNCATED: - return -(errno=ERANGE); + return -ERANGE; } - - mx__mysql_stmt_log_emerg(stmt); - mx_log_emerg("ERROR: mysql_stmt_fetch() returned undefined result code: %d", res); - return -(errno=EBADE); + return -EBADE; } static int mx__mysql_stmt_fetch_column(struct mx_mysql_stmt *stmt, unsigned int column, unsigned long offset) @@ -504,24 +407,19 @@ static int mx__mysql_stmt_fetch_column(struct mx_mysql_stmt *stmt, unsigned int mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_fetch_column"; res = mysql_stmt_fetch_column(stmt->stmt, &(stmt->result.bind[column]), column, offset); if (res == 0) return 0; - mx__mysql_stmt_log_warning(stmt); + mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); switch (mx__mysql_stmt_errno(stmt)) { case CR_INVALID_PARAMETER_NO: - mx__mysql_stmt_log_emerg(stmt); - return -(errno=EPROTO); + return -EPROTO; case CR_NO_DATA: - return -(errno=ENOENT); + return -ENOENT; } - - mx__mysql_stmt_log_emerg(stmt); - mx_log_emerg("ERROR: mysql_stmt_fetch_column() returned undefined error number: %d", mx__mysql_stmt_errno(stmt)); - return -(errno=EBADE); + return -EBADE; } static int mx__mysql_stmt_param_count(struct mx_mysql_stmt *stmt) @@ -531,7 +429,6 @@ static int mx__mysql_stmt_param_count(struct mx_mysql_stmt *stmt) mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_param_count"; count = mysql_stmt_param_count(stmt->stmt); mx_assert_return_minus_errno((unsigned long)(int)count == count, ERANGE); @@ -546,7 +443,6 @@ static int mx__mysql_stmt_field_count(struct mx_mysql_stmt *stmt) mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_field_count"; count = mysql_stmt_field_count(stmt->stmt); mx_assert_return_minus_errno((unsigned long)(int)count == count, ERANGE); @@ -561,7 +457,6 @@ static int mx__mysql_stmt_affected_rows(struct mx_mysql_stmt *stmt, unsigned lon mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_affected_rows"; c = mysql_stmt_affected_rows(stmt->stmt); *count = (unsigned long long)c; @@ -577,7 +472,6 @@ static int mx__mysql_stmt_insert_id(struct mx_mysql_stmt *stmt, unsigned long lo mx_assert_return_minus_errno(stmt, EINVAL); mx_assert_return_minus_errno(stmt->stmt, EBADF); - stmt->func = "mysql_stmt_insert_id"; c = mysql_stmt_insert_id(stmt->stmt); *count = (unsigned long long)c; @@ -592,33 +486,27 @@ static int mx__mysql_stmt_close(struct mx_mysql_stmt *stmt) mx_assert_return_minus_errno(stmt, EINVAL); - stmt->func = "mysql_stmt_close"; res = mysql_stmt_close(stmt->stmt); if (res == 0) { stmt->stmt = NULL; return 0; } - - mx__mysql_stmt_log_warning(stmt); + mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); switch (mx__mysql_stmt_errno(stmt)) { case CR_SERVER_GONE_ERROR: - return -(errno=ECONNABORTED); + return -ECONNABORTED; case CR_UNKNOWN_ERROR : - return -(errno=EIO); + return -EIO; } - - mx__mysql_stmt_log_emerg(stmt); - mx_log_emerg("ERROR: mysql_stmt_close() returned undefined error number: %d", mx__mysql_stmt_errno(stmt)); - return -(errno=EBADE); + return -EBADE; } static int mx__mysql_close(struct mx_mysql *mysql) { mx_assert_return_minus_errno(mysql, EINVAL); if (mysql->mysql) { - mysql->func = "mysql_close"; mysql_close(mysql->mysql); mysql->mysql = NULL; } @@ -703,7 +591,8 @@ static int _mx_mysql_bind_validate(struct mx_mysql_bind *b) for (unsigned long i=0; i < b->count; i++) { if (!(b->data[i].flags)) { - return -(errno=EBADSLT); + mx_mysql_save_error("binding not fully initialized"); + return -EBADSLT; } } @@ -740,7 +629,7 @@ static int mx_mysql_init(struct mx_mysql *mysql) if (res != -ENOMEM) return res; - mx_log_debug("mx__mysql_init() failed: %m - retrying (forever) in %d second(s).", MX_MYSQL_FAIL_WAIT_DEFAULT); + mx_log_debug("mx__mysql_init() failed: %s - retrying (forever) in %d second(s).", strerror(-res), MX_MYSQL_FAIL_WAIT_DEFAULT); mx_sleep(MX_MYSQL_FAIL_WAIT_DEFAULT); } while (1); @@ -848,9 +737,8 @@ int mx_mysql_connect_forever_sec(struct mx_mysql **mysql, unsigned int seconds) int res; while ((res = mx_mysql_connect(mysql)) < 0) { - mx__mysql_log_warning(*mysql); mx_mysql_assert_usage_ok(res); - mx_log_warning("mx_mysql_connect() failed: %m - retrying (forever) in %d second(s).", seconds); + mx_log_warning("mx_mysql_connect() failed: %s - retrying (forever) in %d second(s).", mx_mysql_error(), seconds); mx_sleep(seconds); } @@ -921,9 +809,8 @@ static int mx_mysql_ping_forever(struct mx_mysql *mysql) fail++; - mx__mysql_log_warning(mysql); mx_mysql_assert_usage_ok(res); - mx_log_warning("mx_mysql_ping() failed: %m - retrying again (forever) in %d second(s).", MX_MYSQL_FAIL_WAIT_DEFAULT); + mx_log_warning("mx_mysql_ping() failed: %s - retrying again (forever) in %d second(s).", mx_mysql_error(), MX_MYSQL_FAIL_WAIT_DEFAULT); mx_sleep(MX_MYSQL_FAIL_WAIT_DEFAULT); } @@ -945,7 +832,6 @@ static int mx_mysql_statement_init(struct mx_mysql *mysql, struct mx_mysql_stmt s = mx_calloc_forever(1, sizeof(*s)); s->mysql = mysql; - s->func = ""; do { res = mx__mysql_stmt_init(s); @@ -955,7 +841,7 @@ static int mx_mysql_statement_init(struct mx_mysql *mysql, struct mx_mysql_stmt if (res != -ENOMEM) return res; - mx_log_debug("mx__mysql_stmt_init() failed: %m - retrying (forever) in %d second(s).", MX_MYSQL_FAIL_WAIT_DEFAULT); + mx_log_debug("mx__mysql_stmt_init() failed: %s - retrying (forever) in %d second(s).", strerror(-res), MX_MYSQL_FAIL_WAIT_DEFAULT); mx_sleep(MX_MYSQL_FAIL_WAIT_DEFAULT); } while (1); @@ -973,32 +859,31 @@ int mx_mysql_statement_execute(struct mx_mysql_stmt *stmt, unsigned long long *c res = _mx_mysql_bind_validate(&stmt->param); if (res < 0) { - mx_log_crit("MxSQL: parameter list for prepared statement not initialized completely."); return res; } res = mx__mysql_stmt_bind_param(stmt); if (res < 0) { - mx_log_debug("ERROR: mx__mysql_stmt_bind_param: %m"); + mx_log_debug("ERROR: mx__mysql_stmt_bind_param: %s", strerror(-res)); return res; } res = mx__mysql_stmt_execute(stmt); if (res < 0) { - mx_log_debug("ERROR: mx__mysql_stmt_execute: %m"); + mx_log_debug("ERROR: mx__mysql_stmt_execute: %s", strerror(-res)); return res; } res = mx__mysql_stmt_store_result(stmt); if (res < 0) { - mx_log_debug("ERROR: mx__mysql_stmt_store_result: %m"); + mx_log_debug("ERROR: mx__mysql_stmt_store_result: %s", strerror(-res)); return res; } if (count) { res = mx__mysql_stmt_affected_rows(stmt, count); if (res < 0) { - mx_log_debug("ERROR: mx__mysql_stmt_affected_rows(): %m"); + mx_log_debug("ERROR: mx__mysql_stmt_affected_rows(): %s", strerror(-res)); return res; } } @@ -1028,7 +913,7 @@ int mx_mysql_statement_fetch(struct mx_mysql_stmt *stmt) res = mx__mysql_stmt_bind_result(stmt); if (res < 0) { - mx_log_debug("ERROR: mx__mysql_stmt_bind_result: %m"); + mx_log_debug("ERROR: mx__mysql_stmt_bind_result: %s", strerror(-res)); return res; } @@ -1037,7 +922,7 @@ int mx_mysql_statement_fetch(struct mx_mysql_stmt *stmt) return 0; if (res < 0 && res != -ERANGE) { - mx_log_debug("ERROR: mx__mysql_stmt_fetch: %m"); + mx_log_debug("ERROR: mx__mysql_stmt_fetch: %s", strerror(-res)); return res; } @@ -1067,7 +952,7 @@ int mx_mysql_statement_fetch(struct mx_mysql_stmt *stmt) } if (!no_error) - return -(errno=ERANGE); + return -ERANGE; return 0; } @@ -1171,23 +1056,20 @@ static int _mx_mysql_do_statement(struct mx_mysql *mysql, char *query, struct mx stmt = mx_mysql_statement_prepare_with_bindings(mysql, query, param, result); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare_with_bindings(): %m"); - mx_log_err("mx_mysql_statement_prepare_with_bindings(): query was: %s", query); if (cleanup) { mx_mysql_bind_cleanup(param); mx_mysql_bind_cleanup(result); } - return -errno; + return -EINVAL; } res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { - mx_log_err("mx_mysql_statement_execute(): %m"); if (cleanup) mx_mysql_statement_close(&stmt); else mx_mysql_statement_close_no_bind_cleanup(&stmt); - return -(errno=-res); + return res; } if (result && result->count && num_rows) { @@ -1196,13 +1078,12 @@ static int _mx_mysql_do_statement(struct mx_mysql *mysql, char *query, struct mx for (unsigned long cnt = 0; cnt < num_rows; cnt++) { res = mx_mysql_statement_fetch(stmt); if (res < 0) { - mx_log_err("mx_mysql_statement_fetch(): %m"); mx_free_null(tmpdata); if (cleanup) mx_mysql_statement_close(&stmt); else mx_mysql_statement_close_no_bind_cleanup(&stmt); - return -(errno=-res); + return res; } memcpy(tmpdata+(cnt*size), from, size); } @@ -1238,7 +1119,7 @@ int mx_mysql_do_statement_retry_on_fail(struct mx_mysql *mysql, char *query, str mx_mysql_assert_usage_ok(res); - mx_log_warning("mx_mysql_do_statement() failed: %m"); + mx_log_warning("mx_mysql_do_statement() failed: %s", strerror(-res)); if (res != -EAGAIN) break; @@ -1289,9 +1170,6 @@ static struct mx_mysql_stmt *mx_mysql_statement_prepare_with_bindings(struct mx_ return stmt; }; - if (res < 0) - mx__mysql_stmt_log_warning(stmt); - mx_mysql_statement_close_no_bind_cleanup(&stmt); return NULL; @@ -1342,7 +1220,7 @@ static int mx_mysql_bind_integer(struct mx_mysql_bind *b, unsigned int index, vo if (res == 0) return 0; - mx_log_debug("Failed to set index %d: %m", index); + mx_log_debug("Failed to set index %d: %s", index, strerror(-res)); return res; } @@ -1354,7 +1232,7 @@ int mx_mysql_bind_string(struct mx_mysql_bind *b, unsigned int index, char **val if (res == 0) return 0; - mx_log_debug("Failed to set index %d: %m", index); + mx_log_debug("Failed to set index %d: %s", index, strerror(-res)); return res; } diff --git a/mx_mysql.h b/mx_mysql.h index ae5f79e4..c09c3bb7 100644 --- a/mx_mysql.h +++ b/mx_mysql.h @@ -22,18 +22,15 @@ #define mx_mysql_assert_usage_ok(res) \ do { \ if ((res) < 0) { \ - assert((res) == -errno); \ - assert(errno != EINVAL); \ - assert(errno != EBADF); \ - assert(errno != EUCLEAN); \ + assert(res != EINVAL); \ + assert(res != EBADF); \ + assert(res != EUCLEAN); \ } \ } while (0) struct mx_mysql { MYSQL *mysql; - const char *func; - char *default_file; char *default_group; bool reconnect; @@ -74,8 +71,6 @@ struct mx_mysql_stmt { MYSQL_STMT *stmt; - const char *func; - unsigned long field_count; unsigned long param_count; @@ -149,4 +144,6 @@ int mx_mysql_bind_uint16(struct mx_mysql_bind *b, unsigned int index, uint16_t * int mx_mysql_bind_uint32(struct mx_mysql_bind *b, unsigned int index, uint32_t *value); int mx_mysql_bind_uint64(struct mx_mysql_bind *b, unsigned int index, uint64_t *value); +char *mx_mysql_error(void); + #endif From 9d045468305dfe21efd86d8e64aa11744a5b2895 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Sat, 23 Dec 2023 23:38:05 +0100 Subject: [PATCH 03/20] mx_mysql: Remove faulty errno range check The assertion mx_assert_return_minus_errno((unsigned int)(int)error == error, ERANGE); does not function as intended, as the conditional expression is optimized away to true by gcc with -O1 and up [1]. While there are alternatives to detect values outside of the range [0..-INT_MIN] that could not be negated into the range [INT_MIN..0], the check appears to be unnecessary. All callers use the MySQL error numbe for comparison with constants. This commit removes the helper functions `mx__mysql_errno()` and `mx__mysql_stmt_errno()` and replaces them with native MySQL calls. [1]: https://godbolt.org/z/1ajK384Ge --- mx_mysql.c | 48 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/mx_mysql.c b/mx_mysql.c index b29c7eda..3aa8daee 100644 --- a/mx_mysql.c +++ b/mx_mysql.c @@ -45,20 +45,6 @@ char *mx_mysql_error(void) { return mx_mysql_last_error == NULL ? "no error information" : mx_mysql_last_error; } -static int mx__mysql_errno(struct mx_mysql *mysql) -{ - unsigned int error; - - mx_assert_return_minus_errno(mysql, EINVAL); - mx_assert_return_minus_errno(mysql->mysql, EBADF); - - error = mysql_errno(mysql->mysql); - mx_assert_return_minus_errno((unsigned int)(int)error == error, ERANGE); - - /* no mysql errors possible */ - return (int)error; -} - static const char *mx__mysql_error(struct mx_mysql *mysql) { mx_assert_return_NULL(mysql, EINVAL); @@ -68,20 +54,6 @@ static const char *mx__mysql_error(struct mx_mysql *mysql) return mysql_error(mysql->mysql); } -static int mx__mysql_stmt_errno(struct mx_mysql_stmt *stmt) -{ - unsigned int error; - - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); - - error = mysql_stmt_errno(stmt->stmt); - mx_assert_return_minus_errno((unsigned int)(int)error == error, ERANGE); - - /* no mysql errors possible */ - return (int)error; -} - static int mx__mysql_init(struct mx_mysql *mysql) { mx_assert_return_minus_errno(mysql, EINVAL); @@ -121,7 +93,7 @@ static int mx__mysql_real_connect(struct mx_mysql *mysql, const char *host, cons mx_mysql_save_error(mysql_error(mysql->mysql)); - switch (mx__mysql_errno(mysql)) { + switch (mysql_errno(mysql->mysql)) { case CR_ALREADY_CONNECTED: return -EALREADY; @@ -154,7 +126,7 @@ static int mx__mysql_ping(struct mx_mysql *mysql) mx_mysql_save_error(mysql_error(mysql->mysql)); - switch (mx__mysql_errno(mysql)) { + switch (mysql_errno(mysql->mysql)) { case CR_COMMANDS_OUT_OF_SYNC: return -EPROTO; @@ -210,7 +182,7 @@ static int mx__mysql_stmt_prepare(struct mx_mysql_stmt *stmt, char *statement) } mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); - switch (mx__mysql_stmt_errno(stmt)) { + switch (mysql_stmt_errno(stmt->stmt)) { case CR_OUT_OF_MEMORY: return -ENOMEM; @@ -244,7 +216,7 @@ static int mx__mysql_stmt_bind_param(struct mx_mysql_stmt *stmt) mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); - switch (mx__mysql_stmt_errno(stmt)) { + switch (mysql_stmt_errno(stmt->stmt)) { case CR_OUT_OF_MEMORY: return -ENOMEM; @@ -270,7 +242,7 @@ static int mx__mysql_stmt_bind_result(struct mx_mysql_stmt *stmt) mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); - switch (mx__mysql_stmt_errno(stmt)) { + switch (mysql_stmt_errno(stmt->stmt)) { case CR_OUT_OF_MEMORY: return -ENOMEM; @@ -296,7 +268,7 @@ static int mx__mysql_stmt_execute(struct mx_mysql_stmt *stmt) mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); - switch (mx__mysql_stmt_errno(stmt)) { + switch (mysql_stmt_errno(stmt->stmt)) { case CR_COMMANDS_OUT_OF_SYNC: return -EPROTO; @@ -326,7 +298,7 @@ static int mx__mysql_stmt_store_result(struct mx_mysql_stmt *stmt) mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); - switch (mx__mysql_stmt_errno(stmt)) { + switch (mysql_stmt_errno(stmt->stmt)) { case CR_COMMANDS_OUT_OF_SYNC: return -EPROTO; @@ -372,7 +344,7 @@ static int mx__mysql_stmt_fetch(struct mx_mysql_stmt *stmt) if (res == 1) { mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); - switch (mx__mysql_stmt_errno(stmt)) { + switch (mysql_stmt_errno(stmt->stmt)) { case CR_OUT_OF_MEMORY: return -ENOMEM; @@ -412,7 +384,7 @@ static int mx__mysql_stmt_fetch_column(struct mx_mysql_stmt *stmt, unsigned int return 0; mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); - switch (mx__mysql_stmt_errno(stmt)) { + switch (mysql_stmt_errno(stmt->stmt)) { case CR_INVALID_PARAMETER_NO: return -EPROTO; @@ -493,7 +465,7 @@ static int mx__mysql_stmt_close(struct mx_mysql_stmt *stmt) } mx_mysql_save_error(mysql_stmt_error(stmt->stmt)); - switch (mx__mysql_stmt_errno(stmt)) { + switch (mysql_stmt_errno(stmt->stmt)) { case CR_SERVER_GONE_ERROR: return -ECONNABORTED; From 2e8005178e4ffe0fc9b294fbcd5ed3dcaeb9eee8 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 25 Dec 2023 15:22:45 +0100 Subject: [PATCH 04/20] mx_mysql: Fix warning in mx_mysql_option_set_default_file If the file is not readable, the warning is now saved to be retrievable by the caller instead of being emitted. The warning text has been shortened from: MySQL ignoring defaults file: euidaccess("/etc/mxq/mysql_ro.cnfX", R_OK) failed: No such file or directory MySQL falling back to mysql default config search path. to /etc/mxq/mysql_ro.cnfX: No such file or directory - falling back to mysql default config search path --- mx_mysql.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mx_mysql.c b/mx_mysql.c index 3aa8daee..c7d66759 100644 --- a/mx_mysql.c +++ b/mx_mysql.c @@ -41,6 +41,19 @@ static void mx_mysql_save_error(const char *err) { strncpy(mx_mysql_last_error, err, len+1); } +__attribute__ ((format (printf, 1, 2))) +static void mx_mysql_save_error_va(const char *restrict fmt, ...) { + char *s; + va_list ap; + va_start(ap, fmt); + int res = vasprintf(&s, fmt, ap); + va_end(ap); + if (res == -1) + return; + mx_mysql_save_error(s); + free(s); +} + char *mx_mysql_error(void) { return mx_mysql_last_error == NULL ? "no error information" : mx_mysql_last_error; } @@ -614,8 +627,7 @@ int mx_mysql_option_set_default_file(struct mx_mysql *mysql, char *fname) mx_assert_return_minus_errno(mysql, EINVAL); if (fname && (*fname == '/') && (euidaccess(fname, R_OK) != 0)) { - mx_log_warning("MySQL ignoring defaults file: euidaccess(\"%s\", R_OK) failed: %m", fname); - mx_log_warning("MySQL falling back to mysql default config search path."); + mx_mysql_save_error_va("%s: %m - falling back to mysql default config search path", fname); return -errno; } From 2302d0b1754337b3b9720350a4f5e7ee9e3acb8d Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 25 Dec 2023 16:54:00 +0100 Subject: [PATCH 05/20] global: Refactor error handling in mx_mysql callers `mx_mysql` no longer delivers errors in `errno`, so this commit changes the callers to not use `errno` after a failed call to a `mx_mysql` function, but only the return value. The "%m" format for getting the error message is replaced with "%s" in conjunction with `mx_mysql_error()`. This commit also removes some redundant error logging from nested function calls. --- mxq_daemon.c | 14 +++++++------- mxq_group.c | 12 ++++++------ mxq_job.c | 19 ++++++++----------- mxqadmin.c | 12 ++++++------ mxqkill.c | 12 ++++++------ mxqset.c | 30 +++++++++++++++--------------- mxqsub.c | 32 ++++++++++++++++---------------- test_mx_mysql.c | 2 +- 8 files changed, 65 insertions(+), 68 deletions(-) diff --git a/mxq_daemon.c b/mxq_daemon.c index d0236887..66e7d320 100644 --- a/mxq_daemon.c +++ b/mxq_daemon.c @@ -103,9 +103,9 @@ int mxq_daemon_register(struct mx_mysql *mysql, struct mxq_daemon *daemon) " prerequisites = ?" ); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); - return -errno; + return -EINVAL; } idx = 0; @@ -134,7 +134,7 @@ int mxq_daemon_register(struct mx_mysql *mysql, struct mxq_daemon *daemon) res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return res; } @@ -178,7 +178,7 @@ int mxq_daemon_shutdown(struct mx_mysql *mysql, struct mxq_daemon *daemon) res += mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } @@ -221,7 +221,7 @@ int mxq_daemon_mark_crashed(struct mx_mysql *mysql, struct mxq_daemon *daemon) res += mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } @@ -260,7 +260,7 @@ int mxq_daemon_set_status(struct mx_mysql *mysql, struct mxq_daemon *daemon, uin res += mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } @@ -305,7 +305,7 @@ int mxq_daemon_update_statistics(struct mx_mysql *mysql, struct mxq_daemon *daem res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } diff --git a/mxq_group.c b/mxq_group.c index a354f424..d6527ecb 100644 --- a/mxq_group.c +++ b/mxq_group.c @@ -192,7 +192,7 @@ int mxq_load_group(struct mx_mysql *mysql, struct mxq_group **mxq_groups, uint64 res = mx_mysql_do_statement(mysql, query, ¶m, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } @@ -222,7 +222,7 @@ int mxq_load_all_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups) res = mx_mysql_do_statement(mysql, query, NULL, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } @@ -259,7 +259,7 @@ int mxq_load_all_groups_for_user(struct mx_mysql *mysql, struct mxq_group **mxq_ res = mx_mysql_do_statement(mysql, query, ¶m, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } @@ -298,7 +298,7 @@ int mxq_load_active_groups_for_user(struct mx_mysql *mysql, struct mxq_group **m res = mx_mysql_do_statement(mysql, query, ¶m, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } @@ -329,7 +329,7 @@ int mxq_load_running_groups(struct mx_mysql *mysql, struct mxq_group **mxq_group res = mx_mysql_do_statement(mysql, query, NULL, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } @@ -367,7 +367,7 @@ int mxq_load_running_groups_for_user(struct mx_mysql *mysql, struct mxq_group ** res = mx_mysql_do_statement(mysql, query, ¶m, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } diff --git a/mxq_job.c b/mxq_job.c index ba8a606a..44437a38 100644 --- a/mxq_job.c +++ b/mxq_job.c @@ -169,7 +169,7 @@ static int do_jobs_statement(struct mx_mysql *mysql, char *query, struct mx_mysq res = mx_mysql_do_statement(mysql, query, param, &result, &j, (void **)jobs, sizeof(**jobs)); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } for (i=0;ijob_id); return 0; } if (res == 0) { @@ -837,7 +834,7 @@ int mxq_unload_job_from_server(struct mx_mysql *mysql, uint64_t job_id) { res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { - mx_log_err("mx_mysql_do_statement(): %m"); + mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; } return res; diff --git a/mxqadmin.c b/mxqadmin.c index 713f209f..ac3817a2 100644 --- a/mxqadmin.c +++ b/mxqadmin.c @@ -89,7 +89,7 @@ static int update_group_flags_closed(struct mx_mysql *mysql, uint64_t group_id, " AND user_uid = ?" ); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); return -(errno=EIO); } @@ -101,7 +101,7 @@ static int update_group_flags_closed(struct mx_mysql *mysql, uint64_t group_id, res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); @@ -128,7 +128,7 @@ static int update_group_flags_reopen(struct mx_mysql *mysql, uint64_t group_id, " AND user_uid = ?" ); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); return -(errno=EIO); } @@ -140,7 +140,7 @@ static int update_group_flags_reopen(struct mx_mysql *mysql, uint64_t group_id, res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); @@ -164,7 +164,7 @@ int _close_group_for_user(struct mx_mysql *mysql, uint64_t group_id, uint64_t us } if (res < 0) { - mx_log_err("closing group failed: %m"); + mx_log_err("closing group failed"); return res; } @@ -187,7 +187,7 @@ int _reopen_group_for_user(struct mx_mysql *mysql, uint64_t group_id, uint64_t u } if (res < 0) { - mx_log_err("opening group failed: %m"); + mx_log_err("opening group failed"); return res; } diff --git a/mxqkill.c b/mxqkill.c index af4b602b..90077e13 100644 --- a/mxqkill.c +++ b/mxqkill.c @@ -90,7 +90,7 @@ static int update_group_status_cancelled(struct mx_mysql *mysql, struct mxq_grou " AND group_jobs-group_jobs_finished-group_jobs_failed-group_jobs_cancelled-group_jobs_unknown > 0" ); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); return -(errno=EIO); } @@ -101,7 +101,7 @@ static int update_group_status_cancelled(struct mx_mysql *mysql, struct mxq_grou res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); @@ -130,7 +130,7 @@ static int update_job_status_cancelled_by_group(struct mx_mysql *mysql, struct m " AND host_pid = 0" ); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); return -(errno=EIO); } @@ -140,7 +140,7 @@ static int update_job_status_cancelled_by_group(struct mx_mysql *mysql, struct m res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); @@ -473,7 +473,7 @@ int main(int argc, char *argv[]) mx_log_warning("no active group with group_id=%lu found for user=%s(%d)", group.group_id, group.user_name, group.user_uid); else - mx_log_err("cancelling group failed: %m"); + mx_log_err("cancelling group failed"); return 1; } @@ -497,7 +497,7 @@ int main(int argc, char *argv[]) group.group_id); return 0; } else { - mx_log_err("cancelling jobs failed: %m"); + mx_log_err("cancelling jobs failed"); return 1; } } diff --git a/mxqset.c b/mxqset.c index 126471f6..bf205385 100644 --- a/mxqset.c +++ b/mxqset.c @@ -28,15 +28,15 @@ static void verify_group_permission(struct mx_mysql *mysql , long unsigned group stmt = mx_mysql_statement_prepare(mysql,"SELECT user_uid FROM mxq_group WHERE group_id = ? LIMIT 1"); if (!stmt) - die("%m\n"); + die("%s\n", mx_mysql_error()); mx_mysql_statement_param_bind(stmt, 0, uint64, &(groupid)); if (mx_mysql_statement_execute(stmt, &num_rows) < 0) - die("%m\n"); + die("%s\n", mx_mysql_error()); if (num_rows < 1) die("no such group %ld\n", groupid); mx_mysql_statement_result_bind(stmt, 0, uint32, &uid); if (mx_mysql_statement_fetch(stmt) < 0) - die("%m\n"); + die("%s\n", mx_mysql_error()); if ( client_uid != 0 && client_uid != uid ) die("no permission to access this group\n"); mx_mysql_statement_close(&stmt); @@ -59,12 +59,12 @@ static void update_closed_flag(struct mx_mysql *mysql, long unsigned groupid, en stmt = mx_mysql_statement_prepare(mysql, "UPDATE mxq_group SET group_flags = ( group_flags & ?) | ? WHERE group_id = ?"); if (!stmt) - die("%m\n"); + die("%s\n", mx_mysql_error()); mx_mysql_statement_param_bind(stmt, 0, uint64, &(mask)); mx_mysql_statement_param_bind(stmt, 1, uint64, &(value)); mx_mysql_statement_param_bind(stmt, 2, uint64, &(groupid)); if (mx_mysql_statement_execute(stmt, &num_rows) < 0) - die("%m\n"); + die("%s\n", mx_mysql_error()); if (num_rows < 1) die("no such group %ld\n", groupid); mx_mysql_statement_close(&stmt); @@ -81,15 +81,15 @@ static void update_blacklist(struct mx_mysql *mysql, long unsigned groupid, char stmt = mx_mysql_statement_prepare(mysql, "SELECT group_blacklist FROM mxq_group WHERE group_id = ? LIMIT 1"); if (!stmt) - die("%m\n"); + die("%s\n", mx_mysql_error()); mx_mysql_statement_param_bind(stmt, 0, uint64, &groupid); if (mx_mysql_statement_execute(stmt, &num_rows) < 0) - die("%m\n"); + die("%s\n", mx_mysql_error()); if (num_rows < 1) die("no such group %ld\n", groupid); mx_mysql_statement_result_bind(stmt, 0, string, &group_blacklist); if (mx_mysql_statement_fetch(stmt) < 0) - die("%m\n"); + die("%s\n", mx_mysql_error()); mx_mysql_statement_close(&stmt); blacklist = keywordset_new(group_blacklist); free(group_blacklist); @@ -103,11 +103,11 @@ static void update_blacklist(struct mx_mysql *mysql, long unsigned groupid, char stmt = mx_mysql_statement_prepare(mysql, "UPDATE mxq_group SET group_blacklist = ? WHERE group_id = ?"); if (!stmt) - die("%m\n"); + die("%s\n", mx_mysql_error()); mx_mysql_statement_param_bind(stmt, 0, string, &group_blacklist); mx_mysql_statement_param_bind(stmt, 1, uint64, &groupid); if (mx_mysql_statement_execute(stmt, &num_rows) < 0) - die("%m\n"); + die("%s\n", mx_mysql_error()); if (num_rows < 1) die("no such group %ld\n", groupid); mx_mysql_statement_close(&stmt); @@ -126,15 +126,15 @@ static void update_whitelist(struct mx_mysql *mysql, long unsigned groupid, char stmt = mx_mysql_statement_prepare(mysql, "SELECT group_whitelist FROM mxq_group WHERE group_id = ? LIMIT 1"); if (!stmt) - die("%m\n"); + die("%s\n", mx_mysql_error()); mx_mysql_statement_param_bind(stmt, 0, uint64, &groupid); if (mx_mysql_statement_execute(stmt, &num_rows) < 0) - die("%m\n"); + die("%s\n", mx_mysql_error()); if (num_rows < 1) die("no such group %ld\n", groupid); mx_mysql_statement_result_bind(stmt, 0, string, &group_whitelist); if (mx_mysql_statement_fetch(stmt) < 0) - die("%m\n"); + die("%s\n", mx_mysql_error()); mx_mysql_statement_close(&stmt); whitelist = keywordset_new(group_whitelist); free(group_whitelist); @@ -148,11 +148,11 @@ static void update_whitelist(struct mx_mysql *mysql, long unsigned groupid, char stmt = mx_mysql_statement_prepare(mysql, "UPDATE mxq_group SET group_whitelist = ? WHERE group_id = ?"); if (!stmt) - die("%m\n"); + die("%s\n", mx_mysql_error()); mx_mysql_statement_param_bind(stmt, 0, string, &group_whitelist); mx_mysql_statement_param_bind(stmt, 1, uint64, &groupid); if (mx_mysql_statement_execute(stmt, &num_rows) < 0) - die("%m\n"); + die("%s\n", mx_mysql_error()); if (num_rows < 1) die("no such group %ld\n", groupid); mx_mysql_statement_close(&stmt); diff --git a/mxqsub.c b/mxqsub.c index a23383be..526a5d47 100644 --- a/mxqsub.c +++ b/mxqsub.c @@ -179,7 +179,7 @@ static int load_group_id(struct mx_mysql *mysql, struct mxq_group *g) " ORDER BY group_id DESC" " LIMIT 1"); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); return -errno; } @@ -205,7 +205,7 @@ static int load_group_id(struct mx_mysql *mysql, struct mxq_group *g) res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return res; } @@ -217,7 +217,7 @@ static int load_group_id(struct mx_mysql *mysql, struct mxq_group *g) res = mx_mysql_statement_fetch(stmt); if (res < 0) { - mx_log_err("mx_mysql_statement_fetch(): %m"); + mx_log_err("mx_mysql_statement_fetch(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return res; } @@ -275,7 +275,7 @@ static int load_group_id_by_group_id(struct mx_mysql *mysql, struct mxq_group *g " ORDER BY group_id DESC" " LIMIT 1"); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); return -errno; } @@ -302,7 +302,7 @@ static int load_group_id_by_group_id(struct mx_mysql *mysql, struct mxq_group *g res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return res; } @@ -368,7 +368,7 @@ static int load_group_id_run_or_wait(struct mx_mysql *mysql, struct mxq_group *g " ORDER BY group_id DESC" " LIMIT 1"); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); return -errno; } @@ -394,7 +394,7 @@ static int load_group_id_run_or_wait(struct mx_mysql *mysql, struct mxq_group *g res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return res; } @@ -405,7 +405,7 @@ static int load_group_id_run_or_wait(struct mx_mysql *mysql, struct mxq_group *g res = mx_mysql_statement_fetch(stmt); if (res < 0) { - mx_log_err("mx_mysql_statement_fetch(): %m"); + mx_log_err("mx_mysql_statement_fetch(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return res; } @@ -453,7 +453,7 @@ static int add_group(struct mx_mysql *mysql, struct mxq_group *g) " prerequisites = ?," " tags = ?"); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); return -errno; } @@ -478,7 +478,7 @@ static int add_group(struct mx_mysql *mysql, struct mxq_group *g) res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return res; } @@ -530,7 +530,7 @@ static int add_job(struct mx_mysql *mysql, struct mxq_job *j) " job_flags = ?" ); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return -errno; } @@ -549,7 +549,7 @@ static int add_job(struct mx_mysql *mysql, struct mxq_job *j) res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return res; } @@ -579,13 +579,13 @@ static int get_active_groups_for_user(struct mx_mysql *mysql, char *username) " WHERE user_name = ?" " AND (group_jobs_inq > 0 OR group_jobs_running > 0)"); if (!stmt) { - mx_log_err("mx_mysql_statement_prepare(): %m"); + mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); return -errno; } mx_mysql_statement_param_bind(stmt, 0, string, &username); res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { - mx_log_err("mx_mysql_statement_execute(): %m"); + mx_log_err("mx_mysql_statement_execute(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return res; } @@ -593,7 +593,7 @@ static int get_active_groups_for_user(struct mx_mysql *mysql, char *username) mx_mysql_statement_result_bind(stmt, 0, uint64, &count); res = mx_mysql_statement_fetch(stmt); if (res < 0) { - mx_log_err("mx_mysql_statement_fetch(): %m"); + mx_log_err("mx_mysql_statement_fetch(): %s", mx_mysql_error()); mx_mysql_statement_close(&stmt); return res; } @@ -1193,7 +1193,7 @@ int main(int argc, char *argv[]) if (res < 0) { if (res != -ENOENT && res != -EDQUOT) - mx_log_err("Job submission failed: %m"); + mx_log_err("Job submission failed."); return 1; } diff --git a/test_mx_mysql.c b/test_mx_mysql.c index 3d1d0c9f..03a4714c 100644 --- a/test_mx_mysql.c +++ b/test_mx_mysql.c @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) res = mx_mysql_statement_fetch(stmt); assert(res == 0); - mx_log_debug("mx_mysql_statement_fetch(): %m"); + mx_log_debug("mx_mysql_statement_fetch(): %s", mx_mysql_error()); mx_log_debug("&group_name = 0x%x", &group_name); From 6cb040138af791dad02df9143f49a1dc88c3f35c Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 25 Dec 2023 15:47:36 +0100 Subject: [PATCH 06/20] mx_mysql: Use standard assert() Currently, `mx_mysql` uses its own assert macros, which log the failed condition and then return an error value to the caller (via return status and via errno). This commit changes the approach to use the standard `assert()` to abort right away in case of failures, as all `assert()` failures are serious coding errors. This simplifies the coding for the callers. --- mx_mysql.c | 203 +++++++++++++++++++++++++++-------------------------- mx_mysql.h | 13 ---- 2 files changed, 102 insertions(+), 114 deletions(-) diff --git a/mx_mysql.c b/mx_mysql.c index c7d66759..a047ead2 100644 --- a/mx_mysql.c +++ b/mx_mysql.c @@ -15,6 +15,7 @@ #include #include +#include #include "mx_mysql.h" #include "mx_util.h" @@ -60,8 +61,8 @@ char *mx_mysql_error(void) { static const char *mx__mysql_error(struct mx_mysql *mysql) { - mx_assert_return_NULL(mysql, EINVAL); - mx_assert_return_NULL(mysql->mysql, EBADF); + assert(mysql); + assert(mysql->mysql); /* no mysql errors possible */ return mysql_error(mysql->mysql); @@ -69,8 +70,8 @@ static const char *mx__mysql_error(struct mx_mysql *mysql) static int mx__mysql_init(struct mx_mysql *mysql) { - mx_assert_return_minus_errno(mysql, EINVAL); - mx_assert_return_minus_errno(!mysql->mysql, EUCLEAN); + assert(mysql); + assert(!mysql->mysql); mysql->mysql = mysql_init(NULL); if (mysql->mysql) @@ -83,8 +84,8 @@ static int mx__mysql_options(struct mx_mysql *mysql, enum mysql_option option, c { int res; - mx_assert_return_minus_errno(mysql, EINVAL); - mx_assert_return_minus_errno(mysql->mysql, EBADF); + assert(mysql); + assert(mysql->mysql); res = mysql_options(mysql->mysql, option, arg); if (res == 0) @@ -97,8 +98,8 @@ static int mx__mysql_real_connect(struct mx_mysql *mysql, const char *host, cons { MYSQL *m; - mx_assert_return_minus_errno(mysql, EINVAL); - mx_assert_return_minus_errno(mysql->mysql, EBADF); + assert(mysql); + assert(mysql->mysql); m = mysql_real_connect(mysql->mysql, host, user, passwd, db, port, unix_socket, client_flag); if (m && m == mysql->mysql) @@ -128,8 +129,8 @@ static int mx__mysql_real_connect(struct mx_mysql *mysql, const char *host, cons static int mx__mysql_ping(struct mx_mysql *mysql) { - mx_assert_return_minus_errno(mysql, EINVAL); - mx_assert_return_minus_errno(mysql->mysql, EBADF); + assert(mysql); + assert(mysql->mysql); int res; @@ -164,9 +165,9 @@ static int mx__mysql_ping(struct mx_mysql *mysql) static int mx__mysql_stmt_init(struct mx_mysql_stmt *stmt) { - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(!stmt->stmt, EUCLEAN); - mx_assert_return_minus_errno(stmt->mysql, EBADF); + assert(stmt); + assert(!stmt->stmt); + assert(stmt->mysql); stmt->stmt = mysql_stmt_init(stmt->mysql->mysql); if (stmt->stmt) @@ -179,14 +180,14 @@ static int mx__mysql_stmt_prepare(struct mx_mysql_stmt *stmt, char *statement) { int res; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(statement, EINVAL); - mx_assert_return_minus_errno(*statement, EINVAL); + assert(stmt); + assert(statement); + assert(*statement); - mx_assert_return_minus_errno(!stmt->statement, EUCLEAN); + assert(!stmt->statement); - mx_assert_return_minus_errno(stmt->mysql, EBADF); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt->mysql); + assert(stmt->stmt); res = mysql_stmt_prepare(stmt->stmt, statement, strlen(statement)); if (res == 0) { @@ -220,8 +221,8 @@ static int mx__mysql_stmt_bind_param(struct mx_mysql_stmt *stmt) { int res; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); res = (int)mysql_stmt_bind_param(stmt->stmt, stmt->param.bind); if (res == 0) @@ -246,8 +247,8 @@ static int mx__mysql_stmt_bind_result(struct mx_mysql_stmt *stmt) { int res; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); res = (int)mysql_stmt_bind_result(stmt->stmt, stmt->result.bind); if (res == 0) @@ -272,8 +273,8 @@ static int mx__mysql_stmt_execute(struct mx_mysql_stmt *stmt) { int res; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); res = mysql_stmt_execute(stmt->stmt); if (res == 0) @@ -302,8 +303,8 @@ static int mx__mysql_stmt_store_result(struct mx_mysql_stmt *stmt) { int res; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); res = mysql_stmt_store_result(stmt->stmt); if (res == 0) @@ -332,8 +333,8 @@ static int mx__mysql_stmt_free_result(struct mx_mysql_stmt *stmt) { int res; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); res = (int)mysql_stmt_free_result(stmt->stmt); if (res == 0) @@ -347,8 +348,8 @@ static int mx__mysql_stmt_fetch(struct mx_mysql_stmt *stmt) { int res; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); res = mysql_stmt_fetch(stmt->stmt); if (res == 0) @@ -389,8 +390,8 @@ static int mx__mysql_stmt_fetch_column(struct mx_mysql_stmt *stmt, unsigned int { int res; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); res = mysql_stmt_fetch_column(stmt->stmt, &(stmt->result.bind[column]), column, offset); if (res == 0) @@ -411,11 +412,11 @@ static int mx__mysql_stmt_param_count(struct mx_mysql_stmt *stmt) { unsigned long count; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); count = mysql_stmt_param_count(stmt->stmt); - mx_assert_return_minus_errno((unsigned long)(int)count == count, ERANGE); + assert(count <= INT_MAX); /* no mysql errors possible */ return (int)count; @@ -425,11 +426,11 @@ static int mx__mysql_stmt_field_count(struct mx_mysql_stmt *stmt) { unsigned long count; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); count = mysql_stmt_field_count(stmt->stmt); - mx_assert_return_minus_errno((unsigned long)(int)count == count, ERANGE); + assert(count <= INT_MAX); /* no mysql errors possible */ return (int)count; @@ -439,8 +440,8 @@ static int mx__mysql_stmt_affected_rows(struct mx_mysql_stmt *stmt, unsigned lon { my_ulonglong c; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); c = mysql_stmt_affected_rows(stmt->stmt); @@ -454,8 +455,8 @@ static int mx__mysql_stmt_insert_id(struct mx_mysql_stmt *stmt, unsigned long lo { my_ulonglong c; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); c = mysql_stmt_insert_id(stmt->stmt); @@ -469,7 +470,7 @@ static int mx__mysql_stmt_close(struct mx_mysql_stmt *stmt) { bool res; - mx_assert_return_minus_errno(stmt, EINVAL); + assert(stmt); res = mysql_stmt_close(stmt->stmt); if (res == 0) { @@ -489,7 +490,7 @@ static int mx__mysql_stmt_close(struct mx_mysql_stmt *stmt) } static int mx__mysql_close(struct mx_mysql *mysql) { - mx_assert_return_minus_errno(mysql, EINVAL); + assert(mysql); if (mysql->mysql) { mysql_close(mysql->mysql); @@ -510,12 +511,12 @@ static int mx__mysql_library_end(void) { static int _mx_mysql_bind_integer(struct mx_mysql_bind *b, unsigned int index, void *value, int type, int is_unsigned) { - mx_assert_return_minus_errno(b, EINVAL); - mx_assert_return_minus_errno(value, EINVAL); + assert(b); + assert(value); - mx_assert_return_minus_errno(index < b->count, ERANGE); + assert(index < b->count); - mx_assert_return_minus_errno(!(b->data[index].flags), EUCLEAN); + assert(!(b->data[index].flags)); memset(&(b->bind[index]), 0, sizeof(b->bind[index])); @@ -533,14 +534,14 @@ static int _mx_mysql_bind_integer(struct mx_mysql_bind *b, unsigned int index, v static int _mx_mysql_bind_string(struct mx_mysql_bind *b, unsigned int index, char **value) { - mx_assert_return_minus_errno(b, EINVAL); - mx_assert_return_minus_errno(value, EINVAL); + assert(b); + assert(value); - mx_assert_return_minus_errno(index < b->count, ERANGE); + assert(index < b->count); - mx_assert_return_minus_errno(!(b->data[index].flags), EUCLEAN); + assert(!(b->data[index].flags)); - mx_assert_return_minus_errno((*value && b->type == MX_MYSQL_BIND_TYPE_PARAM) || (!*value && b->type == MX_MYSQL_BIND_TYPE_RESULT), EBADF); + assert((*value && b->type == MX_MYSQL_BIND_TYPE_PARAM) || (!*value && b->type == MX_MYSQL_BIND_TYPE_RESULT)); memset(&(b->bind[index]), 0, sizeof(b->bind[index])); @@ -572,7 +573,7 @@ static int _mx_mysql_bind_string(struct mx_mysql_bind *b, unsigned int index, ch static int _mx_mysql_bind_validate(struct mx_mysql_bind *b) { - mx_assert_return_minus_errno(b, EINVAL); + assert(b); for (unsigned long i=0; i < b->count; i++) { if (!(b->data[i].flags)) { @@ -590,8 +591,8 @@ int mx_mysql_initialize(struct mx_mysql **mysql) { struct mx_mysql *m; - mx_assert_return_minus_errno(mysql, EINVAL); - mx_assert_return_minus_errno(!(*mysql), EUCLEAN); + assert(mysql); + assert(!(*mysql)); m = mx_calloc_forever(1, sizeof(*m)); @@ -604,7 +605,7 @@ static int mx_mysql_init(struct mx_mysql *mysql) { int res; - mx_assert_return_minus_errno(mysql, EINVAL); + assert(mysql); do { res = mx__mysql_init(mysql); @@ -624,7 +625,7 @@ static int mx_mysql_init(struct mx_mysql *mysql) int mx_mysql_option_set_default_file(struct mx_mysql *mysql, char *fname) { - mx_assert_return_minus_errno(mysql, EINVAL); + assert(mysql); if (fname && (*fname == '/') && (euidaccess(fname, R_OK) != 0)) { mx_mysql_save_error_va("%s: %m - falling back to mysql default config search path", fname); @@ -641,7 +642,7 @@ int mx_mysql_option_set_default_file(struct mx_mysql *mysql, char *fname) int mx_mysql_option_set_default_group(struct mx_mysql *mysql, char *group) { - mx_assert_return_minus_errno(mysql, EINVAL); + assert(mysql); if (group && !(*group)) group = NULL; @@ -653,7 +654,7 @@ int mx_mysql_option_set_default_group(struct mx_mysql *mysql, char *group) int mx_mysql_option_set_reconnect(struct mx_mysql *mysql, int reconnect) { - mx_assert_return_minus_errno(mysql, EINVAL); + assert(mysql); mysql->reconnect = (bool)!!reconnect; return 0; @@ -663,8 +664,8 @@ static int mx_mysql_real_connect(struct mx_mysql *mysql, const char *host, const { int res; - mx_assert_return_minus_errno(mysql, EINVAL); - mx_assert_return_minus_errno(mysql->mysql, EBADF); + assert(mysql); + assert(mysql->mysql); if (mysql->default_file) { res = mx__mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, mysql->default_file); @@ -699,7 +700,7 @@ int mx_mysql_connect(struct mx_mysql **mysql) { int res; - mx_assert_return_minus_errno(mysql, EINVAL); + assert(mysql); if (!(*mysql)) { res = mx_mysql_initialize(mysql); @@ -730,7 +731,7 @@ int mx_mysql_connect_forever_sec(struct mx_mysql **mysql, unsigned int seconds) } int mx_mysql_disconnect(struct mx_mysql *mysql) { - mx_assert_return_minus_errno(mysql, EINVAL); + assert(mysql); return mx__mysql_close(mysql); } @@ -741,9 +742,9 @@ static int mx_mysql_end(void) { static int mx_mysql_free(struct mx_mysql **mysql) { - mx_assert_return_minus_errno(mysql, EINVAL); - mx_assert_return_minus_errno(*mysql, EBADF); - mx_assert_return_minus_errno(!((*mysql)->mysql), EUCLEAN); + assert(mysql); + assert(*mysql); + assert(!((*mysql)->mysql)); mx_free_null(*mysql); @@ -774,7 +775,7 @@ int mx_mysql_finish(struct mx_mysql **mysql) static int mx_mysql_ping(struct mx_mysql *mysql) { - mx_assert_return_minus_errno(mysql, EINVAL); + assert(mysql); return mx__mysql_ping(mysql); } @@ -784,7 +785,7 @@ static int mx_mysql_ping_forever(struct mx_mysql *mysql) int res; int fail = 0; - mx_assert_return_minus_errno(mysql, EINVAL); + assert(mysql); while (1) { res = mx_mysql_ping(mysql); @@ -809,9 +810,9 @@ static int mx_mysql_statement_init(struct mx_mysql *mysql, struct mx_mysql_stmt struct mx_mysql_stmt *s; int res; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(mysql, EINVAL); - mx_assert_return_minus_errno(!(*stmt), EUCLEAN); + assert(stmt); + assert(mysql); + assert(!(*stmt)); s = mx_calloc_forever(1, sizeof(*s)); @@ -838,8 +839,8 @@ int mx_mysql_statement_execute(struct mx_mysql_stmt *stmt, unsigned long long *c { int res; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); res = _mx_mysql_bind_validate(&stmt->param); if (res < 0) { @@ -886,8 +887,8 @@ int mx_mysql_statement_fetch(struct mx_mysql_stmt *stmt) char *str; int no_error = 1; - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); res = _mx_mysql_bind_validate(&stmt->result); if (res < 0) { @@ -943,21 +944,21 @@ int mx_mysql_statement_fetch(struct mx_mysql_stmt *stmt) int mx_mysql_statement_param_count(struct mx_mysql_stmt *stmt) { - mx_assert_return_minus_errno(stmt, EINVAL); + assert(stmt); return mx__mysql_stmt_param_count(stmt); } int mx_mysql_statement_field_count(struct mx_mysql_stmt *stmt) { - mx_assert_return_minus_errno(stmt, EINVAL); + assert(stmt); return mx__mysql_stmt_field_count(stmt); } static int mx_mysql_stmt_field_count_set(struct mx_mysql_stmt *stmt) { - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); stmt->field_count = mysql_stmt_field_count(stmt->stmt); @@ -966,8 +967,8 @@ static int mx_mysql_stmt_field_count_set(struct mx_mysql_stmt *stmt) static int mx_mysql_stmt_param_count_set(struct mx_mysql_stmt *stmt) { - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(stmt->stmt, EBADF); + assert(stmt); + assert(stmt->stmt); stmt->param_count = mysql_stmt_param_count(stmt->stmt); @@ -989,11 +990,11 @@ static int mx_mysql_bind_cleanup(struct mx_mysql_bind *bind) static int mx_mysql_bind_init_from(struct mx_mysql_bind *bind, unsigned long count, enum mx_mysql_bind_type type, struct mx_mysql_bind *from) { - mx_assert_return_minus_errno(bind, EINVAL); + assert(bind); - mx_assert_return_minus_errno(!bind->count, EUCLEAN); - mx_assert_return_minus_errno(!bind->bind, EUCLEAN); - mx_assert_return_minus_errno(!bind->data, EUCLEAN); + assert(!bind->count); + assert(!bind->bind); + assert(!bind->data); if (from) { assert(count == from->count); @@ -1009,11 +1010,11 @@ static int mx_mysql_bind_init_from(struct mx_mysql_bind *bind, unsigned long cou int mx_mysql_bind_init(struct mx_mysql_bind *bind, unsigned long count, enum mx_mysql_bind_type type) { - mx_assert_return_minus_errno(bind, EINVAL); + assert(bind); - mx_assert_return_minus_errno(!bind->count, EUCLEAN); - mx_assert_return_minus_errno(!bind->bind, EUCLEAN); - mx_assert_return_minus_errno(!bind->data, EUCLEAN); + assert(!bind->count); + assert(!bind->bind); + assert(!bind->data); bind->type = type; bind->count = count; @@ -1122,9 +1123,9 @@ static struct mx_mysql_stmt *mx_mysql_statement_prepare_with_bindings(struct mx_ int res; struct mx_mysql_stmt *stmt = NULL; - mx_assert_return_NULL(mysql, EINVAL); - mx_assert_return_NULL(statement, EINVAL); - mx_assert_return_NULL(*statement, EINVAL); + assert(mysql); + assert(statement); + assert(*statement); res = mx_mysql_statement_init(mysql, &stmt); if (res < 0) @@ -1161,17 +1162,17 @@ static struct mx_mysql_stmt *mx_mysql_statement_prepare_with_bindings(struct mx_ struct mx_mysql_stmt *mx_mysql_statement_prepare(struct mx_mysql *mysql, char *statement) { - mx_assert_return_NULL(mysql, EINVAL); - mx_assert_return_NULL(statement, EINVAL); - mx_assert_return_NULL(*statement, EINVAL); + assert(mysql); + assert(statement); + assert(*statement); return mx_mysql_statement_prepare_with_bindings(mysql, statement, NULL, NULL); } int mx_mysql_statement_close(struct mx_mysql_stmt **stmt) { - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(*stmt, EINVAL); + assert(stmt); + assert(*stmt); mx__mysql_stmt_free_result(*stmt); mx__mysql_stmt_close(*stmt); @@ -1185,8 +1186,8 @@ int mx_mysql_statement_close(struct mx_mysql_stmt **stmt) int mx_mysql_statement_close_no_bind_cleanup(struct mx_mysql_stmt **stmt) { - mx_assert_return_minus_errno(stmt, EINVAL); - mx_assert_return_minus_errno(*stmt, EINVAL); + assert(stmt); + assert(*stmt); mx__mysql_stmt_free_result(*stmt); mx__mysql_stmt_close(*stmt); diff --git a/mx_mysql.h b/mx_mysql.h index c09c3bb7..fd9c5a8a 100644 --- a/mx_mysql.h +++ b/mx_mysql.h @@ -6,19 +6,6 @@ #include "mx_util.h" -#ifdef MX_NDEBUG_MYSQL -# include -# define mx_mysql_assert_return_minus_errno(test, eno) \ - assert(test) -# define mx_mysql_assert_return_NULL(test, eno) \ - assert(test) -#else -# define mx_mysql_assert_return_minus_errno(test, eno) \ - mx_assert_return_minus_errno(test, eno) -# define mx_mysql_assert_return_NULL(test, eno) \ - mx_assert_return_NULL(test, eno) -#endif - #define mx_mysql_assert_usage_ok(res) \ do { \ if ((res) < 0) { \ From 51259a9001aa8de524b3a9361aeff0533f6cb1bd Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 26 Dec 2023 20:20:27 +0100 Subject: [PATCH 07/20] mx_mysql: Refactor bind functions to void Following the last commit, the bind functions and macros of `mx_mysql` can no longer return a failure status. This commit changes them to void functions, simplifying the callers. --- mx_mysql.c | 69 +++++---------- mx_mysql.h | 20 ++--- mxq_daemon.c | 89 ++++++++----------- mxq_group.c | 144 +++++++++++++----------------- mxq_job.c | 245 +++++++++++++++++++++------------------------------ mxqadmin.c | 14 ++- mxqkill.c | 16 ++-- mxqsub.c | 169 +++++++++++++++++------------------ 8 files changed, 331 insertions(+), 435 deletions(-) diff --git a/mx_mysql.c b/mx_mysql.c index a047ead2..ea3a8e59 100644 --- a/mx_mysql.c +++ b/mx_mysql.c @@ -532,7 +532,7 @@ static int _mx_mysql_bind_integer(struct mx_mysql_bind *b, unsigned int index, v return 0; } -static int _mx_mysql_bind_string(struct mx_mysql_bind *b, unsigned int index, char **value) +void mx_mysql_bind_string(struct mx_mysql_bind *b, unsigned int index, char **value) { assert(b); assert(value); @@ -568,7 +568,6 @@ static int _mx_mysql_bind_string(struct mx_mysql_bind *b, unsigned int index, ch } b->data[index].flags = 1; - return 0; } static int _mx_mysql_bind_validate(struct mx_mysql_bind *b) @@ -988,7 +987,7 @@ static int mx_mysql_bind_cleanup(struct mx_mysql_bind *bind) return 0; } -static int mx_mysql_bind_init_from(struct mx_mysql_bind *bind, unsigned long count, enum mx_mysql_bind_type type, struct mx_mysql_bind *from) +static void mx_mysql_bind_init_from(struct mx_mysql_bind *bind, unsigned long count, enum mx_mysql_bind_type type, struct mx_mysql_bind *from) { assert(bind); @@ -1002,13 +1001,13 @@ static int mx_mysql_bind_init_from(struct mx_mysql_bind *bind, unsigned long cou assert(from->bind); assert(from->data); memcpy(bind, from, sizeof(*bind)); - return 0; + return; } - return mx_mysql_bind_init(bind, count, type); + mx_mysql_bind_init(bind, count, type); } -int mx_mysql_bind_init(struct mx_mysql_bind *bind, unsigned long count, enum mx_mysql_bind_type type) +void mx_mysql_bind_init(struct mx_mysql_bind *bind, unsigned long count, enum mx_mysql_bind_type type) { assert(bind); @@ -1020,12 +1019,10 @@ int mx_mysql_bind_init(struct mx_mysql_bind *bind, unsigned long count, enum mx_ bind->count = count; if (!count) - return 0; + return; bind->bind = mx_calloc_forever(bind->count, sizeof(*bind->bind)); bind->data = mx_calloc_forever(bind->count, sizeof(*bind->data)); - - return 0; } static int _mx_mysql_do_statement(struct mx_mysql *mysql, char *query, struct mx_mysql_bind *param, struct mx_mysql_bind *result, void *from, void **to, size_t size, char cleanup) @@ -1144,13 +1141,8 @@ static struct mx_mysql_stmt *mx_mysql_statement_prepare_with_bindings(struct mx_ if (res < 0) break; - res = mx_mysql_bind_init_from(&stmt->param, stmt->param_count, MX_MYSQL_BIND_TYPE_PARAM, param); - if (res < 0) - break; - - res = mx_mysql_bind_init_from(&stmt->result, stmt->field_count, MX_MYSQL_BIND_TYPE_RESULT, result); - if (res < 0) - break; + mx_mysql_bind_init_from(&stmt->param, stmt->param_count, MX_MYSQL_BIND_TYPE_PARAM, param); + mx_mysql_bind_init_from(&stmt->result, stmt->field_count, MX_MYSQL_BIND_TYPE_RESULT, result); return stmt; }; @@ -1209,55 +1201,42 @@ static int mx_mysql_bind_integer(struct mx_mysql_bind *b, unsigned int index, vo return res; } -int mx_mysql_bind_string(struct mx_mysql_bind *b, unsigned int index, char **value) -{ - int res; - - res = _mx_mysql_bind_string(b, index, value); - if (res == 0) - return 0; - - mx_log_debug("Failed to set index %d: %s", index, strerror(-res)); - return res; - -} - -int mx_mysql_bind_int8(struct mx_mysql_bind *b, unsigned int index, int8_t *value) +void mx_mysql_bind_int8(struct mx_mysql_bind *b, unsigned int index, int8_t *value) { - return mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_TINY, 0); + mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_TINY, 0); } -int mx_mysql_bind_uint8(struct mx_mysql_bind *b, unsigned int index, uint8_t *value) +void mx_mysql_bind_uint8(struct mx_mysql_bind *b, unsigned int index, uint8_t *value) { - return mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_TINY, 1); + mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_TINY, 1); } -int mx_mysql_bind_int16(struct mx_mysql_bind *b, unsigned int index, int16_t *value) +void mx_mysql_bind_int16(struct mx_mysql_bind *b, unsigned int index, int16_t *value) { - return mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_SHORT, 0); + mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_SHORT, 0); } -int mx_mysql_bind_uint16(struct mx_mysql_bind *b, unsigned int index, uint16_t *value) +void mx_mysql_bind_uint16(struct mx_mysql_bind *b, unsigned int index, uint16_t *value) { - return mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_SHORT, 1); + mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_SHORT, 1); } -int mx_mysql_bind_int32(struct mx_mysql_bind *b, unsigned int index, int32_t *value) +void mx_mysql_bind_int32(struct mx_mysql_bind *b, unsigned int index, int32_t *value) { - return mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_LONG, 0); + mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_LONG, 0); } -int mx_mysql_bind_uint32(struct mx_mysql_bind *b, unsigned int index, uint32_t *value) +void mx_mysql_bind_uint32(struct mx_mysql_bind *b, unsigned int index, uint32_t *value) { - return mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_LONG, 1); + mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_LONG, 1); } -int mx_mysql_bind_int64(struct mx_mysql_bind *b, unsigned int index, int64_t *value) +void mx_mysql_bind_int64(struct mx_mysql_bind *b, unsigned int index, int64_t *value) { - return mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_LONGLONG, 0); + mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_LONGLONG, 0); } -int mx_mysql_bind_uint64(struct mx_mysql_bind *b, unsigned int index, uint64_t *value) +void mx_mysql_bind_uint64(struct mx_mysql_bind *b, unsigned int index, uint64_t *value) { - return mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_LONGLONG, 1); + mx_mysql_bind_integer(b, index, (void *)value, MYSQL_TYPE_LONGLONG, 1); } diff --git a/mx_mysql.h b/mx_mysql.h index fd9c5a8a..c7f6e768 100644 --- a/mx_mysql.h +++ b/mx_mysql.h @@ -117,19 +117,19 @@ int mx_mysql_statement_close_no_bind_cleanup(struct mx_mysql_stmt **stmt); #define mx_mysql_bind_init_param(b, c) mx_mysql_bind_init((b), (c), MX_MYSQL_BIND_TYPE_PARAM) #define mx_mysql_bind_init_result(b, c) mx_mysql_bind_init((b), (c), MX_MYSQL_BIND_TYPE_RESULT) -int mx_mysql_bind_init(struct mx_mysql_bind *bind, unsigned long count, enum mx_mysql_bind_type type); +void mx_mysql_bind_init(struct mx_mysql_bind *bind, unsigned long count, enum mx_mysql_bind_type type); -int mx_mysql_bind_string(struct mx_mysql_bind *b, unsigned int index, char **value); +void mx_mysql_bind_string(struct mx_mysql_bind *b, unsigned int index, char **value); -int mx_mysql_bind_int8(struct mx_mysql_bind *b, unsigned int index, int8_t *value); -int mx_mysql_bind_int16(struct mx_mysql_bind *b, unsigned int index, int16_t *value); -int mx_mysql_bind_int32(struct mx_mysql_bind *b, unsigned int index, int32_t *value); -int mx_mysql_bind_int64(struct mx_mysql_bind *b, unsigned int index, int64_t *value); +void mx_mysql_bind_int8(struct mx_mysql_bind *b, unsigned int index, int8_t *value); +void mx_mysql_bind_int16(struct mx_mysql_bind *b, unsigned int index, int16_t *value); +void mx_mysql_bind_int32(struct mx_mysql_bind *b, unsigned int index, int32_t *value); +void mx_mysql_bind_int64(struct mx_mysql_bind *b, unsigned int index, int64_t *value); -int mx_mysql_bind_uint8(struct mx_mysql_bind *b, unsigned int index, uint8_t *value); -int mx_mysql_bind_uint16(struct mx_mysql_bind *b, unsigned int index, uint16_t *value); -int mx_mysql_bind_uint32(struct mx_mysql_bind *b, unsigned int index, uint32_t *value); -int mx_mysql_bind_uint64(struct mx_mysql_bind *b, unsigned int index, uint64_t *value); +void mx_mysql_bind_uint8(struct mx_mysql_bind *b, unsigned int index, uint8_t *value); +void mx_mysql_bind_uint16(struct mx_mysql_bind *b, unsigned int index, uint16_t *value); +void mx_mysql_bind_uint32(struct mx_mysql_bind *b, unsigned int index, uint32_t *value); +void mx_mysql_bind_uint64(struct mx_mysql_bind *b, unsigned int index, uint64_t *value); char *mx_mysql_error(void); diff --git a/mxq_daemon.c b/mxq_daemon.c index 66e7d320..ead607b5 100644 --- a/mxq_daemon.c +++ b/mxq_daemon.c @@ -110,27 +110,25 @@ int mxq_daemon_register(struct mx_mysql *mysql, struct mxq_daemon *daemon) idx = 0; - res = mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->daemon_name)); - res += mx_mysql_statement_param_bind(stmt, idx++, uint8, &(daemon->status)); - res += mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->hostname)); - res += mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->mxq_version)); - res += mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->boot_id)); - - res += mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->pid_starttime)); - res += mx_mysql_statement_param_bind(stmt, idx++, uint32, &(daemon->daemon_pid)); - - res += mx_mysql_statement_param_bind(stmt, idx++, uint32, &(daemon->daemon_slots)); - res += mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_memory)); - res += mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_maxtime)); - - res += mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_memory_limit_slot_soft)); - res += mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_memory_limit_slot_hard)); - res += mx_mysql_statement_param_bind(stmt, idx++, uint16, &(daemon->gpus_max)); - res += mx_mysql_statement_param_bind(stmt, idx++, int32, &(daemon->daemon_flags)); - res += mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->tags)); - res += mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->prerequisites)); - - assert(res ==0); + mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->daemon_name)); + mx_mysql_statement_param_bind(stmt, idx++, uint8, &(daemon->status)); + mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->hostname)); + mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->mxq_version)); + mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->boot_id)); + + mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->pid_starttime)); + mx_mysql_statement_param_bind(stmt, idx++, uint32, &(daemon->daemon_pid)); + + mx_mysql_statement_param_bind(stmt, idx++, uint32, &(daemon->daemon_slots)); + mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_memory)); + mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_maxtime)); + + mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_memory_limit_slot_soft)); + mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_memory_limit_slot_hard)); + mx_mysql_statement_param_bind(stmt, idx++, uint16, &(daemon->gpus_max)); + mx_mysql_statement_param_bind(stmt, idx++, int32, &(daemon->daemon_flags)); + mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->tags)); + mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->prerequisites)); res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { @@ -168,15 +166,13 @@ int mxq_daemon_shutdown(struct mx_mysql *mysql, struct mxq_daemon *daemon) " status = " status_str(MXQ_DAEMON_STATUS_EXITED) " WHERE daemon_id = ?"; - res = mx_mysql_bind_init_param(¶m, 1); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 1); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_id)); + mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_id)); assert(res == 0); - res += mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); + res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; @@ -209,17 +205,14 @@ int mxq_daemon_mark_crashed(struct mx_mysql *mysql, struct mxq_daemon *daemon) " AND hostname = ?" " AND daemon_name = ?"; - res = mx_mysql_bind_init_param(¶m, 3); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 3); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint32, &daemon->daemon_id); - res += mx_mysql_bind_var(¶m, idx++, string, &daemon->hostname); - res += mx_mysql_bind_var(¶m, idx++, string, &daemon->daemon_name); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, uint32, &daemon->daemon_id); + mx_mysql_bind_var(¶m, idx++, string, &daemon->hostname); + mx_mysql_bind_var(¶m, idx++, string, &daemon->daemon_name); - res += mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); + res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; @@ -249,16 +242,13 @@ int mxq_daemon_set_status(struct mx_mysql *mysql, struct mxq_daemon *daemon, uin " status = ?" " WHERE daemon_id = ?"; - res = mx_mysql_bind_init_param(¶m, 2); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 2); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint8, &(status)); - res += mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_id)); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, uint8, &(status)); + mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_id)); - res += mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); + res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; @@ -290,18 +280,15 @@ int mxq_daemon_update_statistics(struct mx_mysql *mysql, struct mxq_daemon *daem " daemon_gpus_used = ?" " WHERE daemon_id = ?"; - res = mx_mysql_bind_init_param(¶m, 6); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 6); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_jobs_running)); - res += mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_slots_running)); - res += mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_threads_running)); - res += mx_mysql_bind_var(¶m, idx++, uint64, &(daemon->daemon_memory_used)); - res += mx_mysql_bind_var(¶m, idx++, uint16, &(daemon->gpus_used)); - res += mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_id)); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_jobs_running)); + mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_slots_running)); + mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_threads_running)); + mx_mysql_bind_var(¶m, idx++, uint64, &(daemon->daemon_memory_used)); + mx_mysql_bind_var(¶m, idx++, uint16, &(daemon->gpus_used)); + mx_mysql_bind_var(¶m, idx++, uint32, &(daemon->daemon_id)); res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { diff --git a/mxq_group.c b/mxq_group.c index d6527ecb..8d44c363 100644 --- a/mxq_group.c +++ b/mxq_group.c @@ -52,62 +52,58 @@ " stats_idle_sec" -static int bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_group *g) +static void bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_group *g) { - int res = 0; int idx = 0; - res = mx_mysql_bind_init_result(result, GROUP_FIELDS_CNT); - assert(res >= 0); - - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_id)); - res += mx_mysql_bind_var(result, idx++, string, &(g->group_name)); - res += mx_mysql_bind_var(result, idx++, uint8, &(g->group_status)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_flags)); - res += mx_mysql_bind_var(result, idx++, uint16, &(g->group_priority)); - res += mx_mysql_bind_var(result, idx++, string, &(g->group_blacklist)); - res += mx_mysql_bind_var(result, idx++, string, &(g->group_whitelist)); - res += mx_mysql_bind_var(result, idx++, string, &(g->prerequisites)); - res += mx_mysql_bind_var(result, idx++, string, &(g->tags)); - - res += mx_mysql_bind_var(result, idx++, uint32, &(g->user_uid)); - res += mx_mysql_bind_var(result, idx++, string, &(g->user_name)); - res += mx_mysql_bind_var(result, idx++, uint32, &(g->user_gid)); - res += mx_mysql_bind_var(result, idx++, string, &(g->user_group)); - - res += mx_mysql_bind_var(result, idx++, string, &(g->job_command)); - - res += mx_mysql_bind_var(result, idx++, uint16, &(g->job_threads)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->job_memory)); - res += mx_mysql_bind_var(result, idx++, uint32, &(g->job_time)); - res += mx_mysql_bind_var(result, idx++, uint32, &(g->job_tmpdir_size)); - - res += mx_mysql_bind_var(result, idx++, uint16, &(g->job_max_per_node)); - res += mx_mysql_bind_var(result, idx++, uint16, &(g->job_gpu)); - - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_inq)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_running)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_finished)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_failed)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_cancelled)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_unknown)); - - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_restarted)); - - res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_slots_running)); - - res += mx_mysql_bind_var(result, idx++, uint64, &(g->stats_max_sumrss)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->stats_max_maxrss)); - res += mx_mysql_bind_var(result, idx++, int64, &(g->stats_max_utime.tv_sec)); - res += mx_mysql_bind_var(result, idx++, int64, &(g->stats_max_stime.tv_sec)); - res += mx_mysql_bind_var(result, idx++, int64, &(g->stats_max_real.tv_sec)); - - res += mx_mysql_bind_var(result, idx++, uint64, &(g->stats_wait_sec)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->stats_run_sec)); - res += mx_mysql_bind_var(result, idx++, uint64, &(g->stats_idle_sec)); - - return res; + mx_mysql_bind_init_result(result, GROUP_FIELDS_CNT); + + mx_mysql_bind_var(result, idx++, uint64, &(g->group_id)); + mx_mysql_bind_var(result, idx++, string, &(g->group_name)); + mx_mysql_bind_var(result, idx++, uint8, &(g->group_status)); + mx_mysql_bind_var(result, idx++, uint64, &(g->group_flags)); + mx_mysql_bind_var(result, idx++, uint16, &(g->group_priority)); + mx_mysql_bind_var(result, idx++, string, &(g->group_blacklist)); + mx_mysql_bind_var(result, idx++, string, &(g->group_whitelist)); + mx_mysql_bind_var(result, idx++, string, &(g->prerequisites)); + mx_mysql_bind_var(result, idx++, string, &(g->tags)); + + mx_mysql_bind_var(result, idx++, uint32, &(g->user_uid)); + mx_mysql_bind_var(result, idx++, string, &(g->user_name)); + mx_mysql_bind_var(result, idx++, uint32, &(g->user_gid)); + mx_mysql_bind_var(result, idx++, string, &(g->user_group)); + + mx_mysql_bind_var(result, idx++, string, &(g->job_command)); + + mx_mysql_bind_var(result, idx++, uint16, &(g->job_threads)); + mx_mysql_bind_var(result, idx++, uint64, &(g->job_memory)); + mx_mysql_bind_var(result, idx++, uint32, &(g->job_time)); + mx_mysql_bind_var(result, idx++, uint32, &(g->job_tmpdir_size)); + + mx_mysql_bind_var(result, idx++, uint16, &(g->job_max_per_node)); + mx_mysql_bind_var(result, idx++, uint16, &(g->job_gpu)); + + mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs)); + mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_inq)); + mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_running)); + mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_finished)); + mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_failed)); + mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_cancelled)); + mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_unknown)); + + mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_restarted)); + + mx_mysql_bind_var(result, idx++, uint64, &(g->group_slots_running)); + + mx_mysql_bind_var(result, idx++, uint64, &(g->stats_max_sumrss)); + mx_mysql_bind_var(result, idx++, uint64, &(g->stats_max_maxrss)); + mx_mysql_bind_var(result, idx++, int64, &(g->stats_max_utime.tv_sec)); + mx_mysql_bind_var(result, idx++, int64, &(g->stats_max_stime.tv_sec)); + mx_mysql_bind_var(result, idx++, int64, &(g->stats_max_real.tv_sec)); + + mx_mysql_bind_var(result, idx++, uint64, &(g->stats_wait_sec)); + mx_mysql_bind_var(result, idx++, uint64, &(g->stats_run_sec)); + mx_mysql_bind_var(result, idx++, uint64, &(g->stats_idle_sec)); } void mxq_group_free_content(struct mxq_group *g) @@ -182,13 +178,10 @@ int mxq_load_group(struct mx_mysql *mysql, struct mxq_group **mxq_groups, uint64 " WHERE group_id = ?" " LIMIT 1"; - res = mx_mysql_bind_init_param(¶m, 1); - assert(res == 0); - res = mx_mysql_bind_var(¶m, 0, uint64, &group_id); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 1); + mx_mysql_bind_var(¶m, 0, uint64, &group_id); - res = bind_result_group_fields(&result, &g); - assert(res == 0); + bind_result_group_fields(&result, &g); res = mx_mysql_do_statement(mysql, query, ¶m, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { @@ -217,8 +210,7 @@ int mxq_load_all_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups) " FROM mxq_group" " ORDER BY user_name, group_mtime"; - res = bind_result_group_fields(&result, &g); - assert(res == 0); + bind_result_group_fields(&result, &g); res = mx_mysql_do_statement(mysql, query, NULL, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { @@ -249,13 +241,10 @@ int mxq_load_all_groups_for_user(struct mx_mysql *mysql, struct mxq_group **mxq_ " WHERE user_uid = ?" " ORDER BY user_name, group_mtime"; - res = mx_mysql_bind_init_param(¶m, 1); - assert(res == 0); - res = mx_mysql_bind_var(¶m, 0, uint64, &user_uid); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 1); + mx_mysql_bind_var(¶m, 0, uint64, &user_uid); - res = bind_result_group_fields(&result, &g); - assert(res == 0); + bind_result_group_fields(&result, &g); res = mx_mysql_do_statement(mysql, query, ¶m, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { @@ -288,13 +277,10 @@ int mxq_load_active_groups_for_user(struct mx_mysql *mysql, struct mxq_group **m " AND user_uid = ?" " ORDER BY user_name, group_mtime"; - res = mx_mysql_bind_init_param(¶m, 1); - assert(res == 0); - res = mx_mysql_bind_var(¶m, 0, uint64, &user_uid); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 1); + mx_mysql_bind_var(¶m, 0, uint64, &user_uid); - res = bind_result_group_fields(&result, &g); - assert(res == 0); + bind_result_group_fields(&result, &g); res = mx_mysql_do_statement(mysql, query, ¶m, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { @@ -324,8 +310,7 @@ int mxq_load_running_groups(struct mx_mysql *mysql, struct mxq_group **mxq_group " WHERE (group_jobs_inq > 0 OR group_jobs_running > 0)" " ORDER BY user_name, group_mtime"; - res = bind_result_group_fields(&result, &g); - assert(res == 0); + bind_result_group_fields(&result, &g); res = mx_mysql_do_statement(mysql, query, NULL, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { @@ -357,13 +342,10 @@ int mxq_load_running_groups_for_user(struct mx_mysql *mysql, struct mxq_group ** " AND user_uid = ?" " ORDER BY user_name, group_mtime"; - res = mx_mysql_bind_init_param(¶m, 1); - assert(res == 0); - res = mx_mysql_bind_var(¶m, 0, uint64, &user_uid); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 1); + mx_mysql_bind_var(¶m, 0, uint64, &user_uid); - res = bind_result_group_fields(&result, &g); - assert(res == 0); + bind_result_group_fields(&result, &g); res = mx_mysql_do_statement(mysql, query, ¶m, &result, &g, (void **)&groups, sizeof(*groups)); if (res < 0) { diff --git a/mxq_job.c b/mxq_job.c index 44437a38..b9942927 100644 --- a/mxq_job.c +++ b/mxq_job.c @@ -59,54 +59,50 @@ " stats_nvcsw, " \ " stats_nivcsw" -static int bind_result_job_fields(struct mx_mysql_bind *result, struct mxq_job *j) +static void bind_result_job_fields(struct mx_mysql_bind *result, struct mxq_job *j) { - int res = 0; int idx = 0; - res = mx_mysql_bind_init_result(result, JOB_FIELDS_CNT); - assert(res >= 0); - - res += mx_mysql_bind_var(result, idx++, uint64, &(j->job_id)); - res += mx_mysql_bind_var(result, idx++, uint16, &(j->job_status)); - res += mx_mysql_bind_var(result, idx++, uint64, &(j->job_flags)); - res += mx_mysql_bind_var(result, idx++, uint16, &(j->job_priority)); - res += mx_mysql_bind_var(result, idx++, uint64, &(j->group_id)); - res += mx_mysql_bind_var(result, idx++, string, &(j->job_workdir)); - res += mx_mysql_bind_var(result, idx++, uint32, &(j->job_argc)); - res += mx_mysql_bind_var(result, idx++, string, &(j->job_argv_str)); - res += mx_mysql_bind_var(result, idx++, string, &(j->job_stdout)); - res += mx_mysql_bind_var(result, idx++, string, &(j->job_stderr)); - res += mx_mysql_bind_var(result, idx++, uint32, &(j->job_umask)); - res += mx_mysql_bind_var(result, idx++, string, &(j->host_submit)); - res += mx_mysql_bind_var(result, idx++, string, &(j->host_id)); - res += mx_mysql_bind_var(result, idx++, uint32, &(j->daemon_id)); - res += mx_mysql_bind_var(result, idx++, string, &(j->daemon_name)); - res += mx_mysql_bind_var(result, idx++, string, &(j->host_hostname)); - res += mx_mysql_bind_var(result, idx++, uint32, &(j->host_pid)); - res += mx_mysql_bind_var(result, idx++, uint32, &(j->host_slots)); - res += mx_mysql_bind_var(result, idx++, string, &(j->host_cpu_set_str)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->date_submit)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->date_start)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->date_end)); - res += mx_mysql_bind_var(result, idx++, uint64, &(j->stats_max_sumrss)); - res += mx_mysql_bind_var(result, idx++, int32, &(j->stats_status)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_utime.tv_sec)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_utime.tv_usec)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_stime.tv_sec)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_stime.tv_usec)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_realtime.tv_sec)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_realtime.tv_usec)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_maxrss)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_minflt)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_majflt)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_nswap)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_inblock)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_oublock)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_nvcsw)); - res += mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_nivcsw)); - - return res; + mx_mysql_bind_init_result(result, JOB_FIELDS_CNT); + + mx_mysql_bind_var(result, idx++, uint64, &(j->job_id)); + mx_mysql_bind_var(result, idx++, uint16, &(j->job_status)); + mx_mysql_bind_var(result, idx++, uint64, &(j->job_flags)); + mx_mysql_bind_var(result, idx++, uint16, &(j->job_priority)); + mx_mysql_bind_var(result, idx++, uint64, &(j->group_id)); + mx_mysql_bind_var(result, idx++, string, &(j->job_workdir)); + mx_mysql_bind_var(result, idx++, uint32, &(j->job_argc)); + mx_mysql_bind_var(result, idx++, string, &(j->job_argv_str)); + mx_mysql_bind_var(result, idx++, string, &(j->job_stdout)); + mx_mysql_bind_var(result, idx++, string, &(j->job_stderr)); + mx_mysql_bind_var(result, idx++, uint32, &(j->job_umask)); + mx_mysql_bind_var(result, idx++, string, &(j->host_submit)); + mx_mysql_bind_var(result, idx++, string, &(j->host_id)); + mx_mysql_bind_var(result, idx++, uint32, &(j->daemon_id)); + mx_mysql_bind_var(result, idx++, string, &(j->daemon_name)); + mx_mysql_bind_var(result, idx++, string, &(j->host_hostname)); + mx_mysql_bind_var(result, idx++, uint32, &(j->host_pid)); + mx_mysql_bind_var(result, idx++, uint32, &(j->host_slots)); + mx_mysql_bind_var(result, idx++, string, &(j->host_cpu_set_str)); + mx_mysql_bind_var(result, idx++, int64, &(j->date_submit)); + mx_mysql_bind_var(result, idx++, int64, &(j->date_start)); + mx_mysql_bind_var(result, idx++, int64, &(j->date_end)); + mx_mysql_bind_var(result, idx++, uint64, &(j->stats_max_sumrss)); + mx_mysql_bind_var(result, idx++, int32, &(j->stats_status)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_utime.tv_sec)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_utime.tv_usec)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_stime.tv_sec)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_stime.tv_usec)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_realtime.tv_sec)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_realtime.tv_usec)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_maxrss)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_minflt)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_majflt)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_nswap)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_inblock)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_oublock)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_nvcsw)); + mx_mysql_bind_var(result, idx++, int64, &(j->stats_rusage.ru_nivcsw)); } char *mxq_job_status_to_name(uint64_t status) @@ -164,8 +160,7 @@ static int do_jobs_statement(struct mx_mysql *mysql, char *query, struct mx_mysq struct mxq_job j = {0}; struct mx_mysql_bind result = {0}; - res = bind_result_job_fields(&result, &j); - assert(res == 0); + bind_result_job_fields(&result, &j); res = mx_mysql_do_statement(mysql, query, param, &result, &j, (void **)jobs, sizeof(**jobs)); if (res < 0) { @@ -196,13 +191,10 @@ int mxq_load_job(struct mx_mysql *mysql, struct mxq_job **jobs_result, uint64_t " WHERE job_id = ?" " LIMIT 1"; - res = mx_mysql_bind_init_param(¶m, 1); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 1); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint64, &job_id); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, uint64, &job_id); res = do_jobs_statement(mysql, query, ¶m, &jobs_tmp); if (res >= 0) @@ -228,11 +220,9 @@ int mxq_load_jobs_in_group(struct mx_mysql *mysql, struct mxq_job **jobs_result, " WHERE group_id = ? OR 1 = 0" " ORDER BY server_id, host_hostname, job_id"; - res = mx_mysql_bind_init_param(¶m, 1); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 1); - res = mx_mysql_bind_var(¶m, 0, uint64, &(grp->group_id)); - assert(res == 0); + mx_mysql_bind_var(¶m, 0, uint64, &(grp->group_id)); res = do_jobs_statement(mysql, query, ¶m, &jobs_tmp); if (res >= 0) @@ -263,14 +253,11 @@ int mxq_load_jobs_in_group_with_status(struct mx_mysql *mysql, struct mxq_job ** " host_hostname," " job_id"; - res = mx_mysql_bind_init_param(¶m, 2); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 2); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint64, &(grp->group_id)); - res += mx_mysql_bind_var(¶m, idx++, uint64, &job_status); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, uint64, &(grp->group_id)); + mx_mysql_bind_var(¶m, idx++, uint64, &job_status); res = do_jobs_statement(mysql, query, ¶m, &jobs_tmp); if (res >= 0) @@ -303,17 +290,13 @@ static uint64_t mxq_select_job_from_group(struct mx_mysql *mysql, uint64_t group " job_id" " LIMIT 1"; - res = mx_mysql_bind_init_param(¶m, 1); - assert(res==0); + mx_mysql_bind_init_param(¶m, 1); - res += mx_mysql_bind_var(¶m,0, uint64, &group_id); - assert(res==0); + mx_mysql_bind_var(¶m,0, uint64, &group_id); - res = mx_mysql_bind_init_result(&result, 1); - assert(res==0); + mx_mysql_bind_init_result(&result, 1); - res += mx_mysql_bind_var(&result,0,uint64,&job_id); - assert(res==0); + mx_mysql_bind_var(&result,0,uint64,&job_id); res = mx_mysql_do_statement(mysql, query, ¶m, &result, &job_id, (void **)&job_id_out,sizeof(*job_id_out)); if (res==1) { @@ -358,17 +341,14 @@ static int mxq_assign_job_from_group_to_daemon(struct mx_mysql *mysql, uint64_t return(0); } - res = mx_mysql_bind_init_param(¶m, 5); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 5); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint32, &daemon->daemon_id); - res += mx_mysql_bind_var(¶m, idx++, string, &daemon->hostname); - res += mx_mysql_bind_var(¶m, idx++, uint64, &slots_per_job); - res += mx_mysql_bind_var(¶m, idx++, string, &daemon->daemon_name); - res += mx_mysql_bind_var(¶m, idx++, uint64, &job_id); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, uint32, &daemon->daemon_id); + mx_mysql_bind_var(¶m, idx++, string, &daemon->hostname); + mx_mysql_bind_var(¶m, idx++, uint64, &slots_per_job); + mx_mysql_bind_var(¶m, idx++, string, &daemon->daemon_name); + mx_mysql_bind_var(¶m, idx++, uint64, &job_id); res = mx_mysql_do_statement_noresult(mysql, query, ¶m); if (res < 0) @@ -405,14 +385,11 @@ int mxq_unassign_jobs_of_server(struct mx_mysql *mysql, struct mxq_daemon *daemo " AND host_hostname = ?" " AND server_id = ?"; - res = mx_mysql_bind_init_param(¶m, 2); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 2); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, string, &daemon->hostname); - res += mx_mysql_bind_var(¶m, idx++, string, &daemon->daemon_name); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, string, &daemon->hostname); + mx_mysql_bind_var(¶m, idx++, string, &daemon->daemon_name); res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { @@ -447,15 +424,12 @@ static int mxq_set_job_status_loaded_on_server(struct mx_mysql *mysql, struct mx " AND daemon_id = ?" " AND host_pid = 0"; - res = mx_mysql_bind_init_param(¶m, 3); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 3); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, string, &host_id); - res += mx_mysql_bind_var(¶m, idx++, uint64, &(job->job_id)); - res += mx_mysql_bind_var(¶m, idx++, uint32, &(job->daemon_id)); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, string, &host_id); + mx_mysql_bind_var(¶m, idx++, uint64, &(job->job_id)); + mx_mysql_bind_var(¶m, idx++, uint32, &(job->daemon_id)); res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { @@ -501,18 +475,15 @@ int mxq_set_job_status_running(struct mx_mysql *mysql, struct mxq_job *job) " AND daemon_id = ?" " AND host_pid = 0"; - res = mx_mysql_bind_init_param(¶m, 5); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 5); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint32, &(job->host_pid)); - res += mx_mysql_bind_var(¶m, idx++, uint32, &(job->host_slots)); - res += mx_mysql_bind_var(¶m, idx++, string, &(job->host_cpu_set_str)); + mx_mysql_bind_var(¶m, idx++, uint32, &(job->host_pid)); + mx_mysql_bind_var(¶m, idx++, uint32, &(job->host_slots)); + mx_mysql_bind_var(¶m, idx++, string, &(job->host_cpu_set_str)); - res += mx_mysql_bind_var(¶m, idx++, uint64, &(job->job_id)); - res += mx_mysql_bind_var(¶m, idx++, uint32, &(job->daemon_id)); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, uint64, &(job->job_id)); + mx_mysql_bind_var(¶m, idx++, uint32, &(job->daemon_id)); res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { @@ -579,32 +550,29 @@ int mxq_set_job_status_exited(struct mx_mysql *mysql, struct mxq_job *job) " AND daemon_id = ?" " AND host_pid = ?"; - res = mx_mysql_bind_init_param(¶m, 20); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 20); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint64, &(job->stats_max_sumrss)); - res += mx_mysql_bind_var(¶m, idx++, int32, &(job->stats_status)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_utime.tv_sec)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_utime.tv_usec)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_stime.tv_sec)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_stime.tv_usec)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_realtime.tv_sec)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_realtime.tv_usec)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_maxrss)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_minflt)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_majflt)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_nswap)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_inblock)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_oublock)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_nvcsw)); - res += mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_nivcsw)); - res += mx_mysql_bind_var(¶m, idx++, uint16, &(newstatus)); - res += mx_mysql_bind_var(¶m, idx++, uint64, &(job->job_id)); - res += mx_mysql_bind_var(¶m, idx++, uint32, &(job->daemon_id)); - res += mx_mysql_bind_var(¶m, idx++, uint32, &(job->host_pid)); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, uint64, &(job->stats_max_sumrss)); + mx_mysql_bind_var(¶m, idx++, int32, &(job->stats_status)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_utime.tv_sec)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_utime.tv_usec)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_stime.tv_sec)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_stime.tv_usec)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_realtime.tv_sec)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_realtime.tv_usec)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_maxrss)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_minflt)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_majflt)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_nswap)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_inblock)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_oublock)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_nvcsw)); + mx_mysql_bind_var(¶m, idx++, int64, &(job->stats_rusage.ru_nivcsw)); + mx_mysql_bind_var(¶m, idx++, uint16, &(newstatus)); + mx_mysql_bind_var(¶m, idx++, uint64, &(job->job_id)); + mx_mysql_bind_var(¶m, idx++, uint32, &(job->daemon_id)); + mx_mysql_bind_var(¶m, idx++, uint32, &(job->host_pid)); res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { @@ -630,15 +598,12 @@ int mxq_set_job_status_unknown(struct mx_mysql *mysql, struct mxq_job *job) " job_status = " status_str(MXQ_JOB_STATUS_UNKNOWN) " WHERE job_id = ?"; - res = mx_mysql_bind_init_param(¶m, 1); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 1); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint64, &job->job_id); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, uint64, &job->job_id); - res += mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); + res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, ¶m); if (res < 0) { mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error()); return res; @@ -698,14 +663,11 @@ static int mxq_load_job_from_group_assigned_to_daemon(struct mx_mysql *mysql, st " AND daemon_id = ?" " LIMIT 1"; - res = mx_mysql_bind_init_param(¶m, 2); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 2); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, uint64, &group_id); - res += mx_mysql_bind_var(¶m, idx++, uint32, &daemon->daemon_id); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, uint64, &group_id); + mx_mysql_bind_var(¶m, idx++, uint32, &daemon->daemon_id); res = do_jobs_statement(mysql, query, ¶m, &jobs_tmp); if (res >= 0) @@ -783,14 +745,11 @@ int mxq_load_jobs_running_on_server(struct mx_mysql *mysql, struct mxq_job **job status_str(MXQ_JOB_STATUS_RUNNING) ")" " AND host_hostname = ?" " AND server_id = ?"; - res = mx_mysql_bind_init_param(¶m, 2); - assert(res == 0); + mx_mysql_bind_init_param(¶m, 2); idx = 0; - res = 0; - res += mx_mysql_bind_var(¶m, idx++, string, &daemon->hostname); - res += mx_mysql_bind_var(¶m, idx++, string, &daemon->daemon_name); - assert(res == 0); + mx_mysql_bind_var(¶m, idx++, string, &daemon->hostname); + mx_mysql_bind_var(¶m, idx++, string, &daemon->daemon_name); res=do_jobs_statement(mysql, query, ¶m, &jobs_tmp); if (res >= 0) diff --git a/mxqadmin.c b/mxqadmin.c index ac3817a2..c4746f3c 100644 --- a/mxqadmin.c +++ b/mxqadmin.c @@ -93,10 +93,9 @@ static int update_group_flags_closed(struct mx_mysql *mysql, uint64_t group_id, return -(errno=EIO); } - res = mx_mysql_statement_param_bind(stmt, 0, uint64, &(newflags)); - res += mx_mysql_statement_param_bind(stmt, 1, uint64, &(group_id)); - res += mx_mysql_statement_param_bind(stmt, 2, uint32, &(user_uid)); - assert(res == 0); + mx_mysql_statement_param_bind(stmt, 0, uint64, &(newflags)); + mx_mysql_statement_param_bind(stmt, 1, uint64, &(group_id)); + mx_mysql_statement_param_bind(stmt, 2, uint32, &(user_uid)); res = mx_mysql_statement_execute(stmt, &num_rows); @@ -132,10 +131,9 @@ static int update_group_flags_reopen(struct mx_mysql *mysql, uint64_t group_id, return -(errno=EIO); } - res = mx_mysql_statement_param_bind(stmt, 0, uint64, &(newflags)); - res += mx_mysql_statement_param_bind(stmt, 1, uint64, &(group_id)); - res += mx_mysql_statement_param_bind(stmt, 2, uint32, &(user_uid)); - assert(res == 0); + mx_mysql_statement_param_bind(stmt, 0, uint64, &(newflags)); + mx_mysql_statement_param_bind(stmt, 1, uint64, &(group_id)); + mx_mysql_statement_param_bind(stmt, 2, uint32, &(user_uid)); res = mx_mysql_statement_execute(stmt, &num_rows); diff --git a/mxqkill.c b/mxqkill.c index 90077e13..667122a9 100644 --- a/mxqkill.c +++ b/mxqkill.c @@ -94,9 +94,8 @@ static int update_group_status_cancelled(struct mx_mysql *mysql, struct mxq_grou return -(errno=EIO); } - res = mx_mysql_statement_param_bind(stmt, 0, uint64, &(g->group_id)); - res += mx_mysql_statement_param_bind(stmt, 1, uint32, &(g->user_uid)); - assert(res == 0); + mx_mysql_statement_param_bind(stmt, 0, uint64, &(g->group_id)); + mx_mysql_statement_param_bind(stmt, 1, uint32, &(g->user_uid)); res = mx_mysql_statement_execute(stmt, &num_rows); @@ -134,8 +133,7 @@ static int update_job_status_cancelled_by_group(struct mx_mysql *mysql, struct m return -(errno=EIO); } - res = mx_mysql_statement_param_bind(stmt, 0, uint64, &(g->group_id)); - assert(res == 0); + mx_mysql_statement_param_bind(stmt, 0, uint64, &(g->group_id)); res = mx_mysql_statement_execute(stmt, &num_rows); @@ -176,9 +174,8 @@ static int update_job_status_cancelling_by_job_id_for_user(struct mx_mysql *mysq return -(errno=EIO); } - res = mx_mysql_statement_param_bind(stmt, 0, uint64, &(job_id)); - res += mx_mysql_statement_param_bind(stmt, 1, uint64, &(user_uid)); - assert(res == 0); + mx_mysql_statement_param_bind(stmt, 0, uint64, &(job_id)); + mx_mysql_statement_param_bind(stmt, 1, uint64, &(user_uid)); res = mx_mysql_statement_execute(stmt, &num_rows); @@ -215,8 +212,7 @@ static int update_job_status_cancelled_by_job_id(struct mx_mysql *mysql, uint64_ return -(errno=EIO); } - res = mx_mysql_statement_param_bind(stmt, 0, uint64, &(job_id)); - assert(res == 0); + mx_mysql_statement_param_bind(stmt, 0, uint64, &(job_id)); res = mx_mysql_statement_execute(stmt, &num_rows); diff --git a/mxqsub.c b/mxqsub.c index 526a5d47..ef236d51 100644 --- a/mxqsub.c +++ b/mxqsub.c @@ -183,25 +183,24 @@ static int load_group_id(struct mx_mysql *mysql, struct mxq_group *g) return -errno; } - res = mx_mysql_statement_param_bind(stmt, 0, string, &(g->group_name)); - res += mx_mysql_statement_param_bind(stmt, 1, uint32, &(g->user_uid)); - res += mx_mysql_statement_param_bind(stmt, 2, string, &(g->user_name)); - res += mx_mysql_statement_param_bind(stmt, 3, uint32, &(g->user_gid)); - res += mx_mysql_statement_param_bind(stmt, 4, string, &(g->user_group)); - res += mx_mysql_statement_param_bind(stmt, 5, string, &(g->job_command)); - res += mx_mysql_statement_param_bind(stmt, 6, uint16, &(g->job_threads)); - res += mx_mysql_statement_param_bind(stmt, 7, uint64, &(g->job_memory)); - res += mx_mysql_statement_param_bind(stmt, 8, uint32, &(g->job_time)); - res += mx_mysql_statement_param_bind(stmt, 9, uint32, &(g->job_tmpdir_size)); - res += mx_mysql_statement_param_bind(stmt, 10, uint16, &(g->job_gpu)); - res += mx_mysql_statement_param_bind(stmt, 11, uint16, &(g->job_max_per_node)); - res += mx_mysql_statement_param_bind(stmt, 12, uint16, &(g->group_priority)); - res += mx_mysql_statement_param_bind(stmt, 13, string, &(g->group_blacklist)); - res += mx_mysql_statement_param_bind(stmt, 14, string, &(g->group_whitelist)); - res += mx_mysql_statement_param_bind(stmt, 15, string, &(g->prerequisites)); - res += mx_mysql_statement_param_bind(stmt, 16, string, &(g->tags)); - res += mx_mysql_statement_param_bind(stmt, 17, uint64, &(flags)); - assert(res == 0); + mx_mysql_statement_param_bind(stmt, 0, string, &(g->group_name)); + mx_mysql_statement_param_bind(stmt, 1, uint32, &(g->user_uid)); + mx_mysql_statement_param_bind(stmt, 2, string, &(g->user_name)); + mx_mysql_statement_param_bind(stmt, 3, uint32, &(g->user_gid)); + mx_mysql_statement_param_bind(stmt, 4, string, &(g->user_group)); + mx_mysql_statement_param_bind(stmt, 5, string, &(g->job_command)); + mx_mysql_statement_param_bind(stmt, 6, uint16, &(g->job_threads)); + mx_mysql_statement_param_bind(stmt, 7, uint64, &(g->job_memory)); + mx_mysql_statement_param_bind(stmt, 8, uint32, &(g->job_time)); + mx_mysql_statement_param_bind(stmt, 9, uint32, &(g->job_tmpdir_size)); + mx_mysql_statement_param_bind(stmt, 10, uint16, &(g->job_gpu)); + mx_mysql_statement_param_bind(stmt, 11, uint16, &(g->job_max_per_node)); + mx_mysql_statement_param_bind(stmt, 12, uint16, &(g->group_priority)); + mx_mysql_statement_param_bind(stmt, 13, string, &(g->group_blacklist)); + mx_mysql_statement_param_bind(stmt, 14, string, &(g->group_whitelist)); + mx_mysql_statement_param_bind(stmt, 15, string, &(g->prerequisites)); + mx_mysql_statement_param_bind(stmt, 16, string, &(g->tags)); + mx_mysql_statement_param_bind(stmt, 17, uint64, &(flags)); res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { @@ -279,26 +278,25 @@ static int load_group_id_by_group_id(struct mx_mysql *mysql, struct mxq_group *g return -errno; } - res = mx_mysql_statement_param_bind(stmt, 0, string, &(g->group_name)); - res += mx_mysql_statement_param_bind(stmt, 1, uint32, &(g->user_uid)); - res += mx_mysql_statement_param_bind(stmt, 2, string, &(g->user_name)); - res += mx_mysql_statement_param_bind(stmt, 3, uint32, &(g->user_gid)); - res += mx_mysql_statement_param_bind(stmt, 4, string, &(g->user_group)); - res += mx_mysql_statement_param_bind(stmt, 5, string, &(g->job_command)); - res += mx_mysql_statement_param_bind(stmt, 6, uint16, &(g->job_threads)); - res += mx_mysql_statement_param_bind(stmt, 7, uint64, &(g->job_memory)); - res += mx_mysql_statement_param_bind(stmt, 8, uint32, &(g->job_time)); - res += mx_mysql_statement_param_bind(stmt, 9, uint32, &(g->job_tmpdir_size)); - res += mx_mysql_statement_param_bind(stmt, 10, uint16, &(g->job_gpu)); - res += mx_mysql_statement_param_bind(stmt, 11, uint16, &(g->job_max_per_node)); - res += mx_mysql_statement_param_bind(stmt, 12, uint16, &(g->group_priority)); - res += mx_mysql_statement_param_bind(stmt, 13, string, &(g->group_blacklist)); - res += mx_mysql_statement_param_bind(stmt, 14, string, &(g->group_whitelist)); - res += mx_mysql_statement_param_bind(stmt, 15, string, &(g->prerequisites)); - res += mx_mysql_statement_param_bind(stmt, 16, string, &(g->tags)); - res += mx_mysql_statement_param_bind(stmt, 17, uint64, &(g->group_id)); - res += mx_mysql_statement_param_bind(stmt, 18, uint64, &(flags)); - assert(res == 0); + mx_mysql_statement_param_bind(stmt, 0, string, &(g->group_name)); + mx_mysql_statement_param_bind(stmt, 1, uint32, &(g->user_uid)); + mx_mysql_statement_param_bind(stmt, 2, string, &(g->user_name)); + mx_mysql_statement_param_bind(stmt, 3, uint32, &(g->user_gid)); + mx_mysql_statement_param_bind(stmt, 4, string, &(g->user_group)); + mx_mysql_statement_param_bind(stmt, 5, string, &(g->job_command)); + mx_mysql_statement_param_bind(stmt, 6, uint16, &(g->job_threads)); + mx_mysql_statement_param_bind(stmt, 7, uint64, &(g->job_memory)); + mx_mysql_statement_param_bind(stmt, 8, uint32, &(g->job_time)); + mx_mysql_statement_param_bind(stmt, 9, uint32, &(g->job_tmpdir_size)); + mx_mysql_statement_param_bind(stmt, 10, uint16, &(g->job_gpu)); + mx_mysql_statement_param_bind(stmt, 11, uint16, &(g->job_max_per_node)); + mx_mysql_statement_param_bind(stmt, 12, uint16, &(g->group_priority)); + mx_mysql_statement_param_bind(stmt, 13, string, &(g->group_blacklist)); + mx_mysql_statement_param_bind(stmt, 14, string, &(g->group_whitelist)); + mx_mysql_statement_param_bind(stmt, 15, string, &(g->prerequisites)); + mx_mysql_statement_param_bind(stmt, 16, string, &(g->tags)); + mx_mysql_statement_param_bind(stmt, 17, uint64, &(g->group_id)); + mx_mysql_statement_param_bind(stmt, 18, uint64, &(flags)); res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { @@ -372,25 +370,24 @@ static int load_group_id_run_or_wait(struct mx_mysql *mysql, struct mxq_group *g return -errno; } - res = mx_mysql_statement_param_bind(stmt, 0, string, &(g->group_name)); - res += mx_mysql_statement_param_bind(stmt, 1, uint32, &(g->user_uid)); - res += mx_mysql_statement_param_bind(stmt, 2, string, &(g->user_name)); - res += mx_mysql_statement_param_bind(stmt, 3, uint32, &(g->user_gid)); - res += mx_mysql_statement_param_bind(stmt, 4, string, &(g->user_group)); - res += mx_mysql_statement_param_bind(stmt, 5, string, &(g->job_command)); - res += mx_mysql_statement_param_bind(stmt, 6, uint16, &(g->job_threads)); - res += mx_mysql_statement_param_bind(stmt, 7, uint64, &(g->job_memory)); - res += mx_mysql_statement_param_bind(stmt, 8, uint32, &(g->job_time)); - res += mx_mysql_statement_param_bind(stmt, 9, uint32, &(g->job_tmpdir_size)); - res += mx_mysql_statement_param_bind(stmt, 10, uint16, &(g->job_gpu)); - res += mx_mysql_statement_param_bind(stmt, 11, uint16, &(g->job_max_per_node)); - res += mx_mysql_statement_param_bind(stmt, 12, uint16, &(g->group_priority)); - res += mx_mysql_statement_param_bind(stmt, 13, string, &(g->group_blacklist)); - res += mx_mysql_statement_param_bind(stmt, 14, string, &(g->group_whitelist)); - res += mx_mysql_statement_param_bind(stmt, 15, string, &(g->prerequisites)); - res += mx_mysql_statement_param_bind(stmt, 16, string, &(g->tags)); - res += mx_mysql_statement_param_bind(stmt, 17, uint64, &(flags)); - assert(res == 0); + mx_mysql_statement_param_bind(stmt, 0, string, &(g->group_name)); + mx_mysql_statement_param_bind(stmt, 1, uint32, &(g->user_uid)); + mx_mysql_statement_param_bind(stmt, 2, string, &(g->user_name)); + mx_mysql_statement_param_bind(stmt, 3, uint32, &(g->user_gid)); + mx_mysql_statement_param_bind(stmt, 4, string, &(g->user_group)); + mx_mysql_statement_param_bind(stmt, 5, string, &(g->job_command)); + mx_mysql_statement_param_bind(stmt, 6, uint16, &(g->job_threads)); + mx_mysql_statement_param_bind(stmt, 7, uint64, &(g->job_memory)); + mx_mysql_statement_param_bind(stmt, 8, uint32, &(g->job_time)); + mx_mysql_statement_param_bind(stmt, 9, uint32, &(g->job_tmpdir_size)); + mx_mysql_statement_param_bind(stmt, 10, uint16, &(g->job_gpu)); + mx_mysql_statement_param_bind(stmt, 11, uint16, &(g->job_max_per_node)); + mx_mysql_statement_param_bind(stmt, 12, uint16, &(g->group_priority)); + mx_mysql_statement_param_bind(stmt, 13, string, &(g->group_blacklist)); + mx_mysql_statement_param_bind(stmt, 14, string, &(g->group_whitelist)); + mx_mysql_statement_param_bind(stmt, 15, string, &(g->prerequisites)); + mx_mysql_statement_param_bind(stmt, 16, string, &(g->tags)); + mx_mysql_statement_param_bind(stmt, 17, uint64, &(flags)); res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { @@ -457,24 +454,23 @@ static int add_group(struct mx_mysql *mysql, struct mxq_group *g) return -errno; } - res = mx_mysql_statement_param_bind(stmt, 0, string, &(g->group_name)); - res += mx_mysql_statement_param_bind(stmt, 1, uint32, &(g->user_uid)); - res += mx_mysql_statement_param_bind(stmt, 2, string, &(g->user_name)); - res += mx_mysql_statement_param_bind(stmt, 3, uint32, &(g->user_gid)); - res += mx_mysql_statement_param_bind(stmt, 4, string, &(g->user_group)); - res += mx_mysql_statement_param_bind(stmt, 5, string, &(g->job_command)); - res += mx_mysql_statement_param_bind(stmt, 6, uint16, &(g->job_threads)); - res += mx_mysql_statement_param_bind(stmt, 7, uint64, &(g->job_memory)); - res += mx_mysql_statement_param_bind(stmt, 8, uint32, &(g->job_time)); - res += mx_mysql_statement_param_bind(stmt, 9, uint32, &(g->job_tmpdir_size)); - res += mx_mysql_statement_param_bind(stmt,10, uint16, &(g->job_gpu)); - res += mx_mysql_statement_param_bind(stmt,11, uint16, &(g->job_max_per_node)); - res += mx_mysql_statement_param_bind(stmt,12, uint16, &(g->group_priority)); - res += mx_mysql_statement_param_bind(stmt,13, string, &(g->group_blacklist)); - res += mx_mysql_statement_param_bind(stmt,14, string, &(g->group_whitelist)); - res += mx_mysql_statement_param_bind(stmt,15, string, &(g->prerequisites)); - res += mx_mysql_statement_param_bind(stmt,16, string, &(g->tags)); - assert(res == 0); + mx_mysql_statement_param_bind(stmt, 0, string, &(g->group_name)); + mx_mysql_statement_param_bind(stmt, 1, uint32, &(g->user_uid)); + mx_mysql_statement_param_bind(stmt, 2, string, &(g->user_name)); + mx_mysql_statement_param_bind(stmt, 3, uint32, &(g->user_gid)); + mx_mysql_statement_param_bind(stmt, 4, string, &(g->user_group)); + mx_mysql_statement_param_bind(stmt, 5, string, &(g->job_command)); + mx_mysql_statement_param_bind(stmt, 6, uint16, &(g->job_threads)); + mx_mysql_statement_param_bind(stmt, 7, uint64, &(g->job_memory)); + mx_mysql_statement_param_bind(stmt, 8, uint32, &(g->job_time)); + mx_mysql_statement_param_bind(stmt, 9, uint32, &(g->job_tmpdir_size)); + mx_mysql_statement_param_bind(stmt,10, uint16, &(g->job_gpu)); + mx_mysql_statement_param_bind(stmt,11, uint16, &(g->job_max_per_node)); + mx_mysql_statement_param_bind(stmt,12, uint16, &(g->group_priority)); + mx_mysql_statement_param_bind(stmt,13, string, &(g->group_blacklist)); + mx_mysql_statement_param_bind(stmt,14, string, &(g->group_whitelist)); + mx_mysql_statement_param_bind(stmt,15, string, &(g->prerequisites)); + mx_mysql_statement_param_bind(stmt,16, string, &(g->tags)); res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { @@ -535,17 +531,16 @@ static int add_job(struct mx_mysql *mysql, struct mxq_job *j) return -errno; } - res = mx_mysql_statement_param_bind(stmt, 0, uint16, &(j->job_priority)); - res += mx_mysql_statement_param_bind(stmt, 1, uint64, &(j->group_id)); - res += mx_mysql_statement_param_bind(stmt, 2, string, &(j->job_workdir)); - res += mx_mysql_statement_param_bind(stmt, 3, uint32, &(j->job_argc)); - res += mx_mysql_statement_param_bind(stmt, 4, string, &(j->job_argv_str)); - res += mx_mysql_statement_param_bind(stmt, 5, string, &(j->job_stdout)); - res += mx_mysql_statement_param_bind(stmt, 6, string, &(j->job_stderr)); - res += mx_mysql_statement_param_bind(stmt, 7, uint32, &(j->job_umask)); - res += mx_mysql_statement_param_bind(stmt, 8, string, &(j->host_submit)); - res += mx_mysql_statement_param_bind(stmt, 9, uint64, &(j->job_flags)); - assert(res ==0); + mx_mysql_statement_param_bind(stmt, 0, uint16, &(j->job_priority)); + mx_mysql_statement_param_bind(stmt, 1, uint64, &(j->group_id)); + mx_mysql_statement_param_bind(stmt, 2, string, &(j->job_workdir)); + mx_mysql_statement_param_bind(stmt, 3, uint32, &(j->job_argc)); + mx_mysql_statement_param_bind(stmt, 4, string, &(j->job_argv_str)); + mx_mysql_statement_param_bind(stmt, 5, string, &(j->job_stdout)); + mx_mysql_statement_param_bind(stmt, 6, string, &(j->job_stderr)); + mx_mysql_statement_param_bind(stmt, 7, uint32, &(j->job_umask)); + mx_mysql_statement_param_bind(stmt, 8, string, &(j->host_submit)); + mx_mysql_statement_param_bind(stmt, 9, uint64, &(j->job_flags)); res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { From 4dc09ccd2f5fbab4487ff3da33d512aa2628aa9c Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 25 Dec 2023 16:13:28 +0100 Subject: [PATCH 08/20] mx_mysql: Remove unused fields from struct mx_mysql --- mx_mysql.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mx_mysql.h b/mx_mysql.h index c7f6e768..17f5a06b 100644 --- a/mx_mysql.h +++ b/mx_mysql.h @@ -21,10 +21,6 @@ struct mx_mysql { char *default_file; char *default_group; bool reconnect; - - unsigned int saved_errno; - const char *error; - const char *sqlstate; }; struct mx_mysql_bind_data { From 2f1562c88e3ffb84b69458284ee1cc3108404bf2 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 25 Dec 2023 17:49:12 +0100 Subject: [PATCH 09/20] mx_proc: Remove redudant assignment --- mx_proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mx_proc.c b/mx_proc.c index 72330df4..9f486b2d 100644 --- a/mx_proc.c +++ b/mx_proc.c @@ -137,7 +137,7 @@ int mx_proc_pid_stat_read(struct mx_proc_pid_stat *pps, char *fmt, ...) assert(pps); va_start(ap, fmt); - _mx_cleanup_free_ char *fname = fname = mx_vasprintf_forever(fmt, ap); + _mx_cleanup_free_ char *fname = mx_vasprintf_forever(fmt, ap); va_end(ap); res = mx_read_first_line_from_file(fname, &line); From d25a77ec0c0235bb8b04a95bc6b100b59bbba19d Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 25 Dec 2023 18:07:58 +0100 Subject: [PATCH 10/20] mxq_job: Remove unused job_flags column --- mxq_job.c | 4 +--- mxq_job.h | 1 - mxqsub.c | 8 +------- mysql/create_tables.sql | 2 -- mysql/migrate_016_remove_job_flags.sql | 2 ++ web/pages/mxq/mxq.in | 1 - 6 files changed, 4 insertions(+), 14 deletions(-) create mode 100644 mysql/migrate_016_remove_job_flags.sql diff --git a/mxq_job.c b/mxq_job.c index b9942927..5816f38d 100644 --- a/mxq_job.c +++ b/mxq_job.c @@ -18,11 +18,10 @@ #include "mxq_group.h" #include "mxq_job.h" -#define JOB_FIELDS_CNT 38 +#define JOB_FIELDS_CNT 37 #define JOB_FIELDS \ " job_id, " \ " job_status, " \ - " job_flags, " \ " job_priority, " \ " group_id, " \ " job_workdir, " \ @@ -67,7 +66,6 @@ static void bind_result_job_fields(struct mx_mysql_bind *result, struct mxq_job mx_mysql_bind_var(result, idx++, uint64, &(j->job_id)); mx_mysql_bind_var(result, idx++, uint16, &(j->job_status)); - mx_mysql_bind_var(result, idx++, uint64, &(j->job_flags)); mx_mysql_bind_var(result, idx++, uint16, &(j->job_priority)); mx_mysql_bind_var(result, idx++, uint64, &(j->group_id)); mx_mysql_bind_var(result, idx++, string, &(j->job_workdir)); diff --git a/mxq_job.h b/mxq_job.h index 15699b65..483c16a3 100644 --- a/mxq_job.h +++ b/mxq_job.h @@ -15,7 +15,6 @@ struct mxq_job { uint64_t job_id; uint16_t job_status; - uint64_t job_flags; uint16_t job_priority; uint64_t group_id; diff --git a/mxqsub.c b/mxqsub.c index ef236d51..26ae3b75 100644 --- a/mxqsub.c +++ b/mxqsub.c @@ -521,9 +521,7 @@ static int add_job(struct mx_mysql *mysql, struct mxq_job *j) " job_umask = ?," - " host_submit = ?," - - " job_flags = ?" + " host_submit = ?" ); if (!stmt) { mx_log_err("mx_mysql_statement_prepare(): %s", mx_mysql_error()); @@ -540,7 +538,6 @@ static int add_job(struct mx_mysql *mysql, struct mxq_job *j) mx_mysql_statement_param_bind(stmt, 6, string, &(j->job_stderr)); mx_mysql_statement_param_bind(stmt, 7, uint32, &(j->job_umask)); mx_mysql_statement_param_bind(stmt, 8, string, &(j->host_submit)); - mx_mysql_statement_param_bind(stmt, 9, uint64, &(j->job_flags)); res = mx_mysql_statement_execute(stmt, &num_rows); if (res < 0) { @@ -707,7 +704,6 @@ int main(int argc, char *argv[]) char *arg_mysql_default_file; char *arg_mysql_default_group; char arg_debug; - char arg_jobflags; u_int32_t arg_tmpdir; u_int16_t arg_gpu; @@ -796,7 +792,6 @@ int main(int argc, char *argv[]) arg_stderr = "stdout"; arg_umask = getumask(); arg_debug = 0; - arg_jobflags = 0; arg_groupid = UINT64_UNSET; arg_tmpdir = 10; // 10G arg_blacklist = NULL; @@ -1132,7 +1127,6 @@ int main(int argc, char *argv[]) group.job_max_per_node = arg_max_per_node; - job.job_flags = arg_jobflags; job.job_priority = arg_priority; job.job_workdir = arg_workdir; job.job_stdout = arg_stdout; diff --git a/mysql/create_tables.sql b/mysql/create_tables.sql index 7885e52e..fe0b7581 100644 --- a/mysql/create_tables.sql +++ b/mysql/create_tables.sql @@ -2,7 +2,6 @@ CREATE TABLE IF NOT EXISTS mxq_group ( group_id INT8 UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, group_name VARCHAR(128) NOT NULL DEFAULT 'default', group_status INT1 UNSIGNED NOT NULL DEFAULT 0, - group_flags INT8 UNSIGNED NOT NULL DEFAULT 0, group_priority INT2 UNSIGNED NOT NULL DEFAULT 127, group_blacklist VARCHAR(1000) NOT NULL DEFAULT '', group_whitelist VARCHAR(1000) NOT NULL DEFAULT '', @@ -71,7 +70,6 @@ CREATE TABLE IF NOT EXISTS mxq_group ( CREATE TABLE IF NOT EXISTS mxq_job ( job_id INT8 UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, job_status INT2 UNSIGNED NOT NULL DEFAULT 0, - job_flags INT8 UNSIGNED NOT NULL DEFAULT 0, job_priority INT2 UNSIGNED NOT NULL DEFAULT 127, group_id INT8 UNSIGNED NOT NULL, diff --git a/mysql/migrate_016_remove_job_flags.sql b/mysql/migrate_016_remove_job_flags.sql new file mode 100644 index 00000000..50a06716 --- /dev/null +++ b/mysql/migrate_016_remove_job_flags.sql @@ -0,0 +1,2 @@ +ALTER TABLE mxq_job + DROP COLUMN job_flags; diff --git a/web/pages/mxq/mxq.in b/web/pages/mxq/mxq.in index eac6ac1f..6c0b3751 100755 --- a/web/pages/mxq/mxq.in +++ b/web/pages/mxq/mxq.in @@ -587,7 +587,6 @@ sub job { $out.=<<"EOF";
 job_status       : $job_status_text
-job_flags        : $o{job_flags}
 job_priority     : $o{job_priority}
 
 group_id         : $link_group_id

From 3b778deb8729fa3d104681e3f82b1b814ff813d5 Mon Sep 17 00:00:00 2001
From: Donald Buczek 
Date: Mon, 25 Dec 2023 18:15:23 +0100
Subject: [PATCH 11/20] sql: Add job_cancelled column

When mxqkill is used against a running job, it needs to communicate the
fact that the job should be aborted to the daemon handling it. This
commit adds a boolean (TINYINT) column `job_cancelled` to `mxq_job` for
this purpose.

Other options such as overloading `job_status`, utilizing a bit of
job_flags, and using MySQL BIT or SET data types were considered but
discarded to avoid code complexity.
---
 mysql/create_tables.sql                 | 2 ++
 mysql/migrate_015_add_job_cancelled.sql | 5 +++++
 2 files changed, 7 insertions(+)
 create mode 100644 mysql/migrate_015_add_job_cancelled.sql

diff --git a/mysql/create_tables.sql b/mysql/create_tables.sql
index fe0b7581..cd0c553b 100644
--- a/mysql/create_tables.sql
+++ b/mysql/create_tables.sql
@@ -72,6 +72,8 @@ CREATE TABLE IF NOT EXISTS mxq_job (
    job_status     INT2 UNSIGNED   NOT NULL DEFAULT 0,
    job_priority   INT2 UNSIGNED   NOT NULL DEFAULT 127,
 
+   job_cancelled  BOOLEAN         NOT NULL DEFAULT FALSE,
+
    group_id       INT8 UNSIGNED   NOT NULL,
 
    job_workdir    VARCHAR(4096)   NOT NULL,
diff --git a/mysql/migrate_015_add_job_cancelled.sql b/mysql/migrate_015_add_job_cancelled.sql
new file mode 100644
index 00000000..adc3c0d6
--- /dev/null
+++ b/mysql/migrate_015_add_job_cancelled.sql
@@ -0,0 +1,5 @@
+ALTER TABLE mxq_job
+    ADD COLUMN
+        job_cancelled BOOLEAN NOT NULL DEFAULT FALSE
+    AFTER
+        job_priority;

From 5cadf667f9455dd4524d7135ee236dceb99f6ade Mon Sep 17 00:00:00 2001
From: Donald Buczek 
Date: Wed, 27 Dec 2023 15:07:50 +0100
Subject: [PATCH 12/20] mxqkill: Add cancel_job

To cancel a single job, this commit introduces the following changes:

* The owner uid is verified in advance to avoid a join withi `mxq_group`
  during a later update statement. This is because the join during
  update doesn't work well with the triggers that want to modify
  `mxq_group.. By avoiding this, we can later dispose of the CANCELLING
  state, which is also just a workaround for this problem.

* job_cancelled is set to true for the job, regardless of job_status.

Transitions of job_status will be handled by following commits.
---
 mxqkill.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/mxqkill.c b/mxqkill.c
index 667122a9..1989c7ab 100644
--- a/mxqkill.c
+++ b/mxqkill.c
@@ -33,6 +33,16 @@
 #define UINT64_SPECIAL_MIN (uint64_t)(-2)
 #define UINT64_HASVALUE(x) ((x) < UINT64_SPECIAL_MIN)
 
+__attribute__ ((noreturn))
+__attribute__ ((format (printf, 1, 2)))
+static void die(const char *restrict fmt, ...) {
+    va_list ap;
+    va_start(ap, fmt);
+    vfprintf(stderr, fmt, ap);
+    va_end(ap);
+    _exit(1);
+}
+
 static void print_usage(void)
 {
     mxq_print_generic_version();
@@ -148,6 +158,65 @@ static int update_job_status_cancelled_by_group(struct mx_mysql *mysql, struct m
     return (int)num_rows;
 }
 
+static void verify_job_owner(struct mx_mysql *mysql, uint64_t job_id, uint64_t user_uid) {
+    struct mx_mysql_stmt *stmt = mx_mysql_statement_prepare(mysql,
+        "SELECT user_uid FROM mxq_job, mxq_group"
+        " WHERE mxq_job.group_id = mxq_group.group_id"
+        " AND job_id = ?"
+    );
+    if (!stmt)
+        die("mx_mysql_statement_prepare(): %s\n", mx_mysql_error());
+
+    mx_mysql_statement_param_bind(stmt, 0, uint64, &job_id);
+
+    unsigned long long num_rows;
+    int res = mx_mysql_statement_execute(stmt, &num_rows);
+    if (res < 0)
+        die("mx_mysql_statement_execute(): %s\n", mx_mysql_error());
+
+    if (num_rows == 0)
+        die("no such job_id %lu\n", job_id);
+
+    uint64_t uid;
+    mx_mysql_statement_result_bind(stmt, 0, uint64, &uid);
+
+    res = mx_mysql_statement_fetch(stmt);
+    if (res < 0)
+        die("mx_mysql_statement_fetch: %s\n", mx_mysql_error());
+
+    if (uid != user_uid)
+        die("job %lu: permission denied\n", job_id);
+
+    mx_mysql_statement_close(&stmt);
+}
+
+static void set_job_cancelled(struct mx_mysql *mysql, uint64_t job_id) {
+    struct mx_mysql_stmt *stmt = mx_mysql_statement_prepare(mysql,
+            "UPDATE mxq_job SET job_cancelled = TRUE"
+            " WHERE job_id = ?"
+    );
+    if (!stmt)
+        die("mx_mysql_statement_prepare(): %s\n", mx_mysql_error());
+
+    mx_mysql_statement_param_bind(stmt, 0, uint64, &job_id);
+
+    unsigned long long num_rows;
+    int res = mx_mysql_statement_execute(stmt, &num_rows);
+    if (res < 0)
+        die("mx_mysql_statement_execute(): %s\n", mx_mysql_error());
+    if (num_rows == 0)
+        die("no such job_id %lu\n", job_id);
+
+    mx_mysql_statement_close(&stmt);
+}
+
+__attribute__ ((unused))
+static void cancel_job(struct mx_mysql *mysql, uint64_t job_id, uint64_t user_uid) {
+
+    verify_job_owner(mysql, job_id, user_uid);
+    set_job_cancelled(mysql, job_id);
+}
+
 static int update_job_status_cancelling_by_job_id_for_user(struct mx_mysql *mysql, uint64_t job_id, uint64_t user_uid)
 {
     struct mx_mysql_stmt *stmt = NULL;

From b636630e17fd53f877c10b3d22fd4d929624c402 Mon Sep 17 00:00:00 2001
From: Donald Buczek 
Date: Thu, 28 Dec 2023 18:07:56 +0100
Subject: [PATCH 13/20] mxqkill: Use cancel_job()

Use the `cancel_job()`function introduced in the previous commit to
cancel a single job.
---
 mxqkill.c | 123 +-----------------------------------------------------
 1 file changed, 2 insertions(+), 121 deletions(-)

diff --git a/mxqkill.c b/mxqkill.c
index 1989c7ab..26cb79bb 100644
--- a/mxqkill.c
+++ b/mxqkill.c
@@ -210,92 +210,12 @@ static void set_job_cancelled(struct mx_mysql *mysql, uint64_t job_id) {
     mx_mysql_statement_close(&stmt);
 }
 
-__attribute__ ((unused))
 static void cancel_job(struct mx_mysql *mysql, uint64_t job_id, uint64_t user_uid) {
 
     verify_job_owner(mysql, job_id, user_uid);
     set_job_cancelled(mysql, job_id);
 }
 
-static int update_job_status_cancelling_by_job_id_for_user(struct mx_mysql *mysql, uint64_t job_id, uint64_t user_uid)
-{
-    struct mx_mysql_stmt *stmt = NULL;
-    unsigned long long num_rows = 0;
-    int res;
-
-    assert(job_id);
-
-    stmt = mx_mysql_statement_prepare(mysql,
-            "UPDATE mxq_job AS j"
-                " LEFT JOIN mxq_group AS g"
-                    " ON j.group_id = g.group_id"
-                " SET"
-                    " job_status = " status_str(MXQ_JOB_STATUS_CANCELLING)
-                " WHERE job_id = ?"
-                " AND user_uid = ?"
-                " AND job_status IN (" status_str(MXQ_JOB_STATUS_INQ) "," status_str(MXQ_JOB_STATUS_ASSIGNED) ")"
-                " AND host_hostname = ''"
-                " AND server_id = ''"
-                " AND host_pid = 0"
-            );
-    if (!stmt) {
-        mx_log_err("mx_mysql_statement_prepare(): %m");
-        return -(errno=EIO);
-    }
-
-    mx_mysql_statement_param_bind(stmt, 0, uint64, &(job_id));
-    mx_mysql_statement_param_bind(stmt, 1, uint64, &(user_uid));
-
-    res = mx_mysql_statement_execute(stmt, &num_rows);
-
-    if (res < 0)
-        mx_log_err("mx_mysql_statement_execute(): %m");
-
-    mx_mysql_statement_close(&stmt);
-
-    if (res < 0)
-        return -(errno=-res);
-
-    return (int)num_rows;
-}
-
-static int update_job_status_cancelled_by_job_id(struct mx_mysql *mysql, uint64_t job_id)
-{
-    struct mx_mysql_stmt *stmt = NULL;
-    unsigned long long num_rows = 0;
-    int res;
-
-    assert(job_id);
-
-    stmt = mx_mysql_statement_prepare(mysql,
-            "UPDATE mxq_job SET"
-                    " job_status = " status_str(MXQ_JOB_STATUS_CANCELLED)
-                " WHERE job_id = ?"
-                " AND job_status = " status_str(MXQ_JOB_STATUS_CANCELLING)
-                " AND host_hostname = ''"
-                " AND server_id = ''"
-                " AND host_pid = 0"
-            );
-    if (!stmt) {
-        mx_log_err("mx_mysql_statement_prepare(): %m");
-        return -(errno=EIO);
-    }
-
-    mx_mysql_statement_param_bind(stmt, 0, uint64, &(job_id));
-
-    res = mx_mysql_statement_execute(stmt, &num_rows);
-
-    if (res < 0)
-        mx_log_err("mx_mysql_statement_execute(): %m");
-
-    mx_mysql_statement_close(&stmt);
-
-    if (res < 0)
-        return -(errno=-res);
-
-    return (int)num_rows;
-}
-
 int main(int argc, char *argv[])
 {
     struct mx_mysql *mysql = NULL;
@@ -477,48 +397,9 @@ int main(int argc, char *argv[])
     mx_log_info("MySQL: Connection to database established.");
 
     if (arg_job_id) {
-        int res1, res2;
-
-        res1 = update_job_status_cancelling_by_job_id_for_user(mysql, arg_job_id, passwd->pw_uid);
-        res2 = update_job_status_cancelled_by_job_id(mysql, arg_job_id);
-
+        cancel_job(mysql, arg_job_id, passwd->pw_uid);
         mx_mysql_finish(&mysql);
-        mx_log_info("MySQL: Connection to database closed.");
-
-        if (res1 == -ENOENT)
-            res1=0;
-
-        if (res2 == -ENOENT)
-            res1=0;
-
-        if (res1 < 0)
-            mx_log_err("setting status of job %lu to CANCELLING failed: %s", arg_job_id, strerror(-res1));
-
-        if (res2 < 0)
-            mx_log_err("setting status of job %lu to CANCELLED failed: %s", arg_job_id, strerror(-res2));
-
-        if (res2 > 0) {
-            mx_log_notice("Job %lu cancelled!", arg_job_id);
-            return 0;
-        }
-
-        if (res1 > 0) {
-            mx_log_notice("Updated status of job %lu to CANCELLING.", arg_job_id);
-            if (res2 == 0) {
-                mx_log_warning("Updating status of job %lu to CANCELLED failed. Job vanished. Please retry.", arg_job_id);
-                return 2;
-            }
-            return 1;
-        }
-
-        if (res1 == 0 && res2 == 0) {
-            mx_log_notice("No queued job with job_id=%lu for user %s(%d) found in q.", arg_job_id, passwd->pw_name, passwd->pw_uid);
-            mx_log_warning("Killing a single job is not implemented yet.");
-            mx_log_warning("See https://github.molgen.mpg.de/mariux64/mxq/issues/4 for more details.");
-            return 0;
-        }
-
-        return 1;
+        return 0;
     }
 
     if (arg_group_id) {

From c22b5374e161e45f60467e062640cb47a68fcfb9 Mon Sep 17 00:00:00 2001
From: Donald Buczek 
Date: Wed, 27 Dec 2023 18:31:00 +0100
Subject: [PATCH 14/20] mxqd: Implement job cancellation

This commit introduces periodic checks for the job_cancelled flags for
the jobs run by this daemon. If a cancellation of the job was requested,
the job is killed using the existing mechanism.
---
 mxqd.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/mxqd.c b/mxqd.c
index 021bf786..4c65a2a9 100644
--- a/mxqd.c
+++ b/mxqd.c
@@ -1809,6 +1809,60 @@ static int killall_cancelled(struct ppidcache *ppidcache, struct mxq_server *ser
     return 0;
 }
 
+static void kill_by_jobid(struct ppidcache *ppidcache, struct mxq_server *server, unsigned long job_id) {
+    for (struct mxq_user_list  *ulist = server->users ; ulist ; ulist = ulist->next)
+        for (struct mxq_group_list *glist = ulist->groups ; glist ; glist = glist->next)
+            for (struct mxq_job_list *jlist = glist->jobs; jlist ; jlist = jlist->next)
+                if (jlist->job.job_id == job_id) {
+                    killstate_event(ppidcache, jlist, KILLEVENT_CANCEL);
+                    return;
+                }
+}
+
+static void kill_cancelled_jobs(struct ppidcache *ppidcache, struct mxq_server *server) {
+    struct mx_mysql *mysql = server->mysql;
+    struct mxq_daemon *daemon = &server->daemon;
+    (void)ppidcache;
+
+    __attribute__((cleanup(mx_mysql_statement_close)))
+    struct mx_mysql_stmt *stmt = mx_mysql_statement_prepare(mysql,
+            "SELECT job_id FROM mxq_job"
+            " WHERE job_status = " status_str(MXQ_JOB_STATUS_RUNNING)
+            " AND job_cancelled"
+            " AND host_hostname = ?"
+            " AND server_id = ?"
+    );
+    if (!stmt) {
+        mx_log_err("mx_mysql_stmt_prepare: %s\n", mx_mysql_error());
+        return;
+    }
+
+    mx_mysql_statement_param_bind(stmt, 0, string, &daemon->hostname);
+    mx_mysql_statement_param_bind(stmt, 1, string, &daemon->daemon_name);
+
+    unsigned long long num_rows;
+    int res = mx_mysql_statement_execute(stmt, &num_rows);
+    if (res < 0) {
+        mx_log_err("mx_mysql_statement_execute: %s\n", mx_mysql_error());
+        return;
+    }
+    if (num_rows == 0)
+        return;
+
+    unsigned long job_id;
+    mx_mysql_statement_result_bind(stmt, 0, uint64, &job_id);
+
+    for (unsigned long i = 0 ; i < num_rows ; i++) {
+        res = mx_mysql_statement_fetch(stmt);
+        if (res < 0) {
+            mx_log_err("mx_mysql_statement_fetch: %s\n", mx_mysql_error());
+            return;
+        }
+        mx_log_debug("kill running job id %lu", job_id);
+        kill_by_jobid(ppidcache, server, job_id);
+    }
+}
+
 static void rename_outfiles(struct mxq_server *server, struct mxq_group *group, struct mxq_job *job)
 {
     int res;
@@ -2541,6 +2595,7 @@ static void monitor_jobs(struct mxq_server *server)
     killall_cancelled(ppidcache, server);
     killall_over_time(ppidcache, server);
     killall_over_memory(ppidcache, server);
+    kill_cancelled_jobs(ppidcache, server);
     for (ulist = server->users; ulist; ulist = ulist->next) {
         for (glist = ulist->groups; glist; glist = glist->next) {
             for (jlist = glist->jobs; jlist; jlist = jlist->next)

From 22aadf3b875832784baeb40eca4adea2b1ff0382 Mon Sep 17 00:00:00 2001
From: Donald Buczek 
Date: Thu, 28 Dec 2023 18:17:49 +0100
Subject: [PATCH 15/20] sql: Add mx_update_job2 trigger

This commit removes the -> `CANCELLED` housekeeping from the
`mx_update_job` trigger as we no longer set the state to `CANCELLED` by
code.

Instead, a new trigger is added, which transitions a job from `INQ` to
`CANCELLED` when the `job_cancelled` flag is set.

For jobs that are `RUNNING`, the `job_cancelled` flag needs to be
handled by the daemon, which kills the job. Note that the job will
transition into `KILLED` not into `CANCELLED`.

This approach eliminates the need for any code for jobs getting killed
in the `LOADED` or `ASSIGNED` states, as these will either transition
into `RUNNING` or - in very exceptional cases - back into INQ.
---
 mysql/create_trigger.sql | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/mysql/create_trigger.sql b/mysql/create_trigger.sql
index 0833974e..f70082b8 100644
--- a/mysql/create_trigger.sql
+++ b/mysql/create_trigger.sql
@@ -87,17 +87,6 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job
                     stats_total_real_sec  = stats_total_real_sec  + NEW.stats_real_sec
                 WHERE group_id = NEW.group_id;
 
-            -- INQ(0) | ASSIGNED(100) | CANCELLING(989) -> CANCELLED(990)
-            ELSEIF NEW.job_status = 990 AND OLD.job_status IN (0, 100, 989) THEN
-
-                SET NEW.date_start = NOW();
-                SET NEW.date_end   = NEW.date_start;
-
-                UPDATE mxq_group SET
-                    group_jobs_inq       = group_jobs_inq       - 1,
-                    group_jobs_cancelled = group_jobs_cancelled + 1
-                WHERE group_id = NEW.group_id;
-
             -- LOADED(150) | RUNNING(200)  -> UNKNOWN(999)
             ELSEIF NEW.job_status = 999 AND OLD.job_status IN (150, 200) THEN
 
@@ -162,5 +151,17 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job
         END IF;
     END;
 |
+
+DROP TRIGGER IF EXISTS mxq_update_job2|
+CREATE TRIGGER mxq_update_job2 BEFORE UPDATE ON mxq_job
+    FOR EACH ROW FOLLOWS mxq_update_job
+        IF NEW.job_status = 0 AND NEW.job_cancelled THEN
+            SET NEW.job_status = 990;                     -- CANCELLED
+            UPDATE mxq_group SET
+                group_jobs_inq = group_jobs_inq - 1,
+                group_jobs_cancelled = group_jobs_cancelled + 1
+                WHERE group_id = NEW.group_id;
+        END IF;
+|
 DELIMITER ;
 UNLOCK TABLES;

From ddc935fb634b703a4c2ab83395284c8552cdb97d Mon Sep 17 00:00:00 2001
From: Donald Buczek 
Date: Thu, 28 Dec 2023 18:37:49 +0100
Subject: [PATCH 16/20] mxq_job: Remove CANCELLING status

This commit removes the obsolete job status `CANCELLING`. It also
removes the `* -> NOT IN [ CANCELLING(989) | CANCELLED(990) ]` trigger,
which would reduce to `* -> CANCELLED(990)`, but the only transition to
`CANCELLED` is from `INQ` where there are no job run time statistics
that need to be accumulated into mxq_group.
---
 mxq_job.c                |  2 --
 mxq_job.h                |  2 --
 mysql/create_trigger.sql | 15 ---------------
 web/pages/mxq/mxq.in     |  1 -
 4 files changed, 20 deletions(-)

diff --git a/mxq_job.c b/mxq_job.c
index 5816f38d..daf4061e 100644
--- a/mxq_job.c
+++ b/mxq_job.c
@@ -120,8 +120,6 @@ char *mxq_job_status_to_name(uint64_t status)
             return "failed";
         case MXQ_JOB_STATUS_CANCELLED:
             return "cancelled";
-        case MXQ_JOB_STATUS_CANCELLING:
-            return "cancelling";
         case MXQ_JOB_STATUS_UNKNOWN:
             return "unknown";
         case MXQ_JOB_STATUS_FINISHED:
diff --git a/mxq_job.h b/mxq_job.h
index 483c16a3..d73561cb 100644
--- a/mxq_job.h
+++ b/mxq_job.h
@@ -69,8 +69,6 @@ struct mxq_job {
 #define MXQ_JOB_STATUS_KILLED       400
 #define MXQ_JOB_STATUS_FAILED       750
 
-#define MXQ_JOB_STATUS_CANCELLING   989
-
 #define MXQ_JOB_STATUS_CANCELLED    990
 #define MXQ_JOB_STATUS_UNKNOWN      999
 #define MXQ_JOB_STATUS_FINISHED    1000
diff --git a/mysql/create_trigger.sql b/mysql/create_trigger.sql
index f70082b8..afc016ae 100644
--- a/mysql/create_trigger.sql
+++ b/mysql/create_trigger.sql
@@ -132,21 +132,6 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job
                     group_jobs_running  = group_jobs_running  - 1,
                     group_slots_running = group_slots_running - OLD.host_slots
                 WHERE group_id = NEW.group_id;
-
-            -- * -> NOT IN [ CANCELLING(989) | CANCELLED(990) ]
-            ELSEIF NEW.job_status NOT IN (989, 990) THEN
-
-                UPDATE mxq_group SET
-                   stats_max_sumrss    = GREATEST(stats_max_sumrss, NEW.stats_max_sumrss),
-                   stats_max_maxrss    = GREATEST(stats_max_maxrss, NEW.stats_maxrss),
-                   stats_max_utime_sec = GREATEST(stats_max_utime_sec, NEW.stats_utime_sec),
-                   stats_max_stime_sec = GREATEST(stats_max_stime_sec, NEW.stats_stime_sec),
-                   stats_max_real_sec  = GREATEST(stats_max_real_sec, NEW.stats_real_sec),
-                   stats_total_utime_sec = stats_total_utime_sec+NEW.stats_utime_sec,
-                   stats_total_stime_sec = stats_total_stime_sec+NEW.stats_stime_sec,
-                   stats_total_real_sec  = stats_total_real_sec+NEW.stats_real_sec
-                WHERE group_id = NEW.group_id;
-
             END IF;
         END IF;
     END;
diff --git a/web/pages/mxq/mxq.in b/web/pages/mxq/mxq.in
index 6c0b3751..16f49115 100755
--- a/web/pages/mxq/mxq.in
+++ b/web/pages/mxq/mxq.in
@@ -87,7 +87,6 @@ sub db_init {
 		KILLED      =>  400,
 		FAILED      =>  750,
 		UNKNOWN_PRE =>  755,
-		CANCELLING  =>  989,
 		CANCELLED   =>  990,
 		UNKNOWN     =>  999,
 		FINISHED    => 1000,

From fe10e8e6eb2654ae7e9b0cc6f671c083f2d970a0 Mon Sep 17 00:00:00 2001
From: Donald Buczek 
Date: Wed, 27 Dec 2023 18:43:33 +0100
Subject: [PATCH 17/20] web: Display job_cancelled in job details

---
 web/pages/mxq/mxq.in | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/web/pages/mxq/mxq.in b/web/pages/mxq/mxq.in
index 16f49115..6d50c80f 100755
--- a/web/pages/mxq/mxq.in
+++ b/web/pages/mxq/mxq.in
@@ -571,6 +571,7 @@ sub job {
 	my %o=%{$sth->fetchrow_hashref('NAME_lc')};
 
 	my $job_status_text=job_status($o{'job_status'});
+	my $job_cancelled = $o{job_cancelled} ? "true" : "false";
 	my $job_umask_text=sprintf('%03O',$o{job_umask});
 	my $link_group_id=a({href=>selfurl("/group/$o{group_id}")},$o{group_id});
 	my $job_argv=escapeHTML(split_cmd($o{job_argv}));
@@ -586,6 +587,7 @@ sub job {
 	$out.=<<"EOF";
 
 job_status       : $job_status_text
+job_cancelled    : $job_cancelled
 job_priority     : $o{job_priority}
 
 group_id         : $link_group_id

From 7f4b2dff6ee82f4d5a4e9e4ef160152efdfdc47a Mon Sep 17 00:00:00 2001
From: Donald Buczek 
Date: Thu, 28 Dec 2023 08:59:21 +0100
Subject: [PATCH 18/20] mx_mysql: Remove mx_mysql_error() function

---
 mx_mysql.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/mx_mysql.c b/mx_mysql.c
index ea3a8e59..d2811d5a 100644
--- a/mx_mysql.c
+++ b/mx_mysql.c
@@ -59,15 +59,6 @@ char *mx_mysql_error(void) {
     return mx_mysql_last_error == NULL ? "no error information" : mx_mysql_last_error;
 }
 
-static const char *mx__mysql_error(struct mx_mysql *mysql)
-{
-    assert(mysql);
-    assert(mysql->mysql);
-
-    /* no mysql errors possible */
-    return mysql_error(mysql->mysql);
-}
-
 static int mx__mysql_init(struct mx_mysql *mysql)
 {
     assert(mysql);
@@ -688,7 +679,7 @@ static int mx_mysql_real_connect(struct mx_mysql *mysql, const char *host, const
         return 0;
 
     if (res == -EALREADY) {
-        mx_log_debug("WARNING: %s", mx__mysql_error(mysql));
+        mx_log_debug("WARNING: %s", mysql_error(mysql->mysql));
         return 0;
     }
 

From 1828b05a2b3266ae42d02d3ff7cc4a6a232f694a Mon Sep 17 00:00:00 2001
From: Donald Buczek 
Date: Thu, 28 Dec 2023 09:00:37 +0100
Subject: [PATCH 19/20] mx_mysql: Remove unnecessary check

---
 mx_mysql.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mx_mysql.c b/mx_mysql.c
index d2811d5a..686eb0c4 100644
--- a/mx_mysql.c
+++ b/mx_mysql.c
@@ -93,7 +93,7 @@ static int mx__mysql_real_connect(struct mx_mysql *mysql, const char *host, cons
     assert(mysql->mysql);
 
     m = mysql_real_connect(mysql->mysql, host, user, passwd, db, port, unix_socket, client_flag);
-    if (m && m == mysql->mysql)
+    if (m)
         return 0;
 
     mx_mysql_save_error(mysql_error(mysql->mysql));

From 5149518e7a05db4464eef7b089e07b663c06ba41 Mon Sep 17 00:00:00 2001
From: Donald Buczek 
Date: Thu, 28 Dec 2023 10:04:02 +0100
Subject: [PATCH 20/20] sql: Remove unused group_jobs_restarted column

---
 mxq_group.c                                       | 5 +----
 mxq_group.h                                       | 2 --
 mysql/create_tables.sql                           | 2 --
 mysql/migrate_017_remove_group_jobs_restarted.sql | 2 ++
 web/pages/mxq/mxq.in                              | 1 -
 5 files changed, 3 insertions(+), 9 deletions(-)
 create mode 100644 mysql/migrate_017_remove_group_jobs_restarted.sql

diff --git a/mxq_group.c b/mxq_group.c
index 8d44c363..d34a575a 100644
--- a/mxq_group.c
+++ b/mxq_group.c
@@ -11,7 +11,7 @@
 #include "mx_util.h"
 #include "mx_mysql.h"
 
-#define GROUP_FIELDS_CNT 37
+#define GROUP_FIELDS_CNT 36
 #define GROUP_FIELDS \
             " group_id," \
             " group_name," \
@@ -40,7 +40,6 @@
             " group_jobs_failed," \
             " group_jobs_cancelled," \
             " group_jobs_unknown," \
-            " group_jobs_restarted," \
             " group_slots_running," \
             " stats_max_sumrss," \
             " stats_max_maxrss," \
@@ -91,8 +90,6 @@ static void bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_gr
     mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_cancelled));
     mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_unknown));
 
-    mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_restarted));
-
     mx_mysql_bind_var(result, idx++, uint64, &(g->group_slots_running));
 
     mx_mysql_bind_var(result, idx++, uint64, &(g->stats_max_sumrss));
diff --git a/mxq_group.h b/mxq_group.h
index a72e1580..d0f32663 100644
--- a/mxq_group.h
+++ b/mxq_group.h
@@ -43,8 +43,6 @@ struct mxq_group {
    uint64_t  group_jobs_cancelled;
    uint64_t  group_jobs_unknown;
 
-   uint64_t  group_jobs_restarted;
-
    uint64_t  group_slots_running;
 
    uint64_t  stats_max_sumrss;
diff --git a/mysql/create_tables.sql b/mysql/create_tables.sql
index cd0c553b..3b2bcd06 100644
--- a/mysql/create_tables.sql
+++ b/mysql/create_tables.sql
@@ -31,8 +31,6 @@ CREATE TABLE IF NOT EXISTS mxq_group (
    group_jobs_cancelled INT8 UNSIGNED NOT NULL DEFAULT 0,
    group_jobs_unknown   INT8 UNSIGNED NOT NULL DEFAULT 0,
 
-   group_jobs_restarted INT8 UNSIGNED NOT NULL DEFAULT 0,
-
    group_slots_running  INT8 UNSIGNED NOT NULL DEFAULT 0,
 
    group_mtime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
diff --git a/mysql/migrate_017_remove_group_jobs_restarted.sql b/mysql/migrate_017_remove_group_jobs_restarted.sql
new file mode 100644
index 00000000..b8a91756
--- /dev/null
+++ b/mysql/migrate_017_remove_group_jobs_restarted.sql
@@ -0,0 +1,2 @@
+ALTER TABLE mxq_group
+	DROP COLUMN group_jobs_restarted;
diff --git a/web/pages/mxq/mxq.in b/web/pages/mxq/mxq.in
index 6d50c80f..1aecc0ea 100755
--- a/web/pages/mxq/mxq.in
+++ b/web/pages/mxq/mxq.in
@@ -407,7 +407,6 @@ group_jobs_finished   : $o->{group_jobs_finished}
 group_jobs_failed     : $o->{group_jobs_failed}
 group_jobs_cancelled  : $o->{group_jobs_cancelled}
 group_jobs_unknown    : $o->{group_jobs_unknown}
-group_jobs_restarted  : $o->{group_jobs_restarted}
 
 group_slots_running:  : $o->{group_slots_running}