Skip to content

Commit 37e6006

Browse files
authored
Merge pull request #6775 from chu11/kvs_initial_rootref
kvs: support initial-rootref option
2 parents 7766d9b + a9f25c4 commit 37e6006

File tree

3 files changed

+108
-22
lines changed

3 files changed

+108
-22
lines changed

src/modules/kvs/kvs.c

Lines changed: 33 additions & 22 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,30 +2823,29 @@ 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));
2820-
2821-
/* primary namespace must always be there and not marked
2822-
* for removal
2823-
*/
2824-
if (!(root = kvsroot_mgr_lookup_root_safe (ctx->krm,
2825-
KVS_PRIMARY_NAMESPACE))) {
2826-
2827-
if (!(root = kvsroot_mgr_create_root (ctx->krm,
2828-
ctx->cache,
2829-
ctx->hash_name,
2830-
KVS_PRIMARY_NAMESPACE,
2831-
owner,
2832-
0))) {
2833-
flux_log_error (h, "kvsroot_mgr_create_root");
2834-
goto done;
2835-
}
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));
28362838
}
28372839

2840+
if (!(root = kvsroot_mgr_create_root (ctx->krm,
2841+
ctx->cache,
2842+
ctx->hash_name,
2843+
KVS_PRIMARY_NAMESPACE,
2844+
owner,
2845+
0))) {
2846+
flux_log_error (h, "kvsroot_mgr_create_root");
2847+
goto done;
2848+
}
28382849
setroot (ctx, root, rootref, seq);
28392850

28402851
if (event_subscribe (ctx, KVS_PRIMARY_NAMESPACE) < 0) {

t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ TESTSCRIPTS = \
108108
t1010-kvs-commit-sync.t \
109109
t1011-kvs-checkpoint-period.t \
110110
t1012-kvs-checkpoint.t \
111+
t1013-kvs-initial-rootref.t \
111112
t1101-barrier-basic.t \
112113
t1102-cmddriver.t \
113114
t1103-apidisconnect.t \

t/t1013-kvs-initial-rootref.t

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/sh
2+
#
3+
4+
test_description='Test kvs module initial-rootref option'
5+
6+
. `dirname $0`/kvs/kvs-helper.sh
7+
8+
. `dirname $0`/sharness.sh
9+
10+
RPC=${FLUX_BUILD_DIR}/t/request/rpc
11+
12+
export FLUX_CONF_DIR=$(pwd)
13+
SIZE=4
14+
test_under_flux ${SIZE} minimal -Sstatedir=$(pwd)
15+
16+
test_expect_success 'load content, content-sqlite, and kvs' '
17+
flux module load content &&
18+
flux module load content-sqlite &&
19+
flux module load kvs
20+
'
21+
22+
test_expect_success 'kvs: put some data to kvs' '
23+
flux kvs put --blobref data=1 > blob1.out &&
24+
flux kvs put --blobref data=2 > blob2.out &&
25+
flux kvs put --blobref data=3 > blob3.out &&
26+
flux kvs put --blobref data=4 > blob4.out &&
27+
flux kvs put --blobref data=5 > blob5.out
28+
'
29+
30+
test_expect_success 'kvs: reload kvs' '
31+
flux module reload kvs
32+
'
33+
34+
test_expect_success 'kvs: data should be last written' '
35+
echo "5" > data1.exp &&
36+
flux kvs get data > data1.out &&
37+
test_cmp data1.out data1.exp
38+
'
39+
40+
test_expect_success 'kvs: root should be last one' '
41+
flux kvs getroot -b > getroot1.out &&
42+
test_cmp getroot1.out blob5.out
43+
'
44+
45+
test_expect_success 'kvs: reload kvs with different initial rootref' '
46+
ref=$(cat blob3.out) &&
47+
flux module reload kvs initial-rootref="$ref"
48+
'
49+
50+
test_expect_success 'kvs: data should be previous one' '
51+
echo "3" > data2.exp &&
52+
flux kvs get data > data2.out &&
53+
test_cmp data2.out data2.exp
54+
'
55+
56+
test_expect_success 'kvs: root should be previous one' '
57+
flux kvs getroot -b > getroot2.out &&
58+
test_cmp getroot2.out blob3.out
59+
'
60+
61+
test_expect_success 'kvs: remove kvs module' '
62+
flux module remove kvs
63+
'
64+
65+
test_expect_success 'kvs: load kvs with bad rootref' '
66+
test_must_fail flux module reload kvs initial-rootref="abcdefghijklmnop"
67+
'
68+
69+
test_expect_success 'kvs: remove modules' '
70+
flux module remove content-sqlite &&
71+
flux module remove content
72+
'
73+
74+
test_done

0 commit comments

Comments
 (0)