Skip to content

Commit 3d33f37

Browse files
committed
job-list: store copy of jobspec internally
Problem: In the near future we will need access to the job's jobspec when a job goes inactive, but we do not store a copy of it. Solution: Store a reference to the jobspec in struct job. As a side effect, we no longer need to store several jobspec sub-objects within struct job.
1 parent c21c959 commit 3d33f37

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/modules/job-list/job_state.c

Lines changed: 9 additions & 9 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);
@@ -397,7 +396,9 @@ static int jobspec_parse (struct list_ctx *ctx,
397396
{
398397
json_error_t error;
399398
json_t *jobspec = NULL;
400-
json_t *tasks, *resources, *command, *jobspec_job = NULL;
399+
json_t *jobspec_job = NULL;
400+
json_t *command = NULL;
401+
json_t *tasks, *resources;
401402
int rc = -1;
402403

403404
if (!(jobspec = json_loads (s, 0, &error))) {
@@ -407,6 +408,8 @@ static int jobspec_parse (struct list_ctx *ctx,
407408
goto error;
408409
}
409410

411+
job->jobspec = json_incref (jobspec);
412+
410413
if (json_unpack_ex (jobspec, &error, 0,
411414
"{s:{s:{s?:o}}}",
412415
"attributes",
@@ -426,7 +429,6 @@ static int jobspec_parse (struct list_ctx *ctx,
426429
__FUNCTION__, (uintmax_t)job->id);
427430
goto nonfatal_error;
428431
}
429-
job->jobspec_job = json_incref (jobspec_job);
430432
}
431433

432434
if (json_unpack_ex (jobspec, &error, 0,
@@ -453,10 +455,8 @@ static int jobspec_parse (struct list_ctx *ctx,
453455
goto nonfatal_error;
454456
}
455457

456-
job->jobspec_cmd = json_incref (command);
457-
458-
if (job->jobspec_job) {
459-
if (json_unpack_ex (job->jobspec_job, &error, 0,
458+
if (jobspec_job) {
459+
if (json_unpack_ex (jobspec_job, &error, 0,
460460
"{s?:s}",
461461
"name", &job->name) < 0) {
462462
flux_log (ctx->h, LOG_ERR,
@@ -469,7 +469,7 @@ static int jobspec_parse (struct list_ctx *ctx,
469469
/* If user did not specify job.name, we treat arg 0 of the command
470470
* as the job name */
471471
if (!job->name) {
472-
json_t *arg0 = json_array_get (job->jobspec_cmd, 0);
472+
json_t *arg0 = json_array_get (command, 0);
473473
if (!arg0 || !json_is_string (arg0)) {
474474
flux_log (ctx->h, LOG_ERR,
475475
"%s: job %ju invalid job command",

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)