Skip to content

Commit 69711aa

Browse files
authored
Merge pull request #5840 from garlick/issue#5778
make KVS garbage collection automatic
2 parents 99ea1fc + f113df8 commit 69711aa

File tree

9 files changed

+94
-2
lines changed

9 files changed

+94
-2
lines changed

doc/man1/flux-shutdown.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ OPTIONS
8282
the dump, and the link is removed. :linux:man8:`systemd-tmpfiles`
8383
automatically cleans up dump files in ``/var/lib/flux/dump`` after 30 days.
8484

85+
.. option:: --skip-gc
86+
87+
When garbage collection has been enabled automatically, as indicated
88+
by the ``content.dump`` broker attribute, this option disables it
89+
during shutdown. Otherwise it is a preemptive "no" answer to the garbage
90+
collection prompt.
91+
8592
.. option:: -y, --yes
8693

8794
Answer yes to any yes/no questions.

etc/flux.service.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Wants=munge.service
44

55
[Service]
66
Type=notify
7-
NotifyAccess=main
7+
NotifyAccess=all
88
TimeoutStopSec=90
99
KillMode=mixed
1010
ExecStart=/bin/bash -c '\
@@ -23,6 +23,7 @@ ExecStart=/bin/bash -c '\
2323
-Sbroker.quorum-timeout=none \
2424
-Sbroker.exit-norestart=42 \
2525
-Sbroker.sd-notify=1 \
26+
-Scontent.dump=auto \
2627
-Scontent.restore=auto \
2728
'
2829
SyslogIdentifier=flux

src/cmd/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ AM_CPPFLAGS = \
1414
$(FLUX_SECURITY_CFLAGS) \
1515
$(HWLOC_CFLAGS) \
1616
$(JANSSON_CFLAGS) \
17+
$(LIBSYSTEMD_CFLAGS) \
1718
$(LIBARCHIVE_CFLAGS)
1819

1920

@@ -87,6 +88,7 @@ flux_LDADD = \
8788
$(top_builddir)/src/common/libpmi/libpmi_common.la \
8889
$(top_builddir)/src/common/libfilemap/libfilemap.la \
8990
$(LIBARCHIVE_LIBS) \
91+
$(LIBSYSTEMD_LIBS) \
9092
$(fluxcmd_ldadd)
9193

9294
#

src/cmd/builtin/dump.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#if HAVE_CONFIG_H
1212
# include <config.h>
1313
#endif
14+
#if HAVE_LIBSYSTEMD
15+
#include <systemd/sd-daemon.h>
16+
#endif
1417
#include <unistd.h>
1518
#include <stdarg.h>
1619
#include <jansson.h>
@@ -33,6 +36,7 @@ static void dump_treeobj (struct archive *ar,
3336
const char *path,
3437
json_t *treeobj);
3538

39+
static bool sd_notify_flag;
3640
static bool verbose;
3741
static bool quiet;
3842
static int content_flags;
@@ -49,12 +53,24 @@ static void progress (int delta_keys)
4953
&& !quiet
5054
&& (keycount % 100 == 0 || keycount < 10))
5155
fprintf (stderr, "\rflux-dump: archived %d keys", keycount);
56+
#if HAVE_LIBSYSTEMD
57+
if (sd_notify_flag
58+
&& (keycount % 100 == 0 || keycount < 10)) {
59+
sd_notifyf (0, "EXTEND_TIMEOUT_USEC=%d", 10000000); // 10s
60+
sd_notifyf (0, "STATUS=flux-dump(1) has archived %d keys", keycount);
61+
}
62+
#endif
5263
}
5364

5465
static void progress_end (void)
5566
{
5667
if (!quiet && !verbose)
5768
fprintf (stderr, "\rflux-dump: archived %d keys\n", keycount);
69+
#if HAVE_LIBSYSTEMD
70+
if (sd_notify_flag) {
71+
sd_notifyf (0, "STATUS=flux-dump(1) has archived %d keys", keycount);
72+
}
73+
#endif
5874
}
5975

6076
static struct archive *dump_create (const char *outfile)
@@ -369,6 +385,15 @@ static int cmd_dump (optparse_t *p, int ac, char *av[])
369385
dump_gid = getgid ();
370386

371387
h = builtin_get_flux_handle (p);
388+
389+
/* If the broker is using sd_notify(3) to talk to systemd during
390+
* start/stop, we can use it to ensure systemd doesn't kill us
391+
* while dumping during shutdown. See flux-framework/flux-core#5778.
392+
*/
393+
const char *s;
394+
if ((s = flux_attr_get (h, "broker.sd-notify")) && !streq (s, "0"))
395+
sd_notify_flag = true;
396+
372397
ar = dump_create (outfile);
373398
if (optparse_hasopt (p, "checkpoint")) {
374399
flux_future_t *f;

src/cmd/builtin/restore.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#if HAVE_CONFIG_H
1212
# include <config.h>
1313
#endif
14+
#if HAVE_LIBSYSTEMD
15+
#include <systemd/sd-daemon.h>
16+
#endif
1417
#include <unistd.h>
1518
#include <stdarg.h>
1619
#include <jansson.h>
@@ -35,6 +38,7 @@
3538

3639
#define BLOCKSIZE 10240 // taken from libarchive example
3740

41+
static bool sd_notify_flag;
3842
static bool verbose;
3943
static bool quiet;
4044
static int content_flags;
@@ -56,6 +60,13 @@ static void progress (int delta_blob, int delta_keys)
5660
keycount,
5761
blobcount);
5862
}
63+
#if HAVE_LIBSYSTEMD
64+
if (sd_notify_flag
65+
&& (keycount % 100 == 0 || keycount < 10)) {
66+
sd_notifyf (0, "EXTEND_TIMEOUT_USEC=%d", 10000000); // 10s
67+
sd_notifyf (0, "STATUS=flux-restore(1) has restored %d keys", keycount);
68+
}
69+
#endif
5970
}
6071
static void progress_end (void)
6172
{
@@ -65,6 +76,11 @@ static void progress_end (void)
6576
keycount,
6677
blobcount);
6778
}
79+
#if HAVE_LIBSYSTEMD
80+
if (sd_notify_flag) {
81+
sd_notifyf (0, "STATUS=flux-restore(1) has restored %d keys", keycount);
82+
}
83+
#endif
6884
}
6985

