Skip to content

Commit 86e05aa

Browse files
authored
Merge pull request #5256 from grondo/issue#5243
switch from decimal to f58 jobid encoding in most log messages and shell service name
2 parents a6afc80 + 6ed8137 commit 86e05aa

32 files changed

+319
-279
lines changed

src/cmd/flux-job.c

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "src/common/libutil/jpath.h"
4444
#include "src/common/libjob/job.h"
4545
#include "src/common/libjob/unwrap.h"
46+
#include "src/common/libjob/idf58.h"
4647
#include "src/common/libutil/read_all.h"
4748
#include "src/common/libutil/monotime.h"
4849
#include "src/common/libutil/fsd.h"
@@ -1462,11 +1463,7 @@ size_t read_jobspec (const char *name, void **bufp)
14621463

14631464
static void print_jobid (flux_jobid_t id)
14641465
{
1465-
char buf[32];
1466-
if (flux_job_id_encode (id, "f58", buf, sizeof (buf)) < 0)
1467-
printf ("%ju\n", (uintmax_t) id);
1468-
else
1469-
printf ("%s\n", buf);
1466+
printf ("%s\n", idf58 (id));
14701467
}
14711468

14721469
int cmd_submit (optparse_t *p, int argc, char **argv)
@@ -3286,6 +3283,7 @@ void info_usage (void)
32863283
}
32873284

32883285
struct info_ctx {
3286+
const char *id_arg;
32893287
flux_jobid_t id;
32903288
json_t *keys;
32913289
bool original;
@@ -3298,7 +3296,7 @@ void info_output (flux_future_t *f, const char *suffix, struct info_ctx *ctx)
32983296
if (flux_rpc_get_unpack (f, "{s:s}", suffix, &s) < 0) {
32993297
if (errno == ENOENT) {
33003298
flux_future_destroy (f);
3301-
log_msg_exit ("job %ju id or key not found", (uintmax_t)ctx->id);
3299+
log_msg_exit ("job %s id or key not found", ctx->id_arg);
33023300
}
33033301
else
33043302
log_err_exit ("flux_rpc_get_unpack");
@@ -3343,6 +3341,7 @@ void info_lookup (flux_t *h,
33433341
flux_future_t *f;
33443342
struct info_ctx ctx = {0};
33453343

3344+
ctx.id_arg = argv[optindex-1];
33463345
ctx.id = id;
33473346
if (!(ctx.keys = json_array ()))
33483347
log_msg_exit ("json_array");
@@ -3426,13 +3425,6 @@ int cmd_stats (optparse_t *p, int argc, char **argv)
34263425
return (0);
34273426
}
34283427

3429-
static char *to_f58 (flux_jobid_t id, char *buf, int len)
3430-
{
3431-
if (flux_job_id_encode (id, "f58", buf, len) < 0)
3432-
(void) snprintf (buf, len, "%ju", (uintmax_t) id);
3433-
return buf;
3434-
}
3435-
34363428
int cmd_wait (optparse_t *p, int argc, char **argv)
34373429
{
34383430
flux_t *h;
@@ -3441,7 +3433,6 @@ int cmd_wait (optparse_t *p, int argc, char **argv)
34413433
flux_jobid_t id = FLUX_JOBID_ANY;
34423434
bool success;
34433435
const char *errstr;
3444-
char buf[32];
34453436
int rc = 0;
34463437

34473438
if ((argc - optindex) > 1) {
@@ -3472,16 +3463,14 @@ int cmd_wait (optparse_t *p, int argc, char **argv)
34723463
log_msg_exit ("flux_job_wait_get_id: %s",
34733464
future_strerror (f, errno));
34743465
if (!success) {
3475-
fprintf (stderr, "%s: %s\n",
3476-
to_f58 (id, buf, sizeof (buf)),
3477-
errstr);
3466+
fprintf (stderr, "%s: %s\n", idf58 (id), errstr);
34783467
rc = 1;
34793468
}
34803469
else {
34813470
if (optparse_hasopt (p, "verbose"))
34823471
fprintf (stderr,
34833472
"%s: job completed successfully\n",
3484-
to_f58 (id, buf, sizeof (buf)));
3473+
idf58 (id));
34853474
}
34863475
flux_future_destroy (f);
34873476
}
@@ -3502,7 +3491,7 @@ int cmd_wait (optparse_t *p, int argc, char **argv)
35023491
if (id == FLUX_JOBID_ANY) {
35033492
if (flux_job_wait_get_id (f, &id) < 0)
35043493
log_err_exit ("flux_job_wait_get_id");
3505-
printf ("%s\n", to_f58 (id, buf, sizeof (buf)));
3494+
printf ("%s\n", idf58 (id));
35063495
}
35073496
if (!success)
35083497
log_msg_exit ("%s", errstr);
@@ -3902,7 +3891,6 @@ int cmd_last (optparse_t *p, int argc, char **argv)
39023891
int optindex = optparse_option_index (p);
39033892
flux_future_t *f;
39043893
flux_t *h;
3905-
char buf[32];
39063894
json_t *jobs;
39073895
size_t index;
39083896
json_t *entry;
@@ -3941,12 +3929,8 @@ int cmd_last (optparse_t *p, int argc, char **argv)
39413929
}
39423930
if (json_array_size (jobs) == 0)
39433931
log_msg_exit ("job history is empty");
3944-
json_array_foreach (jobs, index, entry) {
3945-
flux_jobid_t id = json_integer_value (entry);
3946-
if (flux_job_id_encode (id, "f58", buf, sizeof (buf)) < 0)
3947-
log_err_exit ("error encoding job ID");
3948-
printf ("%s\n", buf);
3949-
}
3932+
json_array_foreach (jobs, index, entry)
3933+
printf ("%s\n", idf58 (json_integer_value (entry)));
39503934
flux_future_destroy (f);
39513935
flux_close (h);
39523936
return 0;

src/cmd/top/joblist_pane.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <jansson.h>
1919

2020
#include "src/common/libutil/fsd.h"
21+
#include "src/common/libjob/idf58.h"
2122
#include "ccan/str/str.h"
2223

2324
#include "top.h"
@@ -116,7 +117,7 @@ void joblist_pane_draw (struct joblist_pane *joblist)
116117

117118
json_array_foreach (joblist->jobs, index, job) {
118119
char *uri = NULL;
119-
char idstr[16];
120+
const char *idstr;
120121
char run[16] = "";
121122
flux_jobid_t id;
122123
int userid;
@@ -143,8 +144,7 @@ void joblist_pane_draw (struct joblist_pane *joblist)
143144
"uri", &uri) < 0)
144145
fatal (0, "error decoding a job record from job-list RPC");
145146

