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
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,
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>
9585struct 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
10292struct 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
125112static int content_hash_size ;
126113
127- static const int max_blobrefs_per_response = 1000 ;
128- static const int max_filerefs_per_response = 100 ;
129-
130114static const double max_check_age = 5 ; // seconds since last region stat(2)
131115
132116static 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 */
240221static 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-
437380static 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-
517436static 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-
709533static 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