Skip to content

Commit e2e7ee8

Browse files
committed
job-list: rebuild and store eventlog
Problem: In the near future we will need access to the job's eventlog when a job goes inactive. Solution: Rebuild the job eventlog from the events journal and store it internally in struct job.
1 parent a0d28ce commit e2e7ee8

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/modules/job-list/job_data.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void job_destroy (void *data)
4040
grudgeset_destroy (job->dependencies);
4141
json_decref (job->jobspec);
4242
json_decref (job->R);
43+
free (job->eventlog);
4344
json_decref (job->exception_context);
4445
free (job);
4546
errno = save_errno;

src/modules/job-list/job_data.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ struct job {
7070
/* cache of job information */
7171
json_t *jobspec;
7272
json_t *R;
73+
char *eventlog;
74+
size_t eventlog_len;
7375
json_t *exception_context;
7476

7577
/* Track which states we have seen and have completed transition

src/modules/job-list/job_state.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,42 @@ void job_state_unpause_cb (flux_t *h, flux_msg_handler_t *mh,
409409
flux_log_error (h, "error responding to unpause request");
410410
}
411411

412+
static int store_eventlog_entry (struct job_state_ctx *jsctx,
413+
struct job *job,
414+
json_t *entry)
415+
{
416+
char *s = json_dumps (entry, 0);
417+
int rv = -1;
418+
419+
/* entry should have been verified via eventlog_entry_parse()
420+
* earlier */
421+
assert (s);
422+
423+
if (!job->eventlog) {
424+
job->eventlog_len = strlen (s) + 2; /* +2 for \n and \0 */
425+
if (!(job->eventlog = calloc (1, job->eventlog_len))) {
426+
flux_log_error (jsctx->h, "calloc");
427+
goto error;
428+
429+
}
430+
strcpy (job->eventlog, s);
431+
strcat (job->eventlog, "\n");
432+
}
433+
else {
434+
job->eventlog_len += strlen (s) + 1; /* +1 for \n */
435+
if (!(job->eventlog = realloc (job->eventlog, job->eventlog_len))) {
436+
flux_log_error (jsctx->h, "realloc");
437+
goto error;
438+
}
439+
strcat (job->eventlog, s);
440+
strcat (job->eventlog, "\n");
441+
}
442+
rv = 0;
443+
error:
444+
free (s);
445+
return rv;
446+
}
447+
412448
static int job_transition_state (struct job_state_ctx *jsctx,
413449
struct job *job,
414450
flux_job_state_t newstate,
@@ -487,12 +523,17 @@ static int journal_submit_event (struct job_state_ctx *jsctx,
487523
struct job *job,
488524
flux_jobid_t id,
489525
double timestamp,
526+
json_t *entry,
490527
json_t *context,
491528
json_t *jobspec)
492529
{
493530
if (!job) {
494531
if (!(job = job_create (jsctx->h, id)))
495532
return -1;
533+
if (store_eventlog_entry (jsctx, job, entry) < 0) {
534+
job_destroy (job);
535+
return -1;
536+
}
496537
if (jobspec)
497538
job->jobspec = json_incref (jobspec);
498539
if (zhashx_insert (jsctx->index, &job->id, job) < 0) {
@@ -895,11 +936,17 @@ static int journal_process_event (struct job_state_ctx *jsctx,
895936
return 0;
896937
}
897938

939+
if (job && job->eventlog) {
940+
if (store_eventlog_entry (jsctx, job, event) < 0)
941+
return -1;
942+
}
943+
898944
if (streq (name, "submit")) {
899945
if (journal_submit_event (jsctx,
900946
job,
901947
id,
902948
timestamp,
949+
event,
903950
context,
904951
jobspec) < 0)
905952
return -1;

0 commit comments

Comments
 (0)