X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Flog.c;h=a904fe1beff88f44f78133a48a9a2a4aa6b8edf6;hb=ef355dcfecf0dad2d95ff5fb3d847f1bf8b9ebe5;hp=714650607df8c13f5b79f3b6e2c2a99f151da3e5;hpb=e1ca9ea030f0adc562642adca4b18557b3c9fe9c;p=bluesky.git diff --git a/bluesky/log.c b/bluesky/log.c index 7146506..a904fe1 100644 --- a/bluesky/log.c +++ b/bluesky/log.c @@ -300,26 +300,47 @@ void bluesky_cachefile_unref(BlueSkyCacheFile *cachefile) 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); @@ -362,6 +383,7 @@ BlueSkyCacheFile *bluesky_cachefile_lookup(BlueSkyFS *fs, 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; @@ -376,19 +398,8 @@ BlueSkyCacheFile *bluesky_cachefile_lookup(BlueSkyFS *fs, 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); }