Skip to content

Commit 19a5d5c

Browse files
committed
kvs: support initial-rootref option
Problem: The only way for the KVS to start with a non-default root reference is to read a root reference from the content module's checkpoint service. There is no way to initialize the KVS with a specific root reference. Allowing users to select an initial root reference could be useful for debugging and testing, especially when multiple checkpoints exist. Support a initial-rootref option.
1 parent 6f15692 commit 19a5d5c

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/modules/kvs/kvs.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ struct kvs_ctx {
7373
flux_watcher_t *idle_w;
7474
flux_watcher_t *check_w;
7575
int transaction_merge;
76+
char initial_rootref[BLOBREF_MAX_STRING_SIZE];
77+
bool initial_rootref_set;
7678
bool events_init; /* flag */
7779
char *hash_name;
7880
unsigned int seq; /* for commit transactions */
@@ -2641,6 +2643,16 @@ static int process_args (struct kvs_ctx *ctx, int ac, char **av)
26412643
return -1;
26422644
}
26432645
}
2646+
else if (strstarts (av[i], "initial-rootref=")) {
2647+
char *ptr = av[i] + 16;
2648+
if (strlen (ptr) > BLOBREF_MAX_STRING_SIZE
2649+
|| blobref_validate (ptr) < 0) {
2650+
errno = EINVAL;
2651+
return -1;
2652+
}
2653+
memcpy (ctx->initial_rootref, ptr, strlen (ptr));
2654+
ctx->initial_rootref_set = true;
2655+
}
26442656
else {
26452657
flux_log (ctx->h, LOG_ERR, "Unknown option `%s'", av[i]);
26462658
errno = EINVAL;
@@ -2811,12 +2823,19 @@ int mod_main (flux_t *h, int argc, char **argv)
28112823
goto done;
28122824
}
28132825

2814-
/* Look for a checkpoint and use it if found.
2815-
* Otherwise start the primary root namespace with an empty directory
2816-
* and seq = 0.
2817-
*/
2818-
if (checkpoint_get (h, rootref, sizeof (rootref), &seq) < 0)
2819-
memcpy (rootref, empty_dir_rootref, sizeof (empty_dir_rootref));
2826+
if (ctx->initial_rootref_set) {
2827+
memcpy (rootref,
2828+
ctx->initial_rootref,
2829+
sizeof (ctx->initial_rootref));
2830+
}
2831+
else {
2832+
/* Look for a checkpoint and use it if found. Otherwise
2833+
* start the primary root namespace with an empty
2834+
* directory and seq = 0.
2835+
*/
2836+
if (checkpoint_get (h, rootref, sizeof (rootref), &seq) < 0)
2837+
memcpy (rootref, empty_dir_rootref, sizeof (empty_dir_rootref));
2838+
}
28202839

28212840
if (!(root = kvsroot_mgr_create_root (ctx->krm,
28222841
ctx->cache,

0 commit comments

Comments
 (0)