Skip to content

Commit 7923de5

Browse files
committed
job-list: store copy of jobspec internally
Problem: struct job currently caches two sub-objects of the jobspec in jobspec_job and jobspec_cmd. However, these two sub objects are never used. Solution: Instead store a reference to the jobspec in struct job. Remove the references to the sub objects.
1 parent 66f3c75 commit 7923de5

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/modules/job-list/job_state.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ static void job_destroy (void *data)
122122
free (job->nodelist);
123123
json_decref (job->annotations);
124124
grudgeset_destroy (job->dependencies);
125-
json_decref (job->jobspec_job);
126-
json_decref (job->jobspec_cmd);
125+
json_decref (job->jobspec);
127126
json_decref (job->R);
128127
json_decref (job->exception_context);
129128
zlist_destroy (&job->next_states);
@@ -395,19 +394,20 @@ static int jobspec_parse (struct list_ctx *ctx,
395394
const char *s)
396395
{
397396
json_error_t error;
398-
json_t *jobspec = NULL;
399-
json_t *tasks, *resources, *command, *jobspec_job = NULL;
397+
json_t *jobspec_job = NULL;
398+
json_t *command = NULL;
399+
json_t *tasks, *resources;
400400
struct res_level res[3];
401401
int rc = -1;
402402

403-
if (!(jobspec = json_loads (s, 0, &error))) {
403+
if (!(job->jobspec = json_loads (s, 0, &error))) {
404404
flux_log (ctx->h, LOG_ERR,
405405
"%s: job %ju invalid jobspec: %s",
406406
__FUNCTION__, (uintmax_t)job->id, error.text);
407407
goto error;
408408
}
409409

410-
if (json_unpack_ex (jobspec, &error, 0,
410+
if (json_unpack_ex (job->jobspec, &error, 0,
411411
"{s:{s:{s?:o}}}",
412412
"attributes",
413413
"system",
@@ -426,10 +426,9 @@ static int jobspec_parse (struct list_ctx *ctx,
426426
__FUNCTION__, (uintmax_t)job->id);
427427
goto nonfatal_error;
428428
}
429-
job->jobspec_job = json_incref (jobspec_job);
430429
}
431430

432-
if (json_unpack_ex (jobspec, &error, 0,
431+
if (json_unpack_ex (job->jobspec, &error, 0,
433432
"{s:o}",
434433
"tasks", &tasks) < 0) {
435434
flux_log (ctx->h, LOG_ERR,
@@ -453,10 +452,8 @@ static int jobspec_parse (struct list_ctx *ctx,
453452
goto nonfatal_error;
454453
}
455454

456-
job->jobspec_cmd = json_incref (command);
457-
458-
if (job->jobspec_job) {
459-
if (json_unpack_ex (job->jobspec_job, &error, 0,
455+
if (jobspec_job) {
456+
if (json_unpack_ex (jobspec_job, &error, 0,
460457
"{s?:s}",
461458
"name", &job->name) < 0) {
462459
flux_log (ctx->h, LOG_ERR,
@@ -469,7 +466,7 @@ static int jobspec_parse (struct list_ctx *ctx,
469466
/* If user did not specify job.name, we treat arg 0 of the command
470467
* as the job name */
471468
if (!job->name) {
472-
json_t *arg0 = json_array_get (job->jobspec_cmd, 0);
469+
json_t *arg0 = json_array_get (command, 0);
473470
if (!arg0 || !json_is_string (arg0)) {
474471
flux_log (ctx->h, LOG_ERR,
475472
"%s: job %ju invalid job command",
@@ -480,7 +477,7 @@ static int jobspec_parse (struct list_ctx *ctx,
480477
assert (job->name);
481478
}
482479

483-
if (json_unpack_ex (jobspec, &error, 0,
480+
if (json_unpack_ex (job->jobspec, &error, 0,
484481
"{s:o}",
485482
"resources", &resources) < 0) {
486483
flux_log (ctx->h, LOG_ERR,
@@ -561,7 +558,6 @@ static int jobspec_parse (struct list_ctx *ctx,
561558
nonfatal_error:
562559
rc = 0;
563560
error:
564-
json_decref (jobspec);
565561
return rc;
566562
}
567563

src/modules/job-list/job_state.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ struct job {
101101
struct grudgeset *dependencies;
102102

103103
/* cache of job information */
104-
json_t *jobspec_job;
105-
json_t *jobspec_cmd;
104+
json_t *jobspec;
106105
json_t *R;
107106
json_t *exception_context;
108107

0 commit comments

Comments
 (0)