Implement a rangeset data type and use it to track items in log segments.
[bluesky.git] / bluesky / log.c
index 76d218a..8801b33 100644 (file)
@@ -385,7 +385,7 @@ static void cloudlog_fetch_complete(BlueSkyStoreAsync *async,
                                          cachefile->filename);
         async->data = bluesky_string_dup(async->data);
         bluesky_cloudlog_decrypt(async->data->data, async->data->len,
-                                 cachefile->fs->keys);
+                                 cachefile->fs->keys, cachefile->items);
         if (!g_file_set_contents(pathname, async->data->data, async->data->len,
                                  NULL))
             g_print("Error writing out fetched file to cache!\n");
@@ -451,6 +451,7 @@ BlueSkyCacheFile *bluesky_cachefile_lookup(BlueSkyFS *fs,
         map->log = log;
         g_atomic_int_set(&map->mapcount, 0);
         g_atomic_int_set(&map->refcount, 0);
+        map->items = bluesky_rangeset_new();
 
         g_hash_table_insert(log->mmap_cache, map->filename, map);
 
@@ -481,6 +482,14 @@ BlueSkyRCStr *bluesky_log_map_object(BlueSkyFS *fs, int log_dir,
         return NULL;
     }
 
+    /* Log segments fetched from the cloud might only be partially-fetched.
+     * Check whether the object we are interested in is available. */
+    if (log_dir >= 0) {
+        if (!bluesky_rangeset_lookup(map->items, log_offset)) {
+            g_warning("log-%d: Item at offset %d does not seem to be available\n", log_seq, log_offset);
+        }
+    }
+
     if (map->addr == NULL) {
         while (!map->ready && map->fetching) {
             g_print("Waiting for log segment to be fetched from cloud...\n");