Skip to content

Commit 0a925f9

Browse files
committed
shell/stage-in: use new KVS archive format
Problem: the shell stage-in plugin only works with mmapped files. Rename the stage-in.tags option to stage-in.keys and change the code so it reads the main archive from the KVS. Rework the stage-in sharness test so it does most of the same things as before but using the new tooling.
1 parent f9788dc commit 0a925f9

File tree

2 files changed

+68
-52
lines changed

2 files changed

+68
-52
lines changed

src/shell/stage-in.c

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
* SPDX-License-Identifier: LGPL-3.0
99
\************************************************************/
1010

11-
/* stage-in.c - copy previously mapped files for job */
11+
/* stage-in.c - copy previously archived files for job */
1212

1313
#define FLUX_SHELL_PLUGIN_NAME "stage-in"
1414

1515
#if HAVE_CONFIG_H
1616
#include "config.h"
1717
#endif
18+
#include <fnmatch.h>
1819
#include <unistd.h>
1920
#include <limits.h>
2021
#include <stdlib.h>
@@ -42,15 +43,15 @@
4243
#include "info.h"
4344

4445
struct stage_in {
45-
json_t *tags;
46+
json_t *names;
4647
const char *pattern;
4748
const char *destdir;
4849
flux_t *h;
4950
int count;
5051
size_t total_size;
5152
};
5253

