Skip to content

0.31.0 #149

Merged
merged 20 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 24 additions & 45 deletions mx_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);
}
20 changes: 10 additions & 10 deletions mx_mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
89 changes: 38 additions & 51 deletions mxq_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(&param, 1);
assert(res == 0);
mx_mysql_bind_init_param(&param, 1);

idx = 0;
res = 0;
res += mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_id));
mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_id));
assert(res == 0);
donald marked this conversation as resolved.
Show resolved Hide resolved

res += mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, &param);
res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, &param);
if (res < 0) {
mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error());
return res;
Expand Down Expand Up @@ -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(&param, 3);
assert(res == 0);
mx_mysql_bind_init_param(&param, 3);

idx = 0;
res = 0;
res += mx_mysql_bind_var(&param, idx++, uint32, &daemon->daemon_id);
res += mx_mysql_bind_var(&param, idx++, string, &daemon->hostname);
res += mx_mysql_bind_var(&param, idx++, string, &daemon->daemon_name);
assert(res == 0);
mx_mysql_bind_var(&param, idx++, uint32, &daemon->daemon_id);
mx_mysql_bind_var(&param, idx++, string, &daemon->hostname);
mx_mysql_bind_var(&param, idx++, string, &daemon->daemon_name);

res += mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, &param);
res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, &param);
if (res < 0) {
mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error());
return res;
Expand Down Expand Up @@ -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(&param, 2);
assert(res == 0);
mx_mysql_bind_init_param(&param, 2);

idx = 0;
res = 0;
res += mx_mysql_bind_var(&param, idx++, uint8, &(status));
res += mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_id));
assert(res == 0);
mx_mysql_bind_var(&param, idx++, uint8, &(status));
mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_id));

res += mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, &param);
res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, &param);
if (res < 0) {
mx_log_err("mx_mysql_do_statement(): %s", mx_mysql_error());
return res;
Expand Down Expand Up @@ -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(&param, 6);
assert(res == 0);
mx_mysql_bind_init_param(&param, 6);

idx = 0;
res = 0;
res += mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_jobs_running));
res += mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_slots_running));
res += mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_threads_running));
res += mx_mysql_bind_var(&param, idx++, uint64, &(daemon->daemon_memory_used));
res += mx_mysql_bind_var(&param, idx++, uint16, &(daemon->gpus_used));
res += mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_id));
assert(res == 0);
mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_jobs_running));
mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_slots_running));
mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_threads_running));
mx_mysql_bind_var(&param, idx++, uint64, &(daemon->daemon_memory_used));
mx_mysql_bind_var(&param, idx++, uint16, &(daemon->gpus_used));
mx_mysql_bind_var(&param, idx++, uint32, &(daemon->daemon_id));

res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, &param);
if (res < 0) {
Expand Down