Skip to content

Commit 84e13b8

Browse files
committed
job-list: move job struct into its own files
Problem: In the future, additional services added into job-list may lead to header circular includes. Solution: Move struct job and job create/destroy functions into their own files to break future circular dependencies.
1 parent 6a4047f commit 84e13b8

File tree

11 files changed

+179
-123
lines changed

11 files changed

+179
-123
lines changed

src/modules/job-list/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ job_list_la_SOURCES = \
1919
job-list.h \
2020
job_state.h \
2121
job_state.c \
22+
job_data.h \
23+
job_data.c \
2224
list.h \
2325
list.c \
2426
job_util.h \

src/modules/job-list/job-list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "job-list.h"
1919
#include "job_state.h"
20+
#include "job_data.h"
2021
#include "list.h"
2122
#include "idsync.h"
2223

src/modules/job-list/job_data.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/************************************************************\
2+
* Copyright 2022 Lawrence Livermore National Security, LLC
3+
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
4+
*
5+
* This file is part of the Flux resource manager framework.
6+
* For details, see https://github.com/flux-framework.
7+
*
8+
* SPDX-License-Identifier: LGPL-3.0
9+
\************************************************************/
10+
11+
/* job_data.c - primary struct job helper functions */
12+
13+
#if HAVE_CONFIG_H
14+
#include "config.h"
15+
#endif
16+
#include <jansson.h>
17+
#include <flux/core.h>
18+
19+
#include "src/common/libczmqcontainers/czmq_containers.h"
20+
21+
#include "job_data.h"
22+
23+
void job_destroy (void *data)
24+
{
25+
struct job *job = data;
26+
if (job) {
27+
free (job->ranks);
28+
free (job->nodelist);
29+
json_decref (job->annotations);
30+
grudgeset_destroy (job->dependencies);
31+
json_decref (job->jobspec);
32+
json_decref (job->R);
33+
free (job->eventlog);
34+
json_decref (job->exception_context);
35+
zlist_destroy (&job->next_states);
36+
free (job);
37+
}
38+
}
39+
40+
struct job *job_create (struct list_ctx *ctx, flux_jobid_t id)
41+
{
42+
struct job *job = NULL;
43+
44+
if (!(job = calloc (1, sizeof (*job))))
45+
return NULL;
46+
job->ctx = ctx;
47+
job->id = id;
48+
job->userid = FLUX_USERID_UNKNOWN;
49+
job->urgency = -1;
50+
/* pending jobs that are not yet assigned a priority shall be
51+
* listed after those who do, so we set the job priority to MIN */
52+
job->priority = FLUX_JOB_PRIORITY_MIN;
53+
job->state = FLUX_JOB_STATE_NEW;
54+
job->ntasks = -1;
55+
job->nnodes = -1;
56+
job->expiration = -1.0;
57+
job->wait_status = -1;
58+
job->result = FLUX_JOB_RESULT_FAILED;
59+
60+
if (!(job->next_states = zlist_new ())) {
61+
errno = ENOMEM;
62+
job_destroy (job);
63+
return NULL;
64+
}
65+
66+
job->states_mask = FLUX_JOB_STATE_NEW;
67+
job->states_events_mask = FLUX_JOB_STATE_NEW;
68+
job->eventlog_seq = -1;
69+
return job;
70+
}
71+
72+
/*
73+
* vi:tabstop=4 shiftwidth=4 expandtab
74+
*/

