Skip to content

Commit 788cc32

Browse files
committed
job-list: add job db
Problem: We would like to store inactive jobs on disk for retrieval at a later time. Solution: Add an sqlite job db to the job-list module. If the job-list module is configured with a database path or if the flux broker is configured with a statedir, store all inactive job data to the db.
1 parent a48d354 commit 788cc32

File tree

12 files changed

+578
-9
lines changed

12 files changed

+578
-9
lines changed

src/modules/Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ job_list_la_SOURCES =
173173
job_list_la_CPPFLAGS = \
174174
$(AM_CPPFLAGS) \
175175
$(FLUX_SECURITY_CFLAGS) \
176-
$(HWLOC_CFLAGS)
176+
$(HWLOC_CFLAGS) \
177+
$(SQLITE_CFLAGS)
177178
job_list_la_LIBADD = \
178179
$(builddir)/job-list/libjob-list.la \
179180
$(top_builddir)/src/common/libjob/libjob.la \
@@ -182,7 +183,8 @@ job_list_la_LIBADD = \
182183
$(top_builddir)/src/common/libflux-optparse.la \
183184
$(top_builddir)/src/common/librlist/librlist.la \
184185
$(JANSSON_LIBS) \
185-
$(HWLOC_LIBS)
186+
$(HWLOC_LIBS) \
187+
$(SQLITE_LIBS)
186188
job_list_la_LDFLAGS = $(fluxmod_ldflags) -module
187189

188190
job_ingest_la_SOURCES =

src/modules/job-list/Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ libjob_list_la_SOURCES = \
2222
job_state.c \
2323
job_data.h \
2424
job_data.c \
25+
job_db.h \
26+
job_db.c \
2527
list.h \
2628
list.c \
2729
job_util.h \
2830
job_util.c \
2931
idsync.h \
3032
idsync.c \
3133
stats.h \
32-
stats.c
34+
stats.c \
35+
util.h \
36+
util.c
3337

3438
TESTS = \
3539
test_job_data.t

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,16 @@ static void list_ctx_destroy (struct list_ctx *ctx)
163163
flux_msg_handler_delvec (ctx->handlers);
164164
if (ctx->jsctx)
165165
job_state_destroy (ctx->jsctx);
166+
if (ctx->dbctx)
167+
job_db_ctx_destroy (ctx->dbctx);
166168
if (ctx->isctx)
167169
idsync_ctx_destroy (ctx->isctx);
168170
free (ctx);
169171
errno = saved_errno;
170172
}
171173
}
172174

173-
static struct list_ctx *list_ctx_create (flux_t *h)
175+
static struct list_ctx *list_ctx_create (flux_t *h, int argc, char **argv)
174176
{
175177
struct list_ctx *ctx = calloc (1, sizeof (*ctx));
176178
if (!ctx)
@@ -182,7 +184,13 @@ static struct list_ctx *list_ctx_create (flux_t *h)
182184
goto error;
183185
if (!(ctx->isctx = idsync_ctx_create (ctx->h)))
184186
goto error;
185-
if (!(ctx->jsctx = job_state_create (ctx->isctx)))
187+
/* job_db_setup() performs a job_db_ctx_create() and some
188+
* initialization */
189+
if (!(ctx->dbctx = job_db_setup (h, argc, argv))) {
190+
if (errno != ENOTBLK)
191+
goto error;
192+
}
193+
if (!(ctx->jsctx = job_state_create (ctx->dbctx, ctx->isctx)))
186194
goto error;
187195
return ctx;
188196
error:
@@ -195,7 +203,7 @@ int mod_main (flux_t *h, int argc, char **argv)
195203
struct list_ctx *ctx;
196204
int rc = -1;
197205

198-
if (!(ctx = list_ctx_create (h))) {
206+
if (!(ctx = list_ctx_create (h, argc, argv))) {
199207
flux_log_error (h, "initialization error");
200208
goto done;
201209
}

src/modules/job-list/job-list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
#include "src/common/libczmqcontainers/czmq_containers.h"
1717

1818
#include "job_state.h"
19+
#include "job_db.h"
1920
#include "idsync.h"
2021

2122
struct list_ctx {
2223
flux_t *h;
2324
flux_msg_handler_t **handlers;
2425
struct job_state_ctx *jsctx;
26+
struct job_db_ctx *dbctx;
2527
struct idsync_ctx *isctx;
2628
};
2729

0 commit comments

Comments
 (0)