Skip to content

Commit bce7253

Browse files
committed
job-list: add state matching library
Problem: In job-list we store jobs on three lists, pending, running, and inactive. If we begin to use RFC31 constraints to filter jobs, it would be inefficient to scan all three lists for every job list query. Solution: Add a job state matching library. It will determine if jobs in the pending, running, or inactive state are possible given the job constraint sent with the job-list query. For example: states=pending AND userid=42 In the above constraint, a job in a pending state can possibly be matched to this constraint, so it is worthwhile to scan the pending job list for jobs with userid=42. However, it is impossible for a job in running or inactive state to match at all, so they should not be scanned. This will allow job-list queries to run more efficiently if entire lists can be skipped if it is impossible for any jobs on those lists to be matched to a constraint. Add unit tests.
1 parent 0bf85d7 commit bce7253

File tree

7 files changed

+1777
-45
lines changed

7 files changed

+1777
-45
lines changed

src/modules/job-list/Makefile.am

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ libjob_list_la_SOURCES = \
3131
stats.h \
3232
stats.c \
3333
match.h \
34-
match.c
34+
match.c \
35+
state_match.h \
36+
state_match.c \
37+
match_util.h \
38+
match_util.c
3539

3640
TESTS = \
3741
test_job_data.t \
38-
test_match.t
42+
test_match.t \
43+
test_state_match.t
3944

4045
test_ldadd = \
4146
$(builddir)/libjob-list.la \
@@ -76,6 +81,14 @@ test_match_t_LDADD = \
7681
test_match_t_LDFLAGS = \
7782
$(test_ldflags)
7883

84+
test_state_match_t_SOURCES = test/state_match.c
85+
test_state_match_t_CPPFLAGS = \
86+
$(test_cppflags)
87+
test_state_match_t_LDADD = \
88+
$(test_ldadd)
89+
test_state_match_t_LDFLAGS = \
90+
$(test_ldflags)
91+
7992
EXTRA_DIST = \
8093
test/R/1node_1core.R \
8194
test/R/1node_4core.R \

src/modules/job-list/match.c

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
#include "ccan/str/str.h"
2222

2323
#include "match.h"
24+
#include "match_util.h"
2425

25-
/* identical to czmq_destructor, czmq.h happens to define a
26-
* conflicting symbol we use */
27-
typedef void (destructor_f) (void **item);
2826
typedef bool (*match_f) (struct list_constraint *, const struct job *);
29-
typedef int (*array_to_bitmask_f) (json_t *, flux_error_t *);
3027

3128
struct list_constraint {
3229
zlistx_t *values;
@@ -302,45 +299,6 @@ static bool match_states (struct list_constraint *c, const struct job *job)
302299
return ((*states) & job->state);
303300
}
304301

305-
static int array_to_states_bitmask (json_t *values, flux_error_t *errp)
306-
{
307-
int states = 0;
308-
json_t *entry;
309-
size_t index;
310-
int valid_states = (FLUX_JOB_STATE_NEW
311-
| FLUX_JOB_STATE_PENDING
312-
| FLUX_JOB_STATE_RUNNING
313-
| FLUX_JOB_STATE_INACTIVE);
314-
315-
json_array_foreach (values, index, entry) {
316-
flux_job_state_t state;
317-
if (json_is_string (entry)) {
318-
const char *statestr = json_string_value (entry);
319-
if (flux_job_strtostate (statestr, &state) < 0) {
320-
errprintf (errp,
321-
"invalid states value '%s' specified",
322-
statestr);
323-
return -1;
324-
}
325-
}
326-
else if (json_is_integer (entry)) {
327-
state = json_integer_value (entry);
328-
if (state & ~valid_states) {
329-
errprintf (errp,
330-
"invalid states value '%Xh' specified",
331-
state);
332-
return -1;
333-
}
334-
}
335-
else {
336-
errprintf (errp, "states value invalid type");
337-
return -1;
338-
}
339-
states |= state;
340-
}
341-
return states;
342-
}
343-
344302
static struct list_constraint *create_states_constraint (json_t *values,
345303
flux_error_t *errp)
346304
{

src/modules/job-list/match_util.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/************************************************************\
2+
* Copyright 2023 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+
#if HAVE_CONFIG_H
12+
#include "config.h"
13+
#endif
14+
15+
#include <stdlib.h>
16+
#include <string.h>
17+
#include <errno.h>
18+
#include <jansson.h>
19+
20+
#include "src/common/libutil/errprintf.h"
21+
22+
#include "match_util.h"
23+
24+
int array_to_states_bitmask (json_t *values, flux_error_t *errp)
25+
{
26+
int states = 0;
27+
json_t *entry;
28+
size_t index;
29+
int valid_states = (FLUX_JOB_STATE_NEW
30+
| FLUX_JOB_STATE_PENDING
31+
| FLUX_JOB_STATE_RUNNING
32+
| FLUX_JOB_STATE_INACTIVE);
33+
34+
json_array_foreach (values, index, entry) {
35+
flux_job_state_t state;
36+
if (json_is_string (entry)) {
37+
const char *statestr = json_string_value (entry);
38+
if (flux_job_strtostate (statestr, &state) < 0) {
39+
errprintf (errp,
40+
"invalid states value '%s' specified",
41+
statestr);
42+
return -1;
43+
}
44+
}
45+
else if (json_is_integer (entry)) {
46+
state = json_integer_value (entry);
47+
if (state & ~valid_states) {
48+
errprintf (errp,
49+
"invalid states value '%Xh' specified",
50+
state);
51+
return -1;
52+
}
53+
}
54+
else {
55+
errprintf (errp, "states value invalid type");
56+
return -1;
57+
}
58+
states |= state;
59+
}
60+
return states;
61+
}
62+
63+
/* vi: ts=4 sw=4 expandtab
64+
*/

src/modules/job-list/match_util.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/************************************************************\
2+
* Copyright 2023 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 HAVE_JOB_LIST_MATCH_UTIL_H
12+
#define HAVE_JOB_LIST_MATCH_UTIL_H 1
13+
14+
#if HAVE_CONFIG_H
15+
#include "config.h"
16+
#endif
17+
18+
#include <flux/core.h> /* flux_error_t */
19+
#include <jansson.h>
20+
21+
/* identical to czmq_destructor, czmq.h happens to define a
22+
* conflicting symbol we use */
23+
typedef void (destructor_f) (void **item);
24+
25+
typedef int (*array_to_bitmask_f) (json_t *, flux_error_t *);
26+
27+
int array_to_states_bitmask (json_t *values, flux_error_t *errp);
28+
29+
#endif /* !HAVE_JOB_LIST_MATCH_UTIL_H */

0 commit comments

Comments
 (0)