src/modules/job-list/job_data.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/************************************************************\
2+
* Copyright 2018 Lawrence Livermore National Security, LLC
3+
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
4+
*
5+
* This file is part of the Flux resource manager framework.
6+
* For details, see https://github.com/flux-framework.
7+
*
8+
* SPDX-License-Identifier: LGPL-3.0
9+
\************************************************************/
10+
11+
#ifndef _FLUX_JOB_LIST_JOB_DATA_H
12+
#define _FLUX_JOB_LIST_JOB_DATA_H
13+
14+
#include <flux/core.h>
15+
#include <jansson.h>
16+
17+
#include "job-list.h"
18+
#include "src/common/libutil/grudgeset.h"
19+
#include "src/common/libczmqcontainers/czmq_containers.h"
20+
21+
/* timestamp of when we enter the state
22+
*
23+
* associated eventlog entries when restarting
24+
*
25+
* t_depend - "submit"
26+
* t_priority - "priority" (not saved, can be entered multiple times)
27+
* t_sched - "depend" (not saved, can be entered multiple times)
28+
* t_run - "alloc"
29+
* t_cleanup - "finish" or "exception" w/ severity == 0
30+
* t_inactive - "clean"
31+
*/
32+
struct job {
33+
struct list_ctx *ctx;
34+
35+
flux_jobid_t id;
36+
uint32_t userid;
37+
int urgency;
38+
int64_t priority;
39+
double t_submit;
40+
// t_depend is identical to t_submit
41+
// double t_depend;
42+
double t_run;
43+
double t_cleanup;
44+
double t_inactive;
45+
flux_job_state_t state;
46+
const char *name;
47+
int ntasks;
48+
int nnodes;
49+
char *ranks;
50+
char *nodelist;
51+
double expiration;
52+
int wait_status;
53+
bool success;
54+
bool exception_occurred;
55+
int exception_severity;
56+
const char *exception_type;
57+
const char *exception_note;
58+
flux_job_result_t result;
59+
json_t *annotations;
60+
struct grudgeset *dependencies;
61+
62+
/* cache of job information */
63+
json_t *jobspec;
64+
json_t *R;
65+
char *eventlog;
66+
size_t eventlog_len;
67+
json_t *exception_context;
68+
69+
/* Track which states we have seen and have completed transition
70+
* to. We do not immediately update to the new state and place
71+
* onto a new list until we have retrieved any necessary data
72+
* associated to that state. For example, when the 'depend' state
73+
* has been seen, we don't immediately place it on the `pending`
74+
* list. We wait until we've retrieved data such as userid,
75+
* urgency, etc.
76+
*
77+
* Track which states we've seen via the states_mask.
78+
*
79+
* Track states seen via events stream in states_events_mask.
80+
*/
81+
zlist_t *next_states;
82+
unsigned int states_mask;
83+
unsigned int states_events_mask;
84+
void *list_handle;
85+
86+
int eventlog_seq; /* last event seq read */
87+
};
88+
89+
void job_destroy (void *data);
90+
91+
struct job *job_create (struct list_ctx *ctx, flux_jobid_t id);
92+
93+
#endif /* ! _FLUX_JOB_LIST_JOB_DATA_H */
94+
95+
/*
96+
* vi:tabstop=4 shiftwidth=4 expandtab
97+
*/

src/modules/job-list/job_state.c

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "src/common/libidset/idset.h"
2929

3030
#include "job_state.h"
31+
#include "job_data.h"
3132
#include "idsync.h"
3233
#include "job_util.h"
3334

@@ -114,61 +115,12 @@ static int job_inactive_cmp (const void *a1, const void *a2)
114115
return NUMCMP (j2->t_inactive, j1->t_inactive);
115116
}
116117

117-
static void job_destroy (void *data)
118-
{
119-
struct job *job = data;
120-
if (job) {
121-
free (job->ranks);
122-
free (job->nodelist);
123-
json_decref (job->annotations);
124-
grudgeset_destroy (job->dependencies);
125-
json_decref (job->jobspec);
126-
json_decref (job->R);
127-
free (job->eventlog);
128-
json_decref (job->exception_context);
129-
zlist_destroy (&job->next_states);
130-
free (job);
131-
}
132-
}
133-
134118
static void job_destroy_wrapper (void **data)
135119
{
136120
struct job **job = (struct job **)data;
137121
job_destroy (*job);
138122
}
139123