146-
if (flux_job_id_encode (id, "f58", idstr, sizeof (idstr)) < 0)
147-
fatal (errno, "error encoding jobid as F58");
147+
idstr = idf58 (id);
148148
(void)fsd_format_duration_ex (run, sizeof (run), fabs (now - t_run), 2);
149149
if (!(username = ucache_lookup (joblist->ucache, userid)))
150150
fatal (errno, "error looking up userid %d in ucache", (int)userid);
@@ -314,7 +314,6 @@ void joblist_pane_enter (struct joblist_pane *joblist)
314314
flux_jobid_t id;
315315
char *uri = NULL;
316316
char title [1024];
317-
char jobid [24];
318317
flux_error_t error;
319318

320319
json_t *job = get_current_job (joblist);
@@ -329,12 +328,11 @@ void joblist_pane_enter (struct joblist_pane *joblist)
329328
return;
330329
if (uri == NULL)
331330
return;
332-
if (flux_job_id_encode (id, "f58", jobid, sizeof (jobid)) < 0
333-
|| snprintf (title,
334-
sizeof(title),
335-
"%s/%s",
336-
joblist->top->title,
337-
jobid) > sizeof (title))
331+
if (snprintf (title,
332+
sizeof(title),
333+
"%s/%s",
334+
joblist->top->title,
335+
idf58 (id)) > sizeof (title))
338336
fatal (errno, "failed to build job title for job");
339337

340338
/* Lazily attempt to run top on jobid, but for now simply return to the

src/cmd/top/top.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "src/common/libutil/uri.h"
1919
#include "src/common/libutil/errprintf.h"
20+
#include "src/common/libjob/idf58.h"
2021
#include "ccan/str/str.h"
2122
#include "top.h"
2223

@@ -224,18 +225,8 @@ static flux_jobid_t get_jobid (flux_t *h)
224225

225226
static char * build_title (struct top *top, const char *title)
226227
{
227-
if (!title) {
228-
char jobid [24];
229-
title = "";
230-
if (top->id != FLUX_JOBID_ANY) {
231-
if (flux_job_id_encode (top->id,
232-
"f58",
233-
jobid,
234-
sizeof (jobid)) < 0)
235-
fatal (errno, "failed to build jobid");
236-
title = jobid;
237-
}
238-
}
228+
if (!title)
229+
title = idf58 (top->id);
239230
return strdup (title);
240231
}
241232

src/common/libjob/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ libjob_la_SOURCES = \
3939
jj.c \
4040
jj.h \
4141
unwrap.c \
42-
unwrap.h
42+
unwrap.h \
43+
idf58.h
4344

4445
TESTS = \
4546
test_job.t \

src/common/libjob/idf58.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 _IDF58_H
12+
#define _IDF58_H
13+
14+
#include <flux/core.h>
15+
16+
/* Convenience function to convert a flux_jobid_t to F58 encoding
17+
* If the encode fails (unlikely), then the decimal encoding is returned.
18+
*/
19+
static inline const char *idf58 (flux_jobid_t id)
20+
{
21+
static __thread char buf[21];
22+
if (flux_job_id_encode (id, "f58", buf, sizeof (buf)) < 0) {
23+
/* 64bit integer is guaranteed to fit in 21 bytes
24+
* floor(log(2^64-1)/log(1)) + 1 = 20
25+
*/
26+
(void) sprintf (buf, "%ju", (uintmax_t) id);
27+
}
28+
return buf;
29+
}
30+
31+
#endif /* !_IDF58_H */
32+
33+
/*
34+
* vi:tabstop=4 shiftwidth=4 expandtab
35+
*/