7086
static struct archive *restore_create (const char *infile)
@@ -377,6 +393,11 @@ static int cmd_restore (optparse_t *p, int ac, char *av[])
377393
blob_size_limit = optparse_get_size_int (p, "size-limit", "0");
378394

379395
h = builtin_get_flux_handle (p);
396+
397+
const char *s;
398+
if ((s = flux_attr_get (h, "broker.sd-notify")) && !streq (s, "0"))
399+
sd_notify_flag = true;
400+
380401
ar = restore_create (infile);
381402

382403
if (optparse_hasopt (p, "checkpoint")) {

src/cmd/builtin/shutdown.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ static bool gc_threshold_check (flux_t *h, optparse_t *p)
7474
get_gc_threshold (h, &gc_threshold);
7575

7676
if (gc_threshold > 0 && version > gc_threshold) {
77-
if (optparse_hasopt (p, "yes") || optparse_hasopt (p, "no")) {
77+
if (optparse_hasopt (p, "yes")
78+
|| optparse_hasopt (p, "no")
79+
|| optparse_hasopt (p, "skip-gc")) {
7880
if (optparse_hasopt (p, "yes"))
7981
rc = true;
8082
else
@@ -143,6 +145,11 @@ static int subcmd (optparse_t *p, int ac, char *av[])
143145
if (optparse_hasopt (p, "background"))
144146
flags &= ~FLUX_RPC_STREAMING;
145147

148+
if (optparse_hasopt (p, "skip-gc")) {
149+
if (flux_attr_set (h, "content.dump", "") < 0)
150+
log_err_exit ("error clearing content.dump attribute");
151+
}
152+
146153
if (optparse_hasopt (p, "gc")
147154
|| optparse_hasopt (p, "dump")
148155
|| gc_threshold_check (h, p)) {
@@ -176,6 +183,9 @@ static int subcmd (optparse_t *p, int ac, char *av[])
176183
}
177184

178185
static struct optparse_option opts[] = {
186+
{ .name = "skip-gc", .has_arg = 0,
187+
.usage = "Skip KVS garbage collection this time, if already enabled",
188+
},
179189
{ .name = "gc", .has_arg = 0,
180190
.usage = "Garbage collect KVS (short for --dump=auto)",
181191
},

t/system/0004-recovery.t

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ test_expect_success 'flux start --recover works from dump file' '
2020
test_expect_success 'restart flux' '
2121
sudo systemctl start flux
2222
'
23+
get_uptime_state () {
24+
local state=$(flux uptime | cut -d' ' -f3) || state=unknown
25+
echo $state
26+
}
27+
test_expect_success 'wait for flux to reach run state' '
28+
while test $(get_uptime_state) != run; do \
29+
sleep 1; \
30+
done
31+
'

t/t2808-shutdown-cmd.t

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,5 +315,20 @@ test_expect_success 'clean up dump files from previous tests' '
315315
rm -f dump.tgz &&
316316
rm -f dump/RESTORE
317317
'
318+
test_expect_success 'submit batch with dump=auto and wait for it to start (8)' '
319+
cat >batch.sh <<-EOT &&
320+
#!/bin/sh
321+
touch job8-has-started
322+
flux run sleep 300
323+
EOT
324+
chmod +x batch.sh &&
325+
flux batch -t30m -n1 \
326+
--broker-opts=-Scontent.dump=auto batch.sh >jobid8 &&
327+
$waitfile job8-has-started
328+
'
329+
test_expect_success 'shutdown --skip-gc does not produce dump' '
330+
FLUX_URI=$(flux uri --local $(cat jobid8)) flux shutdown --skip-gc &&
331+
test_must_fail tar tvf dump/RESTORE
332+
'
318333

319334
test_done

t/t9000-system.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ if test -n "$FLUX_ENABLE_SYSTEM_TESTS"; then
1313
FLUX_TEST_INSTALLED_PATH=${FLUX_TEST_INSTALLED_PATH:-/usr/bin}
1414
fi
1515
fi
16+
# Append --logfile option if FLUX_TESTS_LOGFILE is set in environment:
17+
test -n "$FLUX_TESTS_LOGFILE" && set -- "$@" --logfile
1618
. `dirname $0`/sharness.sh
1719

1820
# Do not run system tests by default unless FLUX_ENABLE_SYSTEM_TESTS

0 commit comments

Comments
 (0)