140-
static struct job *job_create (struct list_ctx *ctx, flux_jobid_t id)
141-
{
142-
struct job *job = NULL;
143-
144-
if (!(job = calloc (1, sizeof (*job))))
145-
return NULL;
146-
job->ctx = ctx;
147-
job->id = id;
148-
job->userid = FLUX_USERID_UNKNOWN;
149-
job->urgency = -1;
150-
/* pending jobs that are not yet assigned a priority shall be
151-
* listed after those who do, so we set the job priority to MIN */
152-
job->priority = FLUX_JOB_PRIORITY_MIN;
153-
job->state = FLUX_JOB_STATE_NEW;
154-
job->ntasks = -1;
155-
job->nnodes = -1;
156-
job->expiration = -1.0;
157-
job->wait_status = -1;
158-
job->result = FLUX_JOB_RESULT_FAILED;
159-
160-
if (!(job->next_states = zlist_new ())) {
161-
errno = ENOMEM;
162-
job_destroy (job);
163-
return NULL;
164-
}
165-
166-
job->states_mask = FLUX_JOB_STATE_NEW;
167-
job->states_events_mask = FLUX_JOB_STATE_NEW;
168-
job->eventlog_seq = -1;
169-
return job;
170-
}
171-
172124
/* zlistx_insert() and zlistx_reorder() take a 'low_value' parameter
173125
* which indicates which end of the list to search from.
174126
* false=search begins at tail (lowest urgency, youngest)

src/modules/job-list/job_state.h

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
#include "job-list.h"
1818
#include "stats.h"
19-
#include "src/common/libutil/grudgeset.h"
20-
#include "src/common/libczmqcontainers/czmq_containers.h"
2119

2220
/* To handle the common case of user queries on job state, we will
2321
* store jobs in three different lists.
@@ -59,74 +57,6 @@ struct job_state_ctx {
5957
flux_future_t *events;
6058
};
6159

62-
/* timestamp of when we enter the state
63-
*
64-
* associated eventlog entries when restarting
65-
*
66-
* t_depend - "submit"
67-
* t_priority - "priority" (not saved, can be entered multiple times)
68-
* t_sched - "depend" (not saved, can be entered multiple times)
69-
* t_run - "alloc"
70-
* t_cleanup - "finish" or "exception" w/ severity == 0
71-
* t_inactive - "clean"
72-
*/
73-
struct job {
74-
struct list_ctx *ctx;
75-
76-
flux_jobid_t id;
77-
uint32_t userid;
78-
int urgency;
79-
int64_t priority;
80-
double t_submit;
81-
// t_depend is identical to t_submit
82-
// double t_depend;
83-
double t_run;
84-
double t_cleanup;
85-
double t_inactive;
86-
flux_job_state_t state;
87-
const char *name;
88-
int ntasks;
89-
int nnodes;
90-
char *ranks;
91-
char *nodelist;
92-
double expiration;
93-
int wait_status;
94-
bool success;
95-
bool exception_occurred;
96-
int exception_severity;
97-
const char *exception_type;
98-
const char *exception_note;
99-
flux_job_result_t result;
100-
json_t *annotations;
101-
struct grudgeset *dependencies;
102-
103-
/* cache of job information */
104-
json_t *jobspec;
105-
json_t *R;
106-
char *eventlog;
107-
size_t eventlog_len;
108-
json_t *exception_context;
109-
110-
/* Track which states we have seen and have completed transition
111-
* to. We do not immediately update to the new state and place
112-
* onto a new list until we have retrieved any necessary data
113-
* associated to that state. For example, when the 'depend' state
114-
* has been seen, we don't immediately place it on the `pending`
115-
* list. We wait until we've retrieved data such as userid,
116-
* urgency, etc.
117-
*
118-
* Track which states we've seen via the states_mask.
119-
*
120-
* Track states seen via events stream in states_events_mask.
121-
*/
122-
zlist_t *next_states;
123-
unsigned int states_mask;
124-
unsigned int states_events_mask;
125-
void *list_handle;
126-
127-
int eventlog_seq; /* last event seq read */
128-
};
129-
13060
struct job_state_ctx *job_state_create (struct list_ctx *ctx);
13161

13262
void job_state_destroy (void *data);

src/modules/job-list/job_util.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#include "job-list.h"
2424
#include "job_util.h"
25-
#include "job_state.h"
2625

2726
void seterror (job_list_error_t *errp, const char *fmt, ...)
2827
{

src/modules/job-list/job_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include <flux/core.h>
1515

16-
#include "job_state.h"
16+
#include "job_data.h"
1717

1818
typedef struct {
1919
char text[160];

src/modules/job-list/list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "idsync.h"
2525
#include "list.h"
2626
#include "job_util.h"
27-
#include "job_state.h"
27+
#include "job_data.h"
2828

2929
json_t *get_job_by_id (struct list_ctx *ctx,
3030
job_list_error_t *errp,

src/modules/job-list/stats.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <ctype.h>
1616
#include <flux/core.h>
1717

18-
#include "job_state.h"
1918
#include "stats.h"
19+
#include "job_data.h"
2020

2121
/* Return the index into stats->state_count[] array for the
2222
* job state 'state'

0 commit comments

Comments
 (0)