src/common/libschedutil/hello.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <flux/core.h>
1515
#include <jansson.h>
1616

17+
#include "src/common/libjob/idf58.h"
1718
#include "schedutil_private.h"
1819
#include "init.h"
1920
#include "hello.h"
@@ -25,14 +26,14 @@ static void raise_exception (flux_t *h, flux_jobid_t id, const char *note)
2526

2627
flux_log (h,
2728
LOG_INFO,
28-
"raising fatal exception on running job id=%ju",
29-
(uintmax_t)id);
29+
"raising fatal exception on running job id=%s",
30+
idf58 (id));
3031

3132
if (!(f = flux_job_raise (h, id, "scheduler-restart", 0, note))
3233
|| flux_future_get (f, NULL) < 0) {
3334
flux_log_error (h,
34-
"error raising fatal exception on %ju: %s",
35-
(uintmax_t)id,
35+
"error raising fatal exception on %s: %s",
36+
idf58 (id),
3637
future_strerror (f, errno));
3738
}
3839
flux_future_destroy (f);
@@ -64,8 +65,8 @@ static int schedutil_hello_job (schedutil_t *util,
6465
flux_future_destroy (f);
6566
return 0;
6667
error:
67-
flux_log_error (util->h, "hello: error loading R for id=%ju",
68-
(uintmax_t)id);
68+
flux_log_error (util->h, "hello: error loading R for id=%s",
69+
idf58 (id));
6970
flux_future_destroy (f);
7071
return -1;
7172
}

src/modules/job-archive/job-archive.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "src/common/libutil/fsd.h"
2929
#include "src/common/libutil/tstat.h"
3030
#include "src/common/libutil/monotime.h"
31+
#include "src/common/libjob/idf58.h"
3132

3233
#define BUSY_TIMEOUT_DEFAULT 50
3334
#define BUFSIZE 1024
@@ -298,8 +299,8 @@ void job_info_lookup_continuation (flux_future_t *f, void *arg)
298299
"t_run", &t_run,
299300
"t_cleanup", &t_cleanup,
300301
"t_inactive", &t_inactive) < 0) {
301-
flux_log (ctx->h, LOG_ERR, "%s: parse job %ju error: %s",
302-
__FUNCTION__, (uintmax_t)id, error.text);
302+
flux_log (ctx->h, LOG_ERR, "%s: parse job %s error: %s",
303+
__FUNCTION__, idf58 (id), error.text);
303304
goto out;
304305
}
305306

src/modules/job-exec/bulk-exec.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "src/common/libczmqcontainers/czmq_containers.h"
2222
#include "src/common/libutil/aux.h"
23+
#include "src/common/libjob/idf58.h"
2324
#include "bulk-exec.h"
2425

2526
struct exec_cmd {
@@ -491,8 +492,8 @@ void bulk_exec_kill_log_error (flux_future_t *f, flux_jobid_t id)
491492
if (flux_future_get (cf, NULL) < 0) {
492493
uint32_t rank = flux_rpc_get_nodeid (cf);
493494
flux_log_error (h,
494-
"%ju: exec_kill: %s (rank %lu)",
495-
(uintmax_t) id,
495+
"%s: exec_kill: %s (rank %lu)",
496+
idf58 (id),
496497
flux_get_hostbyrank (h, rank),
497498
(unsigned long)rank);
498499
}

src/modules/job-exec/exec.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <unistd.h>
3434

35+
#include "src/common/libjob/idf58.h"
3536
#include "ccan/str/str.h"
3637

3738
#include "job-exec.h"
@@ -457,18 +458,20 @@ static int exec_kill (struct jobinfo *job, int signum)
457458
f = bulk_exec_kill (exec, signum);
458459
if (!f) {
459460
if (errno != ENOENT)
460-
flux_log_error (job->h, "%ju: bulk_exec_kill", job->id);
461+
flux_log_error (job->h, "%s: bulk_exec_kill", idf58 (job->id));
461462
return 0;
462463
}
463464

464465
flux_log (job->h, LOG_DEBUG,
465-
"exec_kill: %ju: signal %d",
466-
(uintmax_t) job->id,
466+
"exec_kill: %s: signal %d",
467+
idf58 (job->id),
467468
signum);
468469

469470
jobinfo_incref (job);
470471
if (flux_future_then (f, 3., exec_kill_cb, job) < 0) {
471-
flux_log_error (job->h, "%ju: exec_kill: flux_future_then", job->id);
472+
flux_log_error (job->h,
473+
"%s: exec_kill: flux_future_then",
474+
idf58 (job->id));
472475
flux_future_destroy (f);
473476
return -1;
474477
}

0 commit comments

Comments
 (0)