Skip to content

Commit ccb601c

Browse files
committed
modules/content: drop content.mmap-list RPC
Problem: flux-archive stores file lists in the KVS, so the mechansim for listing mmapped files via the content module is no longer needed. Drop the RPC handler and associated functions. Drop the code for making filerefs available via the content cache as that was only required for 'blobref' mode of this RPC. Drop filemap_mmap_list() from libfilemap.
1 parent 56c8b28 commit ccb601c

File tree

3 files changed

+11
-231
lines changed

3 files changed

+11
-231
lines changed

src/common/libfilemap/filemap.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,35 +55,6 @@ static int decode_data (const char *s, void **data, size_t *data_size)
5555
return 0;
5656
}
5757

58-
flux_future_t *filemap_mmap_list (flux_t *h,
59-
bool blobref,
60-
json_t *tags,
61-
const char *pattern)
62-
{
63-
flux_future_t *f;
64-
65-
if (pattern) {
66-
f = flux_rpc_pack (h,
67-
"content.mmap-list",
68-
0,
69-
FLUX_RPC_STREAMING,
70-
"{s:b s:s s:O}",
71-
"blobref", blobref ? 1 : 0,
72-
"pattern", pattern,
73-
"tags", tags);
74-
}
75-
else {
76-
f = flux_rpc_pack (h,
77-
"content.mmap-list",
78-
0,
79-
FLUX_RPC_STREAMING,
80-
"{s:b s:O}",
81-
"blobref", blobref ? 1 : 0,
82-
"tags", tags);
83-
}
84-
return f;
85-
}
86-
8758
/* When ARCHIVE_EXTRACT_NO_OVERWRITE is set, the overwrite error from
8859
* libarchive-3.6 is "Attempt to write to an empty file". This is
8960
* going to be confusing when the file is not empty, such as the common

src/common/libfilemap/filemap.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ typedef void (*filemap_trace_f) (void *arg,
3030
int64_t ctime,
3131
const char *encoding);
3232

33-
/*
34-
* Call content.mmap-list for tags in JSON array 'tags' with optional
35-
* glob pattern 'pattern'.
36-
*/
37-
flux_future_t *filemap_mmap_list (flux_t *h,
38-
bool blobref,
39-
json_t *tags,
40-
const char *pattern);
41-
4233
/* Extract an RFC 37 File Archive in either array or dictionary form.
4334
* If 'trace_cb' is set, then it will be called for each extracted file.
4435
*

src/modules/content/mmap.c

Lines changed: 11 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,8 @@
1717
*
1818
* All files have one or more tags, so the regions are placed in a
1919
* hash-of-lists where the list names are tags, and the entries are struct
20-
* content_regions. When files are listed or removed, the requestor provides
21-
* one or more tags. (flux filemap has an implicit "main" tag, but that
22-
* is entirely implemented in the tools, not here).
23-
*
24-
* The general idea is that one makes a list query with tags and an optional
25-
* glob and gets back a list of blobrefs. Each blobref represents a serialized
26-
* 'fileref' object that corresponds to a file/content_region. Within the
27-
* fileref is optionally a vector of blobrefs representing data content.
28-
* Having obtained this list, the client can use it to pull the fileref, and
29-
* subsequently its data through the content cache.
20+
* content_regions. When files are mapped, the requestor provides a tag.
21+
* When files are removed, the requestor provides (only) one or more tags.
3022
*
3123
* The content-cache calls content_mmap_region_lookup() on rank 0 when it
3224
* doesn't have a requested blobref in cache, and only consults the backing
@@ -38,14 +30,13 @@
3830
* Slightly tricky optimization:
3931
* To speed up content_mmap_region_lookup() we have mm->cache, which is used
4032
* to find a content_region given a hash. The cache contains hash keys for
41-
* both mmapped data (fileref.blobvec) and serialized fileref objects.
42-
* A given hash may appear in multiple files or parts of the same file,
43-
* so when a file is mapped, we put all its hashes in mm->cache except those
44-
* that are already mapped. If nothing is unmapped, then we know all the
45-
* blobrefs for all the files will remain valid. However when something is
46-
* unmapped we could be losing pieces of unrelated files. Since unmaps are
47-
* bulk operations involving tags, we just walk the entire hash-of-lists
48-
* at that time and restore any missing cache entries.
33+
* mmapped data. A given hash may appear in multiple files or parts of the
34+
* same file, so when a file is mapped, we put all its hashes in mm->cache
35+
* except those that are already mapped. If nothing is unmapped, then we know
36+
* all the blobrefs for all the files will remain valid. However when
37+
* something is unmapped we could be losing pieces of unrelated files. Since
38+
* unmaps are bulk operations involving tags, we just walk the entire
39+
* hash-of-lists at that time and restore any missing cache entries.
4940
*
5041
* Safety issue:
5142
* The content addressable storage model relies on the fact that once hashed,
@@ -75,7 +66,6 @@
7566
#include <unistd.h>
7667
#include <limits.h>
7768
#include <stdlib.h>
78-
#include <fnmatch.h>
7969
#include <jansson.h>
8070
#include <assert.h>
8171
#include <flux/core.h>
@@ -95,17 +85,14 @@
9585
struct cache_entry {
9686
struct content_region *reg;
9787
const void *data; // pointer into reg->mapinfo.base
98-
size_t size; // or reg->fileref_data
88+
size_t size; //
9989
void *hash; // contiguous with struct
10090
};
10191

10292
struct content_region {
10393
struct blobvec_mapinfo mapinfo;
10494
int refcount;
10595
json_t *fileref;
106-
void *fileref_data; // encoded fileref data
107-
size_t fileref_size; // encoded fileref size
108-
char *blobref; // blobref for fileref data
10996

11097
struct content_mmap *mm;
11198

@@ -124,9 +111,6 @@ struct content_mmap {
124111

125112
static int content_hash_size;
126113

127-
static const int max_blobrefs_per_response = 1000;
128-
static const int max_filerefs_per_response = 100;
129-
130114
static const double max_check_age = 5; // seconds since last region stat(2)
131115

132116
static void cache_entry_destroy (struct cache_entry *e)
@@ -228,14 +212,11 @@ static void region_cache_remove (struct content_region *reg)
228212
cache_entry_remove (reg->mm, reg, blobref);
229213
}
230214
}
231-
if (reg->blobref)
232-
cache_entry_remove (reg->mm, reg, reg->blobref);
233-
234215
errno = saved_errno;
235216
}
236217
}
237218

238-
/* Add cache entries for entries associated with region (blobvec + fileref).
219+
/* Add cache entries for entries associated with region
239220
*/
240221
static int region_cache_add (struct content_region *reg)
241222
{
@@ -244,11 +225,6 @@ static int region_cache_add (struct content_region *reg)
244225
json_t *data = NULL;
245226
json_t *entry;
246227

247-
if (cache_entry_add (reg,
248-
reg->fileref_data,
249-
reg->fileref_size,
250-
reg->blobref) < 0)
251-
return -1;
252228
if (json_unpack (reg->fileref,
253229
"{s?s s?o}",
254230
"encoding", &encoding,
@@ -326,8 +302,6 @@ void content_mmap_region_decref (struct content_region *reg)
326302
(void)munmap (reg->mapinfo.base, reg->mapinfo.size);
327303
json_decref (reg->fileref);
328304
free (reg->fullpath);
329-
free (reg->blobref);
330-
free (reg->fileref_data);
331305
free (reg);
332306
errno = saved_errno;
333307
}
@@ -363,10 +337,6 @@ bool content_mmap_validate (struct content_region *reg,
363337
{
364338
char hash2[BLOBREF_MAX_DIGEST_SIZE];
365339

366-
// no need to check the fileref blob as it was not mmapped
367-
if (data == reg->fileref_data)
368-
return true;
369-
370340
assert (reg->mapinfo.base != NULL);
371341
assert (data >= reg->mapinfo.base);
372342
assert (data + data_size <= reg->mapinfo.base + reg->mapinfo.size);
@@ -407,33 +377,6 @@ struct content_region *content_mmap_region_lookup (struct content_mmap *mm,
407377
return e->reg;
408378
}
409379

410-
static int fileref_encode (json_t *fileref,
411-
const char *hash_name,
412-
void **fileref_data,
413-
size_t *fileref_size,
414-
char **blobrefp)
415-
{
416-
void *data;
417-
size_t size;
418-
char blobref[BLOBREF_MAX_STRING_SIZE];
419-
char *blobref_cpy;
420-
421-
if (!(data = json_dumps (fileref, JSON_COMPACT))) {
422-
errno = ENOMEM;
423-
return -1;
424-
}
425-
size = strlen (data) + 1;
426-
if (blobref_hash (hash_name, data, size, blobref, sizeof (blobref)) < 0
427-
|| !(blobref_cpy = strdup (blobref))) {
428-
ERRNO_SAFE_WRAP (free, data);
429-
return -1;
430-
}
431-
*fileref_data = data;
432-
*fileref_size = size;
433-
*blobrefp = blobref_cpy;
434-
return 0;
435-
}
436-
437380
static struct content_region *content_mmap_region_create (
438381
struct content_mmap *mm,
439382
const char *path,
@@ -459,18 +402,6 @@ static struct content_region *content_mmap_region_create (
459402
&reg->mapinfo,
460403
error)))
461404
goto error;
462-
if (fileref_encode (reg->fileref,
463-
mm->hash_name,
464-
&reg->fileref_data,
465-
&reg->fileref_size,
466-
&reg->blobref) < 0) {
467-
errprintf (error,
468-
"%s: error encoding fileref: %s",
469-
path,
470-
strerror (errno));
471-
goto error;
472-
}
473-
474405
if (region_cache_add (reg) < 0) {
475406
errprintf (error,
476407
"%s: error caching region blobrefs: %s",
@@ -502,18 +433,6 @@ static int check_string_array (json_t *o, int min_count)
502433
return -1;
503434
}
504435

505-
static bool fnmatch_fileref (const char *pattern, json_t *fileref)
506-
{
507-
if (pattern) {
508-
const char *path;
509-
510-
if (json_unpack (fileref, "{s:s}", "path", &path) < 0
511-
|| fnmatch (pattern, path, 0) != 0)
512-
return false;
513-
}
514-
return true;
515-
}
516-
517436
static void content_mmap_add_cb (flux_t *h,
518437
flux_msg_handler_t *mh,
519438
const flux_msg_t *msg,
@@ -611,101 +530,6 @@ static void content_mmap_remove_cb (flux_t *h,
611530
flux_log_error (h, "error responding to content.mmap-remove request");
612531
}
613532

614-
/* Get a list of files that match tag(s) and glob pattern, if any.
615-
* Avoid listing duplicates (e.g. a file with multiple tags) by tracking
616-
* fileref blobrefs in a JSON object. Send data in zero or more responses
617-
* (respecting max_blobrefs_per_response or max_filerefs_per_response)
618-
* terminated by ENODATA.
619-
*/
620-
static void content_mmap_list_cb (flux_t *h,
621-
flux_msg_handler_t *mh,
622-
const flux_msg_t *msg,
623-
void *arg)
624-
{
625-
struct content_mmap *mm = arg;
626-
const char *errmsg = NULL;
627-
int blobref;
628-
json_t *tags;
629-
const char *pattern = NULL;
630-
json_t *files = NULL;
631-
json_t *uniqhash = NULL;
632-
struct content_region *reg;
633-
size_t index;
634-
json_t *entry;
635-
636-
if (flux_request_unpack (msg,
637-
NULL,
638-
"{s:b s:o s?s}",
639-
"blobref", &blobref,
640-
"tags", &tags,
641-
"pattern", &pattern) < 0
642-
|| check_string_array (tags, 1) < 0)
643-
goto error;
644-
if (!flux_msg_is_streaming (msg)) {
645-
errno = EPROTO;
646-
goto error;
647-
}
648-
if (mm->rank != 0) {
649-
errmsg = "content can only be mmapped on rank 0";
650-
errno = EINVAL;
651-
goto error;
652-
}
653-
if (!(files = json_array ())
654-
|| !(uniqhash = json_object ())) {
655-
json_decref (files);
656-
goto nomem;
657-
}
658-
json_array_foreach (tags, index, entry) {
659-
const char *name = json_string_value (entry);
660-
661-
reg = hola_list_first (mm->tags, name);
662-
while (reg) {
663-
if (!json_object_get (uniqhash, reg->blobref)
664-
&& fnmatch_fileref (pattern, reg->fileref)) {
665-
json_t *o;
666-
if (json_object_set (uniqhash, reg->blobref, json_null ()) < 0)
667-
goto nomem;
668-
if (blobref) {
669-
if (!(o = json_string (reg->blobref))
670-
|| json_array_append_new (files, o) < 0) {
671-
json_decref (o);
672-
goto nomem;
673-
}
674-
}
675-
else {
676-
if (json_array_append (files, reg->fileref) < 0)
677-
goto nomem;
678-
}
679-
if (json_array_size (files) == (blobref ?
680-
max_blobrefs_per_response :
681-
max_filerefs_per_response)) {
682-
if (flux_respond_pack (h, msg, "{s:O}", "files", files) < 0)
683-
goto error;
684-
if (json_array_clear (files) < 0)
685-
goto nomem;
686-
}
687-
}
688-
reg = hola_list_next (mm->tags, name);
689-
}
690-
}
691-
if (json_array_size (files) > 0) {
692-
if (flux_respond_pack (h, msg, "{s:O}", "files", files) < 0)
693-
goto error;
694-
}
695-
if (flux_respond_error (h, msg, ENODATA, NULL) < 0) // end of stream
696-
flux_log_error (h, "error responding to content.mmap-list request");
697-
json_decref (files);
698-
json_decref (uniqhash);
699-
return;
700-
nomem:
701-
errno = ENOMEM;
702-
error:
703-
if (flux_respond_error (h, msg, errno, errmsg) < 0)
704-
flux_log_error (h, "error responding to content.mmap-list request");
705-
json_decref (files);
706-
json_decref (uniqhash);
707-
}
708-
709533
static const struct flux_msg_handler_spec htab[] = {
710534
{
711535
FLUX_MSGTYPE_REQUEST,
@@ -719,12 +543,6 @@ static const struct flux_msg_handler_spec htab[] = {
719543
content_mmap_remove_cb,
720544
0
721545
},
722-
{
723-
FLUX_MSGTYPE_REQUEST,
724-
"content.mmap-list",
725-
content_mmap_list_cb,
726-
0
727-
},
728546
FLUX_MSGHANDLER_TABLE_END,
729547
};
730548

0 commit comments

Comments
 (0)