g_atomic_int_add(&cachefile->refcount, -1);
}
+static void cloudlog_fetch_complete(BlueSkyStoreAsync *async,
+ BlueSkyCacheFile *cachefile);
+
+static void cloudlog_fetch_start(BlueSkyCacheFile *cachefile)
+{
+ g_atomic_int_inc(&cachefile->refcount);
+ cachefile->fetching = TRUE;
+ g_print("Starting fetch of %s from cloud\n", cachefile->filename);
+ BlueSkyStoreAsync *async = bluesky_store_async_new(cachefile->fs->store);
+ async->op = STORE_OP_GET;
+ async->key = g_strdup(cachefile->filename);
+ bluesky_store_async_add_notifier(async,
+ (GFunc)cloudlog_fetch_complete,
+ cachefile);
+ bluesky_store_async_submit(async);
+ bluesky_store_async_unref(async);
+}
+
static void cloudlog_fetch_complete(BlueSkyStoreAsync *async,
BlueSkyCacheFile *cachefile)
{
g_print("Fetch of %s from cloud complete, status = %d\n",
async->key, async->result);
- if (async->result < 0)
- return;
-
g_mutex_lock(cachefile->lock);
- char *pathname = g_strdup_printf("%s/%s", cachefile->log->log_directory,
- cachefile->filename);
- if (!g_file_set_contents(pathname, async->data->data, async->data->len,
- NULL))
- {
- g_print("Error writing out fetched file to cache!\n");
+ if (async->result >= 0) {
+ char *pathname = g_strdup_printf("%s/%s",
+ cachefile->log->log_directory,
+ cachefile->filename);
+ if (!g_file_set_contents(pathname, async->data->data, async->data->len,
+ NULL))
+ g_print("Error writing out fetched file to cache!\n");
+ g_free(pathname);
+
+ cachefile->fetching = FALSE;
+ cachefile->ready = TRUE;
+ } else {
+ g_print("Error fetching from cloud, retrying...\n");
+ cloudlog_fetch_start(cachefile);
}
- g_free(pathname);
- cachefile->fetching = FALSE;
- cachefile->ready = TRUE;
+
bluesky_cachefile_unref(cachefile);
g_cond_broadcast(cachefile->cond);
g_mutex_unlock(cachefile->lock);
g_print("Adding cache file %s\n", logname);
map = g_new0(BlueSkyCacheFile, 1);
+ map->fs = fs;
map->type = type;
map->lock = g_mutex_new();
map->type = type;
g_hash_table_insert(log->mmap_cache, map->filename, map);
// If the log file is stored in the cloud, we may need to fetch it
- if (clouddir >= 0) {
- g_atomic_int_inc(&map->refcount);
- map->fetching = TRUE;
- g_print("Starting fetch of %s from cloud\n", logname);
- BlueSkyStoreAsync *async = bluesky_store_async_new(fs->store);
- async->op = STORE_OP_GET;
- async->key = g_strdup(logname);
- bluesky_store_async_add_notifier(async,
- (GFunc)cloudlog_fetch_complete,
- map);
- bluesky_store_async_submit(async);
- bluesky_store_async_unref(async);
- }
+ if (clouddir >= 0)
+ cloudlog_fetch_start(map);
} else {
g_mutex_lock(map->lock);
}