53-
json_t *parse_tags (const char *s, const char *default_value)
54+
json_t *parse_names (const char *s, const char *default_value)
5455
{
5556
char *argz = NULL;
5657
size_t argz_len;
@@ -107,37 +108,51 @@ static void trace_cb (void *arg,
107108

108109
static int extract (struct stage_in *ctx)
109110
{
110-
flux_future_t *f;
111+
size_t i;
112+
json_t *nameobj;
111113

112-
if (!(f = filemap_mmap_list (ctx->h,
113-
false,
114-
ctx->tags,
115-
ctx->pattern))) {
116-
shell_log_error ("mmap-list: %s", strerror (errno));
117-
return -1;
118-
}
119-
for (;;) {
120-
json_t *files;
114+
json_array_foreach (ctx->names, i, nameobj) {
115+
char *key = NULL;
116+
flux_future_t *f = NULL;
117+
json_t *archive;
121118
flux_error_t error;
122119

123-
if (flux_rpc_get_unpack (f, "{s:o}", "files", &files) < 0) {
124-
if (errno == ENODATA)
125-
break; // end of stream
126-
shell_log_error ("mmap-list: %s", future_strerror (f, errno));
120+
if (asprintf (&key, "archive.%s", json_string_value (nameobj)) < 0
121+
|| !(f = flux_kvs_lookup (ctx->h, "primary", 0, key))
122+
|| flux_kvs_lookup_get_unpack (f, "o", &archive) < 0) {
123+
shell_log_error ("could not lookup %s in primary KVS namespace: %s",
124+
key,
125+
future_strerror (f, errno));
126+
flux_future_destroy (f);
127127
return -1;
128128
}
129+
if (ctx->pattern) {
130+
size_t index = 0;
131+
while (index < json_array_size (archive)) {
132+
json_t *entry;
133+
const char *path;
134+
135+
if (!(entry = json_array_get (archive, index))
136+
|| json_unpack (entry, "{s:s}", "path", &path) < 0
137+
|| fnmatch (ctx->pattern, path, 0) != 0) {
138+
json_array_remove (archive, index);
139+
continue;
140+
}
141+
index++;
142+
}
143+
}
129144
if (filemap_extract (ctx->h,
130-
files,
145+
archive,
131146
0,
132147
&error,
133148
trace_cb,
134149
ctx) < 0) {
135150
shell_log_error ("%s", error.text);
151+
flux_future_destroy (f);
136152
return -1;
137153
}
138-
flux_future_reset (f);
154+
flux_future_destroy (f);
139155
}
140-
flux_future_destroy (f);
141156
return 0;
142157
}
143158

@@ -181,7 +196,7 @@ static int extract_files (struct stage_in *ctx)
181196
static int stage_in (flux_shell_t *shell, json_t *config)
182197
{
183198
struct stage_in ctx;
184-
const char *tags = NULL;
199+
const char *names = NULL;
185200
const char *destination = NULL;
186201
bool leader_only = false;
187202

@@ -191,15 +206,15 @@ static int stage_in (flux_shell_t *shell, json_t *config)
191206
if (json_is_object (config)) {
192207
if (json_unpack (config,
193208
"{s?s s?s s?s}",
194-
"tags", &tags,
209+
"names", &names,
195210
"pattern", &ctx.pattern,
196211
"destination", &destination)) {
197212
shell_log_error ("Error parsing stage_in shell option");
198213
goto error;
199214
}
200215
}
201-
if (!(ctx.tags = parse_tags (tags, "main"))) {
202-
shell_log_error ("Error parsing stage_in.tags shell option");
216+
if (!(ctx.names = parse_names (names, "main"))) {
217+
shell_log_error ("Error parsing stage_in.names shell option");
203218
goto error;
204219
}
205220
if (destination) {
@@ -228,10 +243,10 @@ static int stage_in (flux_shell_t *shell, json_t *config)
228243
goto error;
229244
}
230245

231-
json_decref (ctx.tags);
246+
json_decref (ctx.names);
232247
return 0;
233248
error:
234-
json_decref (ctx.tags);
249+
json_decref (ctx.names);
235250
return -1;
236251
}
237252

t/t2617-job-shell-stage-in.t

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,31 @@ lptest=${FLUX_BUILD_DIR}/t/shell/lptest
88

99
test_under_flux 4 job
1010

11-
test_expect_success 'map the red test files' '
11+
test_expect_success 'archive the red test files' '
1212
mkdir red &&
1313
touch red/empty &&
1414
truncate --size 8192 red/holy &&
1515
$lptest >red/lptest &&
1616
echo foo >red/small &&
1717
mkdir red/dir &&
1818
ln -s dir red/link &&
19-
flux filemap map -vv --tags red red
19+
flux archive create -v --name=red red
2020
'
21-
test_expect_success 'map the blue test files' '
21+
test_expect_success 'archive the blue test files' '
2222
dir=blue/a/b/c/d/e/f/g/h &&
2323
mkdir -p $dir &&
2424
echo bar >$dir/test &&
25-
flux filemap map -vv --tags blue blue
25+
flux archive create -v --name=blue blue
2626
'
27-
test_expect_success 'map the main test files' '
27+
test_expect_success 'archive the main test files' '
2828
mkdir main &&
2929
echo "Hello world!" >main/hello &&
30-
flux filemap map -vv main
30+
flux archive create -v main
3131
'
3232
test_expect_success 'list all the files' '
33-
flux filemap list --long --tags=red,blue,main
33+
flux archive extract --list-only -v --name=red &&
34+
flux archive extract --list-only -v --name=blue &&
35+
flux archive extract --list-only -v
3436
'
3537
test_expect_success 'create file tree checker script' '
3638
cat >check.sh <<-EOT &&
@@ -41,24 +43,18 @@ test_expect_success 'create file tree checker script' '
4143
EOT
4244
chmod 755 check.sh
4345
'
44-
test_expect_success 'verify that stage-in works with default tag (main)' '
46+
test_expect_success 'verify that stage-in works with default key (main)' '
4547
flux run -N4 -ostage-in ./check.sh main
4648
'
47-
test_expect_success 'verify that stage-in works with tags=red' '
48-
flux run -N2 -ostage-in.tags=red ./check.sh red
49+
test_expect_success 'verify that stage-in works with names=red' '
50+
flux run -N2 -ostage-in.names=red ./check.sh red
4951
'
50-
test_expect_success 'verify that stage-in works with tags=red,blue' '
51-
flux run -N1 -ostage-in.tags=red,blue ./check.sh red blue
52-
'
53-
test_expect_success 'verify that stage-in.direct works' '
54-
flux run -N1 \
55-
-ostage-in.tags=red \
56-
-ostage-in.direct \
57-
./check.sh red
52+
test_expect_success 'verify that stage-in works with names=red,blue' '
53+
flux run -N1 -ostage-in.names=red,blue ./check.sh red blue
5854
'
5955
test_expect_success 'verify that stage-in.pattern works' '
6056
flux run -N1 \
61-
-ostage-in.tags=red,blue \
57+
-ostage-in.names=red,blue \
6258
-ostage-in.pattern=red/* \
6359
-overbose=2 \
6460
./check.sh red 2>pattern.err
@@ -99,17 +95,22 @@ test_expect_success 'verify that stage-in.destination fails on bad prefix' '
9995
-o stage-in.destination=wrong:$(pwd)/testdest \
10096
/bin/true
10197
'
102-
test_expect_success 'unmap all' '
103-
flux filemap unmap --tags=red,blue,main
98+
test_expect_success 'remove archives' '
99+
flux archive remove &&
100+
flux archive remove --name=blue &&
101+
flux archive remove --name=red
102+
'
103+
test_expect_success 'create a test file with random content' '
104+
dd if=/dev/random of=foo bs=4096 count=1 conv=notrunc
104105
'
105-
test_expect_success 'map a test file and access it to prime the cache' '
106+
test_expect_success 'map test file and access it to prime the cache' '
106107
mkdir -p copydir &&
107-
flux filemap map ./red/lptest &&
108-
flux filemap get -C copydir &&
109-
cmp red/lptest copydir/red/lptest
108+
flux archive create --mmap ./foo &&
109+
flux archive extract -C copydir &&
110+
cmp foo copydir/foo
110111
'
111112
test_expect_success 'modify mapped test file without reducing its size' '
112-
dd if=/dev/zero of=red/lptest bs=4096 count=1 conv=notrunc
113+
dd if=/dev/zero of=foo bs=4096 count=1 conv=notrunc
113114
'
114115
test_expect_success 'content change should cause an error' '
115116
test_must_fail flux run -N1 -o stage-in /bin/true 2>changed.err &&

0 commit comments

Comments
 (0)