evas/cserve2: Remap indexes when count is wrong
authorJean-Philippe Andre <jp.andre@samsung.com>
Fri, 23 Aug 2013 09:31:30 +0000 (18:31 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Mon, 28 Oct 2013 06:47:14 +0000 (15:47 +0900)
When advertised count is wrong, try to remap the index.
This will avoid errors with string_get().

src/bin/evas/evas_cserve2_cache.c
src/lib/evas/cserve2/evas_cs2_client.c

index 88cd2c96693619ebaa72ea82c87605c16a174772..bc89150db59037c21599a4cc21ff9c8da57c949c 100644 (file)
@@ -498,6 +498,8 @@ _image_loaded_msg_create(Image_Entry *ientry, Image_Data *idata, int *size)
    else
      idata->shm_id = cserve2_shared_string_add(shmpath);
 
+   idata->valid = EINA_TRUE;
+
    buf = (char *)msg + sizeof(*msg);
    memcpy(buf, shmpath, path_len);
 
@@ -832,7 +834,6 @@ _load_request_response(Image_Entry *ientry,
    idata = _image_data_find(ENTRYID(ientry));
    if (!idata) return NULL;
 
-   idata->valid = EINA_TRUE;
    _entry_load_finish(ASENTRY(ientry));
    ASENTRY(ientry)->request = NULL;
 
index b378b7914a2e14967420f9631cdd7a3556c33ab5..16e1ebbf1b06413b808c5065423717341d075bca 100644 (file)
@@ -1969,7 +1969,17 @@ _shared_index_item_get_by_id(Shared_Index *si, int elemsize, unsigned int id)
    high = si->header->emptyidx; // Should be si->header->sortedidx
 
    if (high > si->count)
-     high = si->count;
+     {
+        if (eina_file_refresh(si->f))
+          {
+             WRN("Refreshing indexes.");
+             _string_index_refresh();
+             _shared_index_remap_check(si, elemsize);
+             high = MIN(si->header->emptyidx, si->count);
+          }
+        else
+          high = si->count;
+     }
 
    base = si->data  + sizeof(Shared_Array_Header);
 
@@ -2128,12 +2138,26 @@ _shared_index_remap_check(Shared_Index *si, int elemsize)
 
    if (si->count != si->header->count)
      {
+        int oldcount;
         // generation_id should have been incremented. Maybe we are hitting
         // a race condition here, when cserve2 grows an index.
         WRN("Reported index count differs from known count: %d vs %d",
             si->header->count, si->count);
+        oldcount = si->count;
+        eina_file_refresh(si->f);
         filesize = eina_file_size_get(si->f);
         si->count = (filesize - sizeof(Shared_Array_Header)) / elemsize;
+        if (si->count != oldcount)
+          {
+             DBG("Remapping current index");
+             eina_file_map_free(si->f, si->data);
+             si->data = eina_file_map_all(si->f, EINA_FILE_RANDOM);
+             if (!si->data)
+               {
+                  ERR("Failed to remap index: %m");
+                  return EINA_FALSE;
+               }
+          }
         if (si->count > si->header->count)
           {
              WRN("Index reports %d elements, but file can contain only %d",