Skip to content

Commit 40931dd

Browse files
committed
flux-restore: add --size-limit=SIZE option
Problem: an archive that includes blobs too large to be stored to the content cache cannot be restored, since failure to restore a blob is treated as a fatal error. Add a --size-limit=SIZE option that instructs flux-restore to skip restoring blobs that exceed the specified size.
1 parent 2bdc5e9 commit 40931dd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/cmd/builtin/restore.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static int content_flags;
3737
static time_t restore_timestamp;
3838
static int blobcount;
3939
static int keycount;
40+
static int blob_size_limit;
4041

4142
static void progress (int delta_blob, int delta_keys)
4243
{
@@ -270,6 +271,17 @@ static json_t *restore_snapshot (struct archive *ar, flux_t *h)
270271
else if (type == AE_IFREG) {
271272
int size = archive_entry_size (entry);
272273

274+
if (blob_size_limit > 0 && size > blob_size_limit) {
275+
fprintf (stderr,
276+
"%s%s size %d exceeds %d limit, skipping\n",
277+
(!quiet && !verbose) ? "\r" : "",
278+
path,
279+
size,
280+
blob_size_limit);
281+
// N.B. archive_read_next_header() skips unconsumed data
282+
// automatically so it is safe to "continue" here.
283+
continue;
284+
}
273285
if (size > bufsize) {
274286
void *newbuf;
275287
if (!(newbuf = realloc (buf, size)))
@@ -354,6 +366,7 @@ static int cmd_restore (optparse_t *p, int ac, char *av[])
354366
content_flags |= CONTENT_FLAG_CACHE_BYPASS;
355367
kvs_checkpoint_flags |= KVS_CHECKPOINT_FLAG_CACHE_BYPASS;
356368
}
369+
blob_size_limit = optparse_get_int (p, "size-limit", 0);
357370

358371
h = builtin_get_flux_handle (p);
359372
ar = restore_create (infile);
@@ -458,6 +471,9 @@ static struct optparse_option restore_opts[] = {
458471
{ .name = "no-cache", .has_arg = 0,
459472
.usage = "Bypass the broker content cache",
460473
},
474+
{ .name = "size-limit", .has_arg = 1, .arginfo = "SIZE",
475+
.usage = "Do not restore blobs greater than SIZE bytes",
476+
},
461477
OPTPARSE_TABLE_END
462478
};
463479

0 commit comments

Comments
 (0)