Skip to content

Commit

Permalink
database: store and retrieve cpuset of job
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed Oct 30, 2015
1 parent 7dee7ef commit 35af203
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
21 changes: 14 additions & 7 deletions mxq_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "mxq_group.h"
#include "mxq_job.h"

#define JOB_FIELDS_CNT 36
#define JOB_FIELDS_CNT 37
#define JOB_FIELDS \
" job_id, " \
" job_status, " \
Expand All @@ -36,6 +36,7 @@
" host_hostname, " \
" host_pid, " \
" host_slots, " \
" host_cpu_set, " \
" UNIX_TIMESTAMP(date_submit) as date_submit, " \
" UNIX_TIMESTAMP(date_start) as date_start, " \
" UNIX_TIMESTAMP(date_end) as date_end, " \
Expand Down Expand Up @@ -81,6 +82,7 @@ static int bind_result_job_fields(struct mx_mysql_bind *result, struct mxq_job *
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));
Expand Down Expand Up @@ -159,6 +161,7 @@ void mxq_job_free_content(struct mxq_job *j)
mx_free_null(j->tmp_stderr);
mx_free_null(j->host_submit);
mx_free_null(j->host_id);
mx_free_null(j->host_cpu_set_str);
mx_free_null(j->server_id);
mx_free_null(j->host_hostname);
mx_free_null(j->job_argv);
Expand All @@ -167,7 +170,7 @@ void mxq_job_free_content(struct mxq_job *j)

static int do_jobs_statement(struct mx_mysql *mysql, char *query, struct mx_mysql_bind *param, struct mxq_job **jobs)
{
int res;
int res,i;
struct mxq_job j = {0};
struct mx_mysql_bind result = {0};

Expand All @@ -179,6 +182,8 @@ static int do_jobs_statement(struct mx_mysql *mysql, char *query, struct mx_mysq
mx_log_err("mx_mysql_do_statement(): %m");
return res;
}
for (i=0;i<res;i++)
mx_str_to_cpuset(&(*jobs)[i].host_cpu_set,(*jobs)[i].host_cpu_set_str);
return res;
}

Expand Down Expand Up @@ -417,22 +422,24 @@ int mxq_set_job_status_running(struct mx_mysql *mysql, struct mxq_job *job)
" job_status = " status_str(MXQ_JOB_STATUS_RUNNING) ","
" date_start = NULL,"
" host_pid = ?,"
" host_slots = ?"
" host_slots = ?,"
" host_cpu_set = ?"
" WHERE job_id = ?"
" AND job_status = " status_str(MXQ_JOB_STATUS_LOADED)
" AND host_hostname = ?"
" AND server_id = ?"
" AND host_pid = 0";

res = mx_mysql_bind_init_param(&param, 5);
res = mx_mysql_bind_init_param(&param, 6);
assert(res == 0);

res = 0;
res += mx_mysql_bind_var(&param, 0, uint32, &(job->host_pid));
res += mx_mysql_bind_var(&param, 1, uint32, &(job->host_slots));
res += mx_mysql_bind_var(&param, 2, uint64, &(job->job_id));
res += mx_mysql_bind_var(&param, 3, string, &(job->host_hostname));
res += mx_mysql_bind_var(&param, 4, string, &(job->server_id));
res += mx_mysql_bind_var(&param, 2, string, &(job->host_cpu_set_str));
res += mx_mysql_bind_var(&param, 3, uint64, &(job->job_id));
res += mx_mysql_bind_var(&param, 4, string, &(job->host_hostname));
res += mx_mysql_bind_var(&param, 5, string, &(job->server_id));
assert(res == 0);

res = mx_mysql_do_statement_noresult_retry_on_fail(mysql, query, &param);
Expand Down
5 changes: 5 additions & 0 deletions mysql/alter_tables_0.18.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE mxq_job
ADD COLUMN
host_cpu_set VARCHAR(4095) NOT NULL DEFAULT ""
AFTER
host_slots;
1 change: 1 addition & 0 deletions mysql/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ CREATE TABLE IF NOT EXISTS mxq_job (
host_hostname VARCHAR(64) NOT NULL DEFAULT "",
host_pid INT4 UNSIGNED NOT NULL DEFAULT 0,
host_slots INT4 UNSIGNED NOT NULL DEFAULT 0,
host_cpu_set VARCHAR(4095) NOT NULL DEFAULT "",

date_submit TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
date_start TIMESTAMP NOT NULL DEFAULT 0,
Expand Down
1 change: 1 addition & 0 deletions web/pages/mxq/mxq.in
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ host_id : $o{host_id}
host_hostname : $o{host_hostname}
host_pid : $o{host_pid}
host_slots : $o{host_slots}
host_cpu_set : $o{host_cpu_set}
date_submit : $o{date_submit}
date_start : $o{date_start} $ago
Expand Down

0 comments on commit 35af203

Please sign in